Поле token в контексте otp токенов переименовано в totp

This commit is contained in:
ErickSkrauch
2017-09-06 20:17:52 +03:00
parent 2bdb79b43d
commit 2c08130f4e
16 changed files with 65 additions and 63 deletions

View File

@@ -20,17 +20,17 @@ class ForgotPasswordForm extends ApiForm {
public $login;
public $token;
public $totp;
public function rules() {
return [
['captcha', ReCaptchaValidator::class],
['login', 'required', 'message' => E::LOGIN_REQUIRED],
['login', 'validateLogin'],
['token', 'required', 'when' => function(self $model) {
['totp', 'required', 'when' => function(self $model) {
return !$this->hasErrors() && $model->getAccount()->is_otp_enabled;
}, 'message' => E::OTP_TOKEN_REQUIRED],
['token', 'validateTotpToken'],
}, 'message' => E::TOTP_REQUIRED],
['totp', 'validateTotp'],
['login', 'validateActivity'],
['login', 'validateFrequency'],
];
@@ -44,7 +44,7 @@ class ForgotPasswordForm extends ApiForm {
}
}
public function validateTotpToken($attribute) {
public function validateTotp($attribute) {
if ($this->hasErrors()) {
return;
}

View File

@@ -17,10 +17,10 @@ class LoginForm extends ApiForm {
public $login;
public $password;
public $token;
public $totp;
public $rememberMe = false;
public function rules() {
public function rules(): array {
return [
['login', 'required', 'message' => E::LOGIN_REQUIRED],
['login', 'validateLogin'],
@@ -30,10 +30,10 @@ class LoginForm extends ApiForm {
}, 'message' => E::PASSWORD_REQUIRED],
['password', 'validatePassword'],
['token', 'required', 'when' => function(self $model) {
['totp', 'required', 'when' => function(self $model) {
return !$model->hasErrors() && $model->getAccount()->is_otp_enabled;
}, 'message' => E::OTP_TOKEN_REQUIRED],
['token', 'validateTotpToken'],
}, 'message' => E::TOTP_REQUIRED],
['totp', 'validateTotp'],
['login', 'validateActivity'],
@@ -58,7 +58,7 @@ class LoginForm extends ApiForm {
}
}
public function validateTotpToken($attribute) {
public function validateTotp($attribute) {
if ($this->hasErrors()) {
return;
}

View File

@@ -22,7 +22,7 @@ class TwoFactorAuthForm extends ApiForm {
const SCENARIO_ACTIVATE = 'enable';
const SCENARIO_DISABLE = 'disable';
public $token;
public $totp;
public $timestamp;
@@ -44,8 +44,8 @@ class TwoFactorAuthForm extends ApiForm {
['timestamp', 'integer', 'on' => [self::SCENARIO_ACTIVATE]],
['account', 'validateOtpDisabled', 'on' => self::SCENARIO_ACTIVATE],
['account', 'validateOtpEnabled', 'on' => self::SCENARIO_DISABLE],
['token', 'required', 'message' => E::OTP_TOKEN_REQUIRED, 'on' => $bothScenarios],
['token', TotpValidator::class, 'on' => $bothScenarios,
['totp', 'required', 'message' => E::TOTP_REQUIRED, 'on' => $bothScenarios],
['totp', TotpValidator::class, 'on' => $bothScenarios,
'account' => $this->account,
'timestamp' => function() {
return $this->timestamp;

View File

@@ -36,7 +36,7 @@ class AuthenticationForm extends ApiForm {
$loginForm->password = $this->password;
if (!$loginForm->validate()) {
$errors = $loginForm->getFirstErrors();
if (isset($errors['token'])) {
if (isset($errors['totp'])) {
Authserver::error("User with login = '{$this->username}' protected by two factor auth.");
throw new ForbiddenOperationException('Account protected with two factor auth.');
} elseif (isset($errors['login'])) {

View File

@@ -52,10 +52,10 @@ class TotpValidator extends Validator {
try {
$totp = TOTP::create($this->account->otp_secret);
if (!$totp->verify((string)$value, $this->getTimestamp(), $this->window)) {
return [E::OTP_TOKEN_INCORRECT, []];
return [E::TOTP_INCORRECT, []];
}
} catch (RangeException $e) {
return [E::OTP_TOKEN_INCORRECT, []];
return [E::TOTP_INCORRECT, []];
}
return null;