Skip to content

Commit

Permalink
Version 1.0.2
Browse files Browse the repository at this point in the history
- Code improvements
  • Loading branch information
Flerex committed May 13, 2018
1 parent 77760e2 commit 57eee4e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 58 deletions.
38 changes: 8 additions & 30 deletions acp/main_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

namespace flerex\linkedaccounts\acp;

// Required by EPV
if (!defined('IN_PHPBB'))
{
exit;
}

class main_module
{

Expand Down Expand Up @@ -63,18 +57,18 @@ public function main($id, $mode)
switch($mode)
{
case 'overview':
default:
$this->tpl_name = 'acp_overview';
$this->page_title = $this->user->lang('ADM_LINKED_ACCOUNTS_OVERVIEW');
$this->mode_overview();
break;

case 'management':
$this->tpl_name = 'acp_management';
$this->page_title = $this->user->lang('ADM_LINKED_ACCOUNTS_MANAGEMENT');
$this->mode_management();
break;
}

$this->{'mode_' . $mode}();

}
}


Expand All @@ -85,24 +79,8 @@ private function mode_overview()
{
add_form_key('flerex_linkedaccounts_ucp_management');

// if ($this->request->is_set_post('unlink'))
// {
// if (!check_form_key('flerex_linkedaccounts_ucp_management'))
// {
// trigger_error('FORM_INVALID');
// }

// $keys = $this->request->variable('keys', array(''));

// if(!empty($keys))
// {
// $this->utils->remove_links($keys);
// }

// }

$start = (int) $this->request->variable('start', 0);
$limit = (int) $this->request->variable('limit', main_module::ACCOUNTS_PER_PAGE);
$start = $this->request->variable('start', 0);
$limit = $this->request->variable('limit', main_module::ACCOUNTS_PER_PAGE);

$accounts = $this->utils->get_accounts($start, $limit);
foreach($accounts as $account)
Expand Down Expand Up @@ -141,7 +119,7 @@ private function mode_management()
}

$username = utf8_clean_string($this->request->variable('account', '', true));
$user_id = (int) $this->request->variable('accountID', 0, true);
$user_id = $this->request->variable('accountID', 0);

if($user_id || $username)
{
Expand Down Expand Up @@ -187,7 +165,7 @@ private function mode_management()
}

$keys = $this->request->variable('keys', array(''));
$current_account = (int) $this->request->variable('currentaccount', '');
$current_account = $this->request->variable('currentaccount', 0);

if(!empty($keys))
{
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "phpbb-extension",
"description": "A phpBB 3.2 extension that allows users to switch between their accounts with ease.",
"homepage": "https://github.com/flerex/linkedaccounts",
"version": "1.0.1",
"time": "2018-3-01",
"version": "1.0.2",
"time": "2018-03-01",
"keywords": ["flerex", "topic", "participants", "list"],
"license": "GPL-2.0",
"authors": [
Expand Down
1 change: 0 additions & 1 deletion config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ services:
flerex.linkedaccounts.listener:
class: flerex\linkedaccounts\event\main_listener
arguments:
- '@user'
- '@auth'
- '@template'
- '@controller.helper'
Expand Down
7 changes: 3 additions & 4 deletions controller/switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class switcher
/** @var \phpbb\auth\auth $auth, */
protected $auth;

/** @var \phpbb\controller\helper */
protected $helper;
/** @var \flerex\linkedaccounts\service\utils $utils */
protected $utils;

/**
* Constructor
Expand All @@ -38,9 +38,8 @@ public function __construct(\phpbb\user $user, \phpbb\auth\auth $auth, \flerex\l
/**
* Demo controller for route /demo/{name}
*
* @param string $name
* @param int $account_id
* @throws \phpbb\exception\http_exception
* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
*/
public function handle($account_id)
{
Expand Down
6 changes: 1 addition & 5 deletions event/main_listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
class main_listener implements EventSubscriberInterface
{

/** @var \phpbb\user */
protected $user;

/** @var \phpbb\auth\auth */
protected $auth;

Expand Down Expand Up @@ -53,9 +50,8 @@ static public function getSubscribedEvents()
* @param \phpbb\controller\helper $helper
* @param \flerex\linkedaccounts\service\utils $utils
*/
public function __construct(\phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\template\template $template, \phpbb\controller\helper $helper, \flerex\linkedaccounts\service\utils $utils)
public function __construct(\phpbb\auth\auth $auth, \phpbb\template\template $template, \phpbb\controller\helper $helper, \flerex\linkedaccounts\service\utils $utils)
{
$this->user = $user;
$this->auth = $auth;
$this->template = $template;
$this->helper = $helper;
Expand Down
4 changes: 2 additions & 2 deletions language/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'FIND_ACCOUNT' => 'Find account',
'CURRENT_PASSWORD_EXPLAIN_LINKACCOUNTS' => 'You must enter your current password if you wish to create a link to the previous account.',
'EMPTY_FIELDS' => 'Username and password cannot be empty.',
'INCORRECT_LINKED_ACCOUNT_CREDENTIALS' => 'The provided credentials don\'t match any account.',
'INCORRECT_LINKED_ACCOUNT_CREDENTIALS' => 'The provided credentials dont match any account.',
'SAME_ACCOUNT' => 'You cannot link this account to itself!',
'INACTIVE_ACCOUNT' => 'The account you are trying to link to appears to be inactive.',
'BANNED_ACCOUNT' => 'The account you are trying to link to appears to be banned.',
Expand All @@ -53,7 +53,7 @@

// ACP Overview Module
'ADM_LINKED_ACCOUNTS_OVERVIEW' => 'Overview',
'ADM_LINKED_ACCOUNTS_OVERVIEW_EXPLAIN' => 'In this section you\'ll find some usage statistics along with a list with the users that have links to other accounts.',
'ADM_LINKED_ACCOUNTS_OVERVIEW_EXPLAIN' => 'In this section youll find some usage statistics along with a list with the users that have links to other accounts.',
'LINKED_ACCOUNTS_COUNT' => 'Users with links',
'LINKED_ACCOUNTS_COUNT_EXPLAIN' => 'Amount of accounts that have at least one link.',
'LINK_COUNT' => 'Links',
Expand Down
17 changes: 7 additions & 10 deletions service/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public function get_user($key)

if(is_numeric($key))
{
$sql .= 'WHERE user_id = ' . (int) $key . ';';
$sql .= 'WHERE user_id = ' . (int) $key;
}
else
{
$sql .= 'WHERE username_clean = \'' . $this->db->sql_escape(utf8_clean_string($key)) . '\';';
$sql .= 'WHERE username_clean = ' . $this->db->sql_escape(utf8_clean_string($key));
}

$result = $this->db->sql_query($sql);
Expand Down Expand Up @@ -120,7 +120,7 @@ public function remove_links($links, $account = null)
$len = count($links);
foreach($links as $key => $account)
{
$sql_where .= '(user_id = ' . (int) $this->db->sql_escape($account) . ' OR linked_user_id = ' . (int) $this->db->sql_escape($account) . ')';
$sql_where .= '(user_id = ' . (int) $account . ' OR linked_user_id = ' . (int) $account . ')';

if($key != $len - 1)
{
Expand Down Expand Up @@ -148,8 +148,8 @@ public function already_linked($linked_id)
{

$sql = 'SELECT COUNT(user_id) AS already_linked FROM ' . $this->linkedacconts_table . '
WHERE (user_id = ' . (int) $this->user->data['user_id'] . ' AND linked_user_id = ' . (int) $this->db->sql_escape($linked_id) . ')
OR (user_id = ' . (int) $this->db->sql_escape($linked_id) . ' AND linked_user_id = ' . (int) $this->user->data['user_id'] . ')';
WHERE (user_id = ' . (int) $this->user->data['user_id'] . ' AND linked_user_id = ' . (int) $linked_id . ')
OR (user_id = ' . (int) $linked_id . ' AND linked_user_id = ' . (int) $this->user->data['user_id'] . ')';

$result = $this->db->sql_query($sql);
$found_something = $this->db->sql_fetchfield('already_linked') != 0;
Expand All @@ -169,8 +169,6 @@ public function already_linked($linked_id)
*/
public function can_switch_to($account_id)
{

$is_linked = false;
$saved_account = null;
foreach($this->get_linked_accounts() as $account)
{
Expand All @@ -181,13 +179,12 @@ public function can_switch_to($account_id)
}
}

if(!$saved_account || ($saved_account['user_type'] == 1 || $this->user->check_ban($account_id, false, $saved_account['user_email'], true) !== false))
if(!$saved_account || ($saved_account['user_type'] == USER_INACTIVE || $this->user->check_ban($account_id, false, $saved_account['user_email'], true) !== false))
{
return false;
}

return true;

}

/**
Expand Down Expand Up @@ -291,7 +288,7 @@ public function get_user_auth_info($username)

$sql = 'SELECT user_id, user_password, user_email, user_type
FROM ' . USERS_TABLE . '
WHERE username_clean = \'' . $this->db->sql_escape(utf8_clean_string($username)) . '\'';
WHERE username_clean = ' . $this->db->sql_escape(utf8_clean_string($username));

$result = $this->db->sql_query($sql);
$output = $this->db->sql_fetchrow($result);
Expand Down
9 changes: 5 additions & 4 deletions ucp/main_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
class main_module
{

const MODULE_BASENAME = '-flerex-linkedaccounts-ucp-main_module';

public $u_action;
public $tpl_name;
public $page_title;
Expand All @@ -41,6 +39,8 @@ class main_module

protected $utils;

protected $module_basename;

public function main($id, $mode)
{
global $config, $request, $template, $user, $db, $phpbb_container;
Expand All @@ -58,6 +58,7 @@ public function main($id, $mode)
$this->linkedacconts_table = $this->table_prefix . 'flerex_linkedaccounts';

$this->utils = $this->phpbb_container->get('flerex.linkedaccounts.utils');
$this->module_basename = str_replace('\\', '-', $id);

switch($mode)
{
Expand Down Expand Up @@ -152,7 +153,7 @@ private function mode_link()
else
{
$this->utils->create_link($this->user->data['user_id'], $user['user_id']);
redirect(append_sid($this->phpbb_root_path . 'ucp.' . $this->phpEx, 'i=' . main_module::MODULE_BASENAME . '&mode=management'));
redirect(append_sid($this->phpbb_root_path . 'ucp.' . $this->phpEx, 'i=' . $this->module_basename . '&mode=management'));
}

}
Expand Down Expand Up @@ -199,7 +200,7 @@ private function mode_management()

$this->template->assign_vars(array(
'U_ACTION' => $this->u_action,
'U_LINK_ACCOUNT' => append_sid($this->phpbb_root_path . 'ucp.' . $this->phpEx, 'i=' . main_module::MODULE_BASENAME . '&mode=link'),
'U_LINK_ACCOUNT' => append_sid($this->phpbb_root_path . 'ucp.' . $this->phpEx, 'i=' . $this->module_basename . '&mode=link'),
));
}

Expand Down

0 comments on commit 57eee4e

Please sign in to comment.