mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Fix: create account by email
Now you can at least create an account if account_login_by_email is enabled :)
This commit is contained in:
parent
2563583f84
commit
0abb9384a6
@ -101,6 +101,37 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
|||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $email
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function createWithEmail($email = null)
|
||||||
|
{
|
||||||
|
// if name is not passed then it will be generated randomly
|
||||||
|
if( !isset($email) )
|
||||||
|
{
|
||||||
|
throw new Exception(__CLASS__ . ':' . __METHOD__ . ' createWithEmail called without e-mail.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// repeats until name is unique
|
||||||
|
do
|
||||||
|
{
|
||||||
|
$name = uniqid();
|
||||||
|
|
||||||
|
$query = $this->db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $this->db->quote($name));
|
||||||
|
} while($query->rowCount() >= 1);
|
||||||
|
|
||||||
|
// saves blank account info
|
||||||
|
$this->db->exec('INSERT INTO `accounts` (`name`, `password`, `email`, `created`) VALUES (' . $this->db->quote($name) . ', ' . '\'\', ' . $this->db->quote($email) . ', ' . time() . ')');
|
||||||
|
|
||||||
|
// reads created account's ID
|
||||||
|
$this->data['id'] = $this->db->lastInsertId();
|
||||||
|
$this->data['name'] = $name;
|
||||||
|
|
||||||
|
// return name of newly created account
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Creates new account.
|
* Creates new account.
|
||||||
*
|
*
|
||||||
|
@ -34,11 +34,13 @@ $errors = array();
|
|||||||
$save = isset($_POST['save']) && $_POST['save'] == 1;
|
$save = isset($_POST['save']) && $_POST['save'] == 1;
|
||||||
if($save)
|
if($save)
|
||||||
{
|
{
|
||||||
if(USE_ACCOUNT_NAME) {
|
if(!config('account_login_by_email')) {
|
||||||
$account_name = $_POST['account'];
|
if(USE_ACCOUNT_NAME) {
|
||||||
}
|
$account_name = $_POST['account'];
|
||||||
else {
|
}
|
||||||
$account_id = $_POST['account'];
|
else {
|
||||||
|
$account_id = $_POST['account'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = $_POST['email'];
|
$email = $_POST['email'];
|
||||||
@ -46,12 +48,14 @@ if($save)
|
|||||||
$password2 = $_POST['password2'];
|
$password2 = $_POST['password2'];
|
||||||
|
|
||||||
// account
|
// account
|
||||||
if(isset($account_id)) {
|
if(!config('account_login_by_email')) {
|
||||||
if(!Validator::accountId($account_id))
|
if (isset($account_id)) {
|
||||||
|
if (!Validator::accountId($account_id)) {
|
||||||
|
$errors['account'] = Validator::getLastError();
|
||||||
|
}
|
||||||
|
} else if (!Validator::accountName($account_name))
|
||||||
$errors['account'] = Validator::getLastError();
|
$errors['account'] = Validator::getLastError();
|
||||||
}
|
}
|
||||||
else if(!Validator::accountName($account_name))
|
|
||||||
$errors['account'] = Validator::getLastError();
|
|
||||||
|
|
||||||
// email
|
// email
|
||||||
if(!Validator::email($email))
|
if(!Validator::email($email))
|
||||||
@ -93,7 +97,7 @@ if($save)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if account name is not equal to password
|
// check if account name is not equal to password
|
||||||
if(USE_ACCOUNT_NAME && strtoupper($account_name) == strtoupper($password)) {
|
if(!config('account_login_by_email') && USE_ACCOUNT_NAME && strtoupper($account_name) == strtoupper($password)) {
|
||||||
$errors['password'] = 'Password may not be the same as account name.';
|
$errors['password'] = 'Password may not be the same as account name.';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,16 +110,28 @@ if($save)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$account_db = new OTS_Account();
|
$account_db = new OTS_Account();
|
||||||
if(USE_ACCOUNT_NAME)
|
if (config('account_login_by_email')) {
|
||||||
$account_db->find($account_name);
|
$account_db->findByEMail($email);
|
||||||
else
|
}
|
||||||
$account_db->load($account_id);
|
else {
|
||||||
|
if(USE_ACCOUNT_NAME) {
|
||||||
|
$account_db->find($account_name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$account_db->load($account_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($account_db->isLoaded()) {
|
if($account_db->isLoaded()) {
|
||||||
if(USE_ACCOUNT_NAME)
|
if (config('account_login_by_email') && !config('account_mail_unique')) {
|
||||||
$errors['account'] = 'Account with this name already exist.';
|
$errors['account'] = 'Account with this email already exist.';
|
||||||
else
|
}
|
||||||
$errors['account'] = 'Account with this id already exist.';
|
else if (!config('account_login_by_email')) {
|
||||||
|
if (USE_ACCOUNT_NAME)
|
||||||
|
$errors['account'] = 'Account with this name already exist.';
|
||||||
|
else
|
||||||
|
$errors['account'] = 'Account with this id already exist.';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($_POST['accept_rules']) || $_POST['accept_rules'] !== 'true')
|
if(!isset($_POST['accept_rules']) || $_POST['accept_rules'] !== 'true')
|
||||||
@ -130,11 +146,12 @@ if($save)
|
|||||||
'accept_rules' => isset($_POST['accept_rules']) ? $_POST['accept_rules'] === 'true' : false,
|
'accept_rules' => isset($_POST['accept_rules']) ? $_POST['accept_rules'] === 'true' : false,
|
||||||
);
|
);
|
||||||
|
|
||||||
if(USE_ACCOUNT_NAME) {
|
if (!config('account_login_by_email')) {
|
||||||
$params['account_name'] = $_POST['account'];
|
if (USE_ACCOUNT_NAME) {
|
||||||
}
|
$params['account_name'] = $_POST['account'];
|
||||||
else {
|
} else {
|
||||||
$params['account_id'] = $_POST['account'];
|
$params['account_id'] = $_POST['account'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$hooks->trigger(HOOK_ACCOUNT_CREATE_AFTER_SUBMIT, $params);
|
$hooks->trigger(HOOK_ACCOUNT_CREATE_AFTER_SUBMIT, $params);
|
||||||
@ -151,10 +168,15 @@ if($save)
|
|||||||
if(empty($errors))
|
if(empty($errors))
|
||||||
{
|
{
|
||||||
$new_account = new OTS_Account();
|
$new_account = new OTS_Account();
|
||||||
if(USE_ACCOUNT_NAME)
|
if (config('account_login_by_email')) {
|
||||||
$new_account->create($account_name);
|
$new_account->createWithEmail($email);
|
||||||
else
|
}
|
||||||
$new_account->create(NULL, $account_id);
|
else {
|
||||||
|
if(USE_ACCOUNT_NAME)
|
||||||
|
$new_account->create($account_name);
|
||||||
|
else
|
||||||
|
$new_account->create(NULL, $account_id);
|
||||||
|
}
|
||||||
|
|
||||||
$config_salt_enabled = $db->hasColumn('accounts', 'salt');
|
$config_salt_enabled = $db->hasColumn('accounts', 'salt');
|
||||||
if($config_salt_enabled)
|
if($config_salt_enabled)
|
||||||
@ -192,7 +214,11 @@ if($save)
|
|||||||
$new_account->setCustomField('premium_points', $config['account_premium_points']);
|
$new_account->setCustomField('premium_points', $config['account_premium_points']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmp_account = (USE_ACCOUNT_NAME ? $account_name : $account_id);
|
$tmp_account = $email;
|
||||||
|
if (!config('account_login_by_email')) {
|
||||||
|
$tmp_account = (USE_ACCOUNT_NAME ? $account_name : $account_id);
|
||||||
|
}
|
||||||
|
|
||||||
if($config['mail_enabled'] && $config['account_mail_verify'])
|
if($config['mail_enabled'] && $config['account_mail_verify'])
|
||||||
{
|
{
|
||||||
$hash = md5(generateRandomString(16, true, true) . $email);
|
$hash = md5(generateRandomString(16, true, true) . $email);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user