mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 09:19:22 +02:00
Fixes to account number
This commit is contained in:
parent
3a3411c117
commit
8985917a96
@ -16,6 +16,11 @@ $use_datatable = true;
|
||||
if ($config['account_country'])
|
||||
require SYSTEM . 'countries.conf.php';
|
||||
|
||||
$nameOrNumberColumn = 'name';
|
||||
if (USE_ACCOUNT_NUMBER) {
|
||||
$nameOrNumberColumn = 'number';
|
||||
}
|
||||
|
||||
$hasSecretColumn = $db->hasColumn('accounts', 'secret');
|
||||
$hasCoinsColumn = $db->hasColumn('accounts', 'coins');
|
||||
$hasPointsColumn = $db->hasColumn('accounts', 'premium_points');
|
||||
@ -48,7 +53,7 @@ else if (isset($_REQUEST['search'])) {
|
||||
if (strlen($search_account) < 3 && !Validator::number($search_account)) {
|
||||
echo_error('Player name is too short.');
|
||||
} else {
|
||||
$query = $db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $db->quote($search_account));
|
||||
$query = $db->query('SELECT `id` FROM `accounts` WHERE `' . $nameOrNumberColumn . '` = ' . $db->quote($search_account));
|
||||
if ($query->rowCount() == 1) {
|
||||
$query = $query->fetch();
|
||||
$id = (int)$query['id'];
|
||||
@ -203,7 +208,7 @@ else if (isset($_REQUEST['search'])) {
|
||||
}
|
||||
}
|
||||
} else if ($id == 0) {
|
||||
$accounts_db = $db->query('SELECT `id`, `name`' . ($hasTypeColumn ? ',type' : ($hasGroupColumn ? ',group_id' : '')) . ' FROM `accounts` ORDER BY `id` ASC');
|
||||
$accounts_db = $db->query('SELECT `id`, `' . $nameOrNumberColumn . '`' . ($hasTypeColumn ? ',type' : ($hasGroupColumn ? ',group_id' : '')) . ' FROM `accounts` ORDER BY `id` ASC');
|
||||
?>
|
||||
<div class="col-12 col-sm-12 col-lg-10">
|
||||
<div class="card card-info card-outline">
|
||||
@ -215,7 +220,7 @@ else if (isset($_REQUEST['search'])) {
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th><?= ($nameOrNumberColumn == 'number' ? 'Number' : 'Name'); ?></th>
|
||||
<?php if($hasTypeColumn || $hasGroupColumn): ?>
|
||||
<th>Position</th>
|
||||
<?php endif; ?>
|
||||
@ -226,7 +231,7 @@ else if (isset($_REQUEST['search'])) {
|
||||
<?php foreach ($accounts_db as $account_lst): ?>
|
||||
<tr>
|
||||
<th><?php echo $account_lst['id']; ?></th>
|
||||
<td><?php echo $account_lst['name']; ?></a></td>
|
||||
<td><?php echo $account_lst[$nameOrNumberColumn]; ?></a></td>
|
||||
<?php if($hasTypeColumn || $hasGroupColumn): ?>
|
||||
<td>
|
||||
<?php if ($hasTypeColumn) {
|
||||
@ -284,6 +289,11 @@ else if (isset($_REQUEST['search'])) {
|
||||
<label for="name">Account Name:</label>
|
||||
<input type="text" class="form-control" id="name" name="name" autocomplete="off" value="<?php echo $account->getName(); ?>"/>
|
||||
</div>
|
||||
<?php elseif (USE_ACCOUNT_NUMBER): ?>
|
||||
<div class="col-12 col-sm-12 col-lg-4">
|
||||
<label for="name">Account Number:</label>
|
||||
<input type="text" class="form-control" id="name" name="name" autocomplete="off" value="<?php echo $account->getNumber(); ?>"/>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="col-12 col-sm-12 col-lg-5">
|
||||
<div class="form-check">
|
||||
|
@ -8,7 +8,7 @@ if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['save
|
||||
else {
|
||||
require SYSTEM . 'init.php';
|
||||
if(!$error) {
|
||||
if(USE_ACCOUNT_NAME)
|
||||
if(USE_ACCOUNT_NAME || USE_ACCOUNT_NUMBER)
|
||||
$account = isset($_SESSION['var_account']) ? $_SESSION['var_account'] : null;
|
||||
else
|
||||
$account_id = isset($_SESSION['var_account_id']) ? $_SESSION['var_account_id'] : null;
|
||||
|
@ -231,26 +231,22 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @param int $id Account number.
|
||||
* @throws PDOException On PDO operation error.
|
||||
*/
|
||||
public function load($id, $fresh = false, $searchOnlyById = false)
|
||||
public function load($id, $fresh = false)
|
||||
{
|
||||
if(!$fresh && isset(self::$cache[$id])) {
|
||||
$this->data = self::$cache[$id];
|
||||
return;
|
||||
}
|
||||
|
||||
$numberColumn = 'id';
|
||||
$nameOrNumber = '';
|
||||
if (!$searchOnlyById) {
|
||||
if (USE_ACCOUNT_NAME) {
|
||||
$nameOrNumber = '`name`,';
|
||||
} else if (USE_ACCOUNT_NUMBER) {
|
||||
$nameOrNumber = '`number`,';
|
||||
$numberColumn = 'number';
|
||||
}
|
||||
if (USE_ACCOUNT_NAME) {
|
||||
$nameOrNumber = '`name`,';
|
||||
} else if (USE_ACCOUNT_NUMBER) {
|
||||
$nameOrNumber = '`number`,';
|
||||
}
|
||||
|
||||
// SELECT query on database
|
||||
$this->data = $this->db->query('SELECT `id`, ' . $nameOrNumber . '`password`, `email`, `blocked`, `rlname`, `location`, `country`, `web_flags`, ' . ($this->db->hasColumn('accounts', 'premdays') ? '`premdays`, ' : '') . ($this->db->hasColumn('accounts', 'lastday') ? '`lastday`, ' : ($this->db->hasColumn('accounts', 'premend') ? '`premend`,' : ($this->db->hasColumn('accounts', 'premium_ends_at') ? '`premium_ends_at`,' : ''))) . '`created` FROM `accounts` WHERE `' . $numberColumn . '` = ' . (int) $id)->fetch();
|
||||
$this->data = $this->db->query('SELECT `id`, ' . $nameOrNumber . '`password`, `email`, `blocked`, `rlname`, `location`, `country`, `web_flags`, ' . ($this->db->hasColumn('accounts', 'premdays') ? '`premdays`, ' : '') . ($this->db->hasColumn('accounts', 'lastday') ? '`lastday`, ' : ($this->db->hasColumn('accounts', 'premend') ? '`premend`,' : ($this->db->hasColumn('accounts', 'premium_ends_at') ? '`premium_ends_at`,' : ''))) . '`created` FROM `accounts` WHERE `id` = ' . (int) $id)->fetch();
|
||||
self::$cache[$id] = $this->data;
|
||||
}
|
||||
|
||||
@ -268,8 +264,13 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
*/
|
||||
public function find($name)
|
||||
{
|
||||
$nameOrNumberColumn = 'name';
|
||||
if (USE_ACCOUNT_NUMBER) {
|
||||
$nameOrNumberColumn = 'number';
|
||||
}
|
||||
|
||||
// finds player's ID
|
||||
$id = $this->db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $this->db->quote($name) )->fetch();
|
||||
$id = $this->db->query('SELECT `id` FROM `accounts` WHERE `' . $nameOrNumberColumn . '` = ' . $this->db->quote($name) )->fetch();
|
||||
|
||||
// if anything was found
|
||||
if( isset($id['id']) )
|
||||
|
@ -602,7 +602,7 @@ class OTS_Player extends OTS_Row_DAO
|
||||
}
|
||||
|
||||
$account = new OTS_Account();
|
||||
$account->load($this->data['account_id'], false, true);
|
||||
$account->load($this->data['account_id']);
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ $current_session = getSession('account');
|
||||
if($current_session !== false)
|
||||
{
|
||||
$account_logged = new OTS_Account();
|
||||
$account_logged->load($current_session);
|
||||
$account_logged->find($current_session);
|
||||
if($account_logged->isLoaded() && $account_logged->getPassword() == getSession('password')
|
||||
//&& (!isset($_SESSION['admin']) || admin())
|
||||
&& (getSession('remember_me') !== false || getSession('last_visit') > time() - 15 * 60)) { // login for 15 minutes if "remember me" is not used
|
||||
|
@ -37,7 +37,7 @@ if(!$logged && isset($_POST['account_login'], $_POST['password_login']))
|
||||
}
|
||||
|
||||
if (!config('account_login_by_email') || config('account_login_by_email_fallback')) {
|
||||
if(USE_ACCOUNT_NAME) {
|
||||
if(USE_ACCOUNT_NAME || USE_ACCOUNT_NUMBER) {
|
||||
$account_logged->find($login_account);
|
||||
} else {
|
||||
$account_logged->load($login_account, true);
|
||||
|
@ -27,15 +27,16 @@ if(isset($_GET['account']))
|
||||
error_(Validator::getLastError());
|
||||
|
||||
$_account = new OTS_Account();
|
||||
if(USE_ACCOUNT_NAME)
|
||||
if(USE_ACCOUNT_NAME || USE_ACCOUNT_NUMBER)
|
||||
$_account->find($account);
|
||||
else
|
||||
$_account->load($account);
|
||||
|
||||
$accountNameOrNumber = (USE_ACCOUNT_NAME ? ' name' : 'number');
|
||||
if($_account->isLoaded())
|
||||
error_('Account with this name already exist.');
|
||||
error_("Account with this $accountNameOrNumber already exist.");
|
||||
|
||||
success_('Good account' . (USE_ACCOUNT_NAME ? ' name' : '') . ' ( ' . $account . ' ).');
|
||||
success_("Good account $accountNameOrNumber ($account).");
|
||||
}
|
||||
else if(isset($_GET['email']))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user