Реализована форма восстановления пароля от аккаунта

Логика проверки пароля вынесена в отдельный валидатор
В composer.json докинута зависимость от php7
This commit is contained in:
ErickSkrauch
2016-05-12 01:13:19 +03:00
parent ebf4947c37
commit 2a4da87fd5
9 changed files with 201 additions and 8 deletions

View File

@ -3,6 +3,7 @@ namespace api\controllers;
use api\models\ForgotPasswordForm;
use api\models\LoginForm;
use api\models\RecoverPasswordForm;
use common\helpers\StringHelper;
use Yii;
use yii\filters\AccessControl;
@ -13,13 +14,13 @@ class AuthenticationController extends Controller {
public function behaviors() {
return ArrayHelper::merge(parent::behaviors(), [
'authenticator' => [
'except' => ['login', 'forgot-password'],
'except' => ['login', 'forgot-password', 'recover-password'],
],
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['login', 'forgot-password'],
'actions' => ['login', 'forgot-password', 'recover-password'],
'allow' => true,
'roles' => ['?'],
],
@ -32,6 +33,7 @@ class AuthenticationController extends Controller {
return [
'login' => ['POST'],
'forgot-password' => ['POST'],
'recover-password' => ['POST'],
];
}
@ -93,4 +95,20 @@ class AuthenticationController extends Controller {
return $response;
}
public function actionRecoverPassword() {
$model = new RecoverPasswordForm();
$model->load(Yii::$app->request->post());
if (($jwt = $model->recoverPassword()) === false) {
return [
'success' => false,
'errors' => $this->normalizeModelErrors($model->getErrors()),
];
}
return [
'success' => true,
'jwt' => $jwt,
];
}
}