|
@@ -24,7 +24,7 @@ class Auth extends Page
|
|
*/
|
|
*/
|
|
public function logout($args)
|
|
public function logout($args)
|
|
{
|
|
{
|
|
- if (empty($args['token']) || ! $this->c->Csrf->verify($args['token'], 'Logout', $args)) {
|
|
|
|
|
|
+ if (! $this->c->Csrf->verify($args['token'], 'Logout', $args)) {
|
|
return $this->c->Redirect->page('Index')->message('Bad token');
|
|
return $this->c->Redirect->page('Index')->message('Bad token');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -37,24 +37,37 @@ class Auth extends Page
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Подготовка данных для страницы входа на форум
|
|
|
|
|
|
+ * Вход на форум
|
|
*
|
|
*
|
|
* @param array $args
|
|
* @param array $args
|
|
|
|
+ * @param string $method
|
|
*
|
|
*
|
|
* @return Page
|
|
* @return Page
|
|
*/
|
|
*/
|
|
- public function login(array $args)
|
|
|
|
|
|
+ public function login(array $args, $method)
|
|
{
|
|
{
|
|
$this->c->Lang->load('auth');
|
|
$this->c->Lang->load('auth');
|
|
|
|
|
|
- $save = empty($args) || ! empty($args['_save']);
|
|
|
|
-
|
|
|
|
- if (! isset($args['_username'])) {
|
|
|
|
- $args['_username'] = '';
|
|
|
|
- }
|
|
|
|
- if (! isset($args['_redirect'])) {
|
|
|
|
- $args['_redirect'] = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
|
|
|
|
- $args['_redirect'] = $this->c->Router->validate($args['_redirect'], 'Index');
|
|
|
|
|
|
+ $v = null;
|
|
|
|
+ if ('POST' === $method) {
|
|
|
|
+ $v = $this->c->Validator->addValidators([
|
|
|
|
+ 'login_process' => [$this, 'vLoginProcess'],
|
|
|
|
+ ])->setRules([
|
|
|
|
+ 'token' => 'token:Login',
|
|
|
|
+ 'redirect' => 'required|referer:Index',
|
|
|
|
+ 'username' => 'required|string',
|
|
|
|
+ 'password' => 'required|string|login_process',
|
|
|
|
+ 'save' => 'checkbox',
|
|
|
|
+ ])->setAliases([
|
|
|
|
+ 'username' => 'Username',
|
|
|
|
+ 'password' => 'Passphrase',
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ if ($v->validation($_POST)) {
|
|
|
|
+ return $this->c->Redirect->url($v->redirect)->message('Login redirect');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->fIswev = $v->getErrors();
|
|
}
|
|
}
|
|
|
|
|
|
$this->fIndex = 'login';
|
|
$this->fIndex = 'login';
|
|
@@ -66,46 +79,15 @@ class Auth extends Page
|
|
$this->formToken = $this->c->Csrf->create('Login');
|
|
$this->formToken = $this->c->Csrf->create('Login');
|
|
$this->forgetLink = $this->c->Router->link('Forget');
|
|
$this->forgetLink = $this->c->Router->link('Forget');
|
|
$this->regLink = $this->c->config->o_regs_allow == '1' ? $this->c->Router->link('Register') : null;
|
|
$this->regLink = $this->c->config->o_regs_allow == '1' ? $this->c->Router->link('Register') : null;
|
|
- $this->username = $args['_username'];
|
|
|
|
- $this->redirect = $args['_redirect'];
|
|
|
|
- $this->save = $save;
|
|
|
|
|
|
+ $this->username = $v ? $v->username : (isset($args['_username']) ? $args['_username'] : '');
|
|
|
|
+ $this->redirect = $v ? $v->redirect : $this->c->Router->validate($_SERVER['HTTP_REFERER'], 'Index'); //????
|
|
|
|
+ $this->save = $v ? $v->save : 1;
|
|
|
|
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Вход на форум
|
|
|
|
- *
|
|
|
|
- * @return Page
|
|
|
|
- */
|
|
|
|
- public function loginPost()
|
|
|
|
- {
|
|
|
|
- $this->c->Lang->load('auth');
|
|
|
|
-
|
|
|
|
- $v = $this->c->Validator->addValidators([
|
|
|
|
- 'login_process' => [$this, 'vLoginProcess'],
|
|
|
|
- ])->setRules([
|
|
|
|
- 'token' => 'token:Login',
|
|
|
|
- 'redirect' => 'referer:Index',
|
|
|
|
- 'username' => ['required|string', \ForkBB\__('Username')],
|
|
|
|
- 'password' => ['required|string|login_process', \ForkBB\__('Passphrase')],
|
|
|
|
- 'save' => 'checkbox',
|
|
|
|
- ]);
|
|
|
|
-
|
|
|
|
- if ($v->validation($_POST)) {
|
|
|
|
- return $this->c->Redirect->url($v->redirect)->message('Login redirect');
|
|
|
|
- } else {
|
|
|
|
- $this->fIswev = $v->getErrors();
|
|
|
|
- return $this->login([
|
|
|
|
- '_username' => $v->username,
|
|
|
|
- '_redirect' => $v->redirect,
|
|
|
|
- '_save' => $v->save,
|
|
|
|
- ]);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Проверка по базе и вход на форум
|
|
|
|
|
|
+ * Проверка по базе и вход
|
|
*
|
|
*
|
|
* @param Validator $v
|
|
* @param Validator $v
|
|
* @param string $password
|
|
* @param string $password
|
|
@@ -143,6 +125,10 @@ class Auth extends Page
|
|
) {
|
|
) {
|
|
$user->registration_ip = $this->c->user->ip;
|
|
$user->registration_ip = $this->c->user->ip;
|
|
}
|
|
}
|
|
|
|
+ // сбросить запрос на смену кодовой фразы
|
|
|
|
+ if (! empty($user->activate_string) && 'p' === $user->activate_string{0}) {
|
|
|
|
+ $user->activate_string = null;
|
|
|
|
+ }
|
|
// изменения юзера в базе
|
|
// изменения юзера в базе
|
|
$this->c->users->update($user);
|
|
$this->c->users->update($user);
|
|
|
|
|
|
@@ -154,18 +140,63 @@ class Auth extends Page
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Подготовка данных для страницы восстановления пароля
|
|
|
|
|
|
+ * Запрос на смену кодовой фразы
|
|
*
|
|
*
|
|
* @param array $args
|
|
* @param array $args
|
|
|
|
+ * @param string $method
|
|
*
|
|
*
|
|
* @return Page
|
|
* @return Page
|
|
*/
|
|
*/
|
|
- public function forget(array $args)
|
|
|
|
|
|
+ public function forget(array $args, $method)
|
|
{
|
|
{
|
|
$this->c->Lang->load('auth');
|
|
$this->c->Lang->load('auth');
|
|
|
|
|
|
- if (! isset($args['_email'])) {
|
|
|
|
- $args['_email'] = '';
|
|
|
|
|
|
+ $v = null;
|
|
|
|
+ if ('POST' === $method) {
|
|
|
|
+ $v = $this->c->Validator->addValidators([
|
|
|
|
+ 'check_email' => [$this, 'vCheckEmail'],
|
|
|
|
+ ])->setRules([
|
|
|
|
+ 'token' => 'token:Forget',
|
|
|
|
+ 'email' => 'required|string:trim,lower|email|check_email',
|
|
|
|
+ ])->setAliases([
|
|
|
|
+ ])->setMessages([
|
|
|
|
+ 'email.email' => 'Invalid email',
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ if ($v->validation($_POST)) {
|
|
|
|
+ $key = 'p' . $this->c->Secury->randomPass(79);
|
|
|
|
+ $hash = $this->c->Secury->hash($v->email . $key);
|
|
|
|
+ $link = $this->c->Router->link('ChangePassword', ['email' => $v->email, 'key' => $key, 'hash' => $hash]);
|
|
|
|
+ $tplData = [
|
|
|
|
+ 'fRootLink' => $this->c->Router->link('Index'),
|
|
|
|
+ 'fMailer' => \ForkBB\__('Mailer', $this->c->config->o_board_title),
|
|
|
|
+ 'username' => $this->tmpUser->username,
|
|
|
|
+ 'link' => $link,
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ $isSent = $this->c->Mail
|
|
|
|
+ ->reset()
|
|
|
|
+ ->setFolder($this->c->DIR_LANG)
|
|
|
|
+ ->setLanguage($this->tmpUser->language)
|
|
|
|
+ ->setTo($v->email, $this->tmpUser->username)
|
|
|
|
+ ->setFrom($this->c->config->o_webmaster_email, \ForkBB\__('Mailer', $this->c->config->o_board_title))
|
|
|
|
+ ->setTpl('passphrase_reset.tpl', $tplData)
|
|
|
|
+ ->send();
|
|
|
|
+ } catch (MailException $e) {
|
|
|
|
+ $isSent = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($isSent) {
|
|
|
|
+ $this->tmpUser->activate_string = $key;
|
|
|
|
+ $this->tmpUser->last_email_sent = time();
|
|
|
|
+ $this->c->users->update($this->tmpUser);
|
|
|
|
+ return $this->c->Message->message(\ForkBB\__('Forget mail', $this->c->config->o_admin_email), false, 200);
|
|
|
|
+ } else {
|
|
|
|
+ return $this->c->Message->message(\ForkBB\__('Error mail', $this->c->config->o_admin_email), true, 200);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $this->fIswev = $v->getErrors();
|
|
}
|
|
}
|
|
|
|
|
|
$this->fIndex = 'login';
|
|
$this->fIndex = 'login';
|
|
@@ -175,69 +206,11 @@ class Auth extends Page
|
|
$this->titles = \ForkBB\__('Passphrase reset');
|
|
$this->titles = \ForkBB\__('Passphrase reset');
|
|
$this->formAction = $this->c->Router->link('Forget');
|
|
$this->formAction = $this->c->Router->link('Forget');
|
|
$this->formToken = $this->c->Csrf->create('Forget');
|
|
$this->formToken = $this->c->Csrf->create('Forget');
|
|
- $this->email = $args['_email'];
|
|
|
|
|
|
+ $this->email = $v ? $v->email : (isset($args['_email']) ? $args['_email'] : '');
|
|
|
|
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Отправка письма для восстановления пароля
|
|
|
|
- *
|
|
|
|
- * @return Page
|
|
|
|
- */
|
|
|
|
- public function forgetPost()
|
|
|
|
- {
|
|
|
|
- $this->c->Lang->load('auth');
|
|
|
|
-
|
|
|
|
- $v = $this->c->Validator->addValidators([
|
|
|
|
- 'check_email' => [$this, 'vCheckEmail'],
|
|
|
|
- ])->setRules([
|
|
|
|
- 'token' => 'token:Forget',
|
|
|
|
- 'email' => 'required|string:trim,lower|email|check_email',
|
|
|
|
- ])->setMessages([
|
|
|
|
- 'email.email' => 'Invalid email',
|
|
|
|
- ]);
|
|
|
|
-
|
|
|
|
- if (! $v->validation($_POST)) {
|
|
|
|
- $this->fIswev = $v->getErrors();
|
|
|
|
- return $this->forget([
|
|
|
|
- '_email' => $v->email,
|
|
|
|
- ]);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $key = 'p' . $this->c->Secury->randomPass(79);
|
|
|
|
- $hash = $this->c->Secury->hash($v->email . $key);
|
|
|
|
- $link = $this->c->Router->link('ChangePassword', ['email' => $v->email, 'key' => $key, 'hash' => $hash]);
|
|
|
|
- $tplData = [
|
|
|
|
- 'fRootLink' => $this->c->Router->link('Index'),
|
|
|
|
- 'fMailer' => \ForkBB\__('Mailer', $this->c->config->o_board_title),
|
|
|
|
- 'username' => $this->tmpUser->username,
|
|
|
|
- 'link' => $link,
|
|
|
|
- ];
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- $isSent = $this->c->Mail
|
|
|
|
- ->reset()
|
|
|
|
- ->setFolder($this->c->DIR_LANG)
|
|
|
|
- ->setLanguage($this->tmpUser->language)
|
|
|
|
- ->setTo($v->email, $this->tmpUser->username)
|
|
|
|
- ->setFrom($this->c->config->o_webmaster_email, \ForkBB\__('Mailer', $this->c->config->o_board_title))
|
|
|
|
- ->setTpl('passphrase_reset.tpl', $tplData)
|
|
|
|
- ->send();
|
|
|
|
- } catch (MailException $e) {
|
|
|
|
- $isSent = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ($isSent) {
|
|
|
|
- $this->tmpUser->activate_string = $key;
|
|
|
|
- $this->tmpUser->last_email_sent = time();
|
|
|
|
- $this->c->users->update($this->tmpUser);
|
|
|
|
- return $this->c->Message->message(\ForkBB\__('Forget mail', $this->c->config->o_admin_email), false, 200);
|
|
|
|
- } else {
|
|
|
|
- return $this->c->Message->message(\ForkBB\__('Error mail', $this->c->config->o_admin_email), true, 200);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Дополнительная проверка email
|
|
* Дополнительная проверка email
|
|
*
|
|
*
|
|
@@ -249,17 +222,14 @@ class Auth extends Page
|
|
public function vCheckEmail(Validator $v, $email)
|
|
public function vCheckEmail(Validator $v, $email)
|
|
{
|
|
{
|
|
if (! empty($v->getErrors())) {
|
|
if (! empty($v->getErrors())) {
|
|
- return $email;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// email забанен
|
|
// email забанен
|
|
- if ($this->c->bans->isBanned($this->c->users->create(['email' => $email])) > 0) {
|
|
|
|
|
|
+ } elseif ($this->c->bans->isBanned($this->c->users->create(['email' => $email])) > 0) {
|
|
$v->addError('Banned email');
|
|
$v->addError('Banned email');
|
|
// нет пользователя с таким email
|
|
// нет пользователя с таким email
|
|
} elseif (! ($user = $this->c->users->load($email, 'email')) instanceof User) {
|
|
} elseif (! ($user = $this->c->users->load($email, 'email')) instanceof User) {
|
|
$v->addError('Invalid email');
|
|
$v->addError('Invalid email');
|
|
// за последний час уже был запрос на этот email
|
|
// за последний час уже был запрос на этот email
|
|
- } elseif (! empty($user->last_email_sent) && time() - $user->last_email_sent < 3600) {
|
|
|
|
|
|
+ } elseif ($user->last_email_sent > 0 && time() - $user->last_email_sent < 3600) {
|
|
$v->addError(\ForkBB\__('Email flood', (int) (($user->last_email_sent + 3600 - time()) / 60)), 'e');
|
|
$v->addError(\ForkBB\__('Email flood', (int) (($user->last_email_sent + 3600 - time()) / 60)), 'e');
|
|
} else {
|
|
} else {
|
|
$this->tmpUser = $user;
|
|
$this->tmpUser = $user;
|
|
@@ -268,33 +238,57 @@ class Auth extends Page
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Подготовка данных для формы изменения пароля
|
|
|
|
|
|
+ * Смена кодовой фразы
|
|
*
|
|
*
|
|
* @param array $args
|
|
* @param array $args
|
|
|
|
+ * @param string $method
|
|
*
|
|
*
|
|
* @return Page
|
|
* @return Page
|
|
*/
|
|
*/
|
|
- public function changePass(array $args)
|
|
|
|
|
|
+ public function changePass(array $args, $method)
|
|
{
|
|
{
|
|
- if (isset($args['_user'])) {
|
|
|
|
- $user = $args['_user'];
|
|
|
|
- unset($args['_user']);
|
|
|
|
- } else {
|
|
|
|
- // что-то пошло не так
|
|
|
|
- if (! hash_equals($args['hash'], $this->c->Secury->hash($args['email'] . $args['key']))
|
|
|
|
- || ! ($user = $this->c->users->load($args['email'], 'email')) instanceof User
|
|
|
|
- || empty($user->activate_string)
|
|
|
|
- || $user->activate_string{0} !== 'p'
|
|
|
|
- || ! hash_equals($user->activate_string, $args['key'])
|
|
|
|
- ) {
|
|
|
|
- return $this->c->Message->message('Bad request', false);
|
|
|
|
- }
|
|
|
|
|
|
+ // что-то пошло не так
|
|
|
|
+ if (! hash_equals($args['hash'], $this->c->Secury->hash($args['email'] . $args['key']))
|
|
|
|
+ || ! ($user = $this->c->users->load($args['email'], 'email')) instanceof User
|
|
|
|
+ || empty($user->activate_string)
|
|
|
|
+ || 'p' !== $user->activate_string{0}
|
|
|
|
+ || ! hash_equals($user->activate_string, $args['key'])
|
|
|
|
+ ) {
|
|
|
|
+ return $this->c->Message->message('Bad request', false);
|
|
}
|
|
}
|
|
|
|
|
|
$this->c->Lang->load('auth');
|
|
$this->c->Lang->load('auth');
|
|
|
|
|
|
|
|
+ if ('POST' === $method) {
|
|
|
|
+ $v = $this->c->Validator->setRules([
|
|
|
|
+ 'token' => 'token:ChangePassword',
|
|
|
|
+ 'password' => 'required|string|min:16|password',
|
|
|
|
+ 'password2' => 'required|same:password',
|
|
|
|
+ ])->setAliases([
|
|
|
|
+ 'password' => 'New pass',
|
|
|
|
+ 'password2' => 'Confirm new pass',
|
|
|
|
+ ])->setArguments([
|
|
|
|
+ 'token' => $args,
|
|
|
|
+ ])->setMessages([
|
|
|
|
+ 'password.password' => 'Pass format',
|
|
|
|
+ 'password2.same' => 'Pass not match',
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ if ($v->validation($_POST)) {
|
|
|
|
+ $user->password = password_hash($v->password, PASSWORD_DEFAULT);
|
|
|
|
+ $user->email_confirmed = 1;
|
|
|
|
+ $user->activate_string = null;
|
|
|
|
+ $this->c->users->update($user);
|
|
|
|
+
|
|
|
|
+ $this->a['fIswev']['s'][] = \ForkBB\__('Pass updated');
|
|
|
|
+ return $this->login([], 'GET');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->fIswev = $v->getErrors();
|
|
|
|
+ }
|
|
|
|
+ // активация аккаунта (письмо активации не дошло, заказали восстановление)
|
|
if ($user->isUnverified) {
|
|
if ($user->isUnverified) {
|
|
- $user->group_id = $this->c->config->o_default_user_group;
|
|
|
|
|
|
+ $user->group_id = $this->c->config->o_default_user_group;
|
|
$user->email_confirmed = 1;
|
|
$user->email_confirmed = 1;
|
|
$this->c->users->update($user);
|
|
$this->c->users->update($user);
|
|
$this->c->Cache->delete('stats');
|
|
$this->c->Cache->delete('stats');
|
|
@@ -311,53 +305,4 @@ class Auth extends Page
|
|
|
|
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Смена пароля
|
|
|
|
- *
|
|
|
|
- * @param array $args
|
|
|
|
- *
|
|
|
|
- * @return Page
|
|
|
|
- */
|
|
|
|
- public function changePassPost(array $args)
|
|
|
|
- {
|
|
|
|
- // что-то пошло не так
|
|
|
|
- if (! hash_equals($args['hash'], $this->c->Secury->hash($args['email'] . $args['key']))
|
|
|
|
- || ! ($user = $this->c->users->load($args['email'], 'email')) instanceof User
|
|
|
|
- || empty($user->activate_string)
|
|
|
|
- || $user->activate_string{0} !== 'p'
|
|
|
|
- || ! hash_equals($user->activate_string, $args['key'])
|
|
|
|
- ) {
|
|
|
|
- return $this->c->Message->message('Bad request', false);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $this->c->Lang->load('auth');
|
|
|
|
-
|
|
|
|
- $v = $this->c->Validator;
|
|
|
|
- $v->setRules([
|
|
|
|
- 'token' => 'token:ChangePassword',
|
|
|
|
- 'password' => ['required|string|min:16|password', \ForkBB\__('New pass')],
|
|
|
|
- 'password2' => ['required|same:password', \ForkBB\__('Confirm new pass')],
|
|
|
|
- ])->setArguments([
|
|
|
|
- 'token' => $args,
|
|
|
|
- ])->setMessages([
|
|
|
|
- 'password.password' => 'Pass format',
|
|
|
|
- 'password2.same' => 'Pass not match',
|
|
|
|
- ]);
|
|
|
|
-
|
|
|
|
- if (! $v->validation($_POST)) {
|
|
|
|
- $this->fIswev = $v->getErrors();
|
|
|
|
- $args['_user'] = $user;
|
|
|
|
- return $this->changePass($args);
|
|
|
|
- }
|
|
|
|
- $data = $v->getData();
|
|
|
|
-
|
|
|
|
- $user->password = password_hash($data['password'], PASSWORD_DEFAULT);
|
|
|
|
- $user->email_confirmed = 1;
|
|
|
|
- $user->activate_string = null;
|
|
|
|
- $this->c->users->update($user);
|
|
|
|
-
|
|
|
|
- $this->a['fIswev']['s'][] = \ForkBB\__('Pass updated');
|
|
|
|
- return $this->login(['_redirect' => $this->c->Router->link('Index')]);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|