mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Добавлен action для формы восстановления пароля
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use api\models\ForgotPasswordForm;
|
||||
use api\models\LoginForm;
|
||||
use common\helpers\StringHelper;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
@@ -11,13 +13,13 @@ class AuthenticationController extends Controller {
|
||||
public function behaviors() {
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
'authenticator' => [
|
||||
'except' => ['login'],
|
||||
'except' => ['login', 'forgot-password'],
|
||||
],
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['login'],
|
||||
'actions' => ['login', 'forgot-password'],
|
||||
'allow' => true,
|
||||
'roles' => ['?'],
|
||||
],
|
||||
@@ -29,6 +31,7 @@ class AuthenticationController extends Controller {
|
||||
public function verbs() {
|
||||
return [
|
||||
'login' => ['POST'],
|
||||
'forgot-password' => ['POST'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -54,4 +57,40 @@ class AuthenticationController extends Controller {
|
||||
];
|
||||
}
|
||||
|
||||
public function actionForgotPassword() {
|
||||
$model = new ForgotPasswordForm();
|
||||
$model->load(Yii::$app->request->post());
|
||||
if ($model->forgotPassword() === false) {
|
||||
$data = [
|
||||
'success' => false,
|
||||
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
||||
];
|
||||
|
||||
if (ArrayHelper::getValue($data['errors'], 'login') === 'error.email_frequency') {
|
||||
$emailActivation = $model->getEmailActivation();
|
||||
$data['data'] = [
|
||||
'canRepeatIn' => $emailActivation->canRepeatIn(),
|
||||
'repeatFrequency' => $emailActivation->repeatTimeout,
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
$emailActivation = $model->getEmailActivation();
|
||||
$response = [
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'canRepeatIn' => $emailActivation->canRepeatIn(),
|
||||
'repeatFrequency' => $emailActivation->repeatTimeout,
|
||||
],
|
||||
];
|
||||
|
||||
if ($model->getLoginAttribute() !== 'email') {
|
||||
$response['data']['emailMask'] = StringHelper::getEmailMask($model->getAccount()->email);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user