Добавлена форма смены пароля и её тесты

This commit is contained in:
ErickSkrauch
2016-02-27 01:22:09 +03:00
parent 86c63f8724
commit 93a94c656b
7 changed files with 259 additions and 24 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace api\controllers;
use api\models\ChangePasswordForm;
use common\models\Account;
use Yii;
use yii\filters\AccessControl;
@ -14,7 +15,7 @@ class AccountsController extends Controller {
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['current'],
'actions' => ['current', 'change-password'],
'allow' => true,
'roles' => ['@'],
],
@ -26,6 +27,7 @@ class AccountsController extends Controller {
public function verbs() {
return [
'current' => ['GET'],
'change-password' => ['POST'],
];
}
@ -42,4 +44,21 @@ class AccountsController extends Controller {
];
}
public function actionChangePassword() {
/** @var Account $account */
$account = Yii::$app->user->identity;
$model = new ChangePasswordForm($account);
$model->load(Yii::$app->request->post());
if (!$model->changePassword()) {
return [
'success' => false,
'errors' => $this->normalizeModelErrors($model->getErrors()),
];
}
return [
'success' => true,
];
}
}