Добавлен action для принятия правил + тесты для него

This commit is contained in:
ErickSkrauch
2016-08-06 19:22:09 +03:00
parent cf6c7bc88e
commit 16fc1ecb8c
6 changed files with 133 additions and 1 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace api\controllers;
use api\models\profile\AcceptRulesForm;
use api\models\profile\ChangeEmail\ConfirmNewEmailForm;
use api\models\profile\ChangeEmail\InitStateForm;
use api\models\profile\ChangeEmail\NewEmailForm;
@ -21,7 +22,7 @@ class AccountsController extends Controller {
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['current'],
'actions' => ['current', 'accept-rules'],
'allow' => true,
'roles' => ['@'],
],
@ -57,6 +58,7 @@ class AccountsController extends Controller {
'change-email-submit-new-email' => ['POST'],
'change-email-confirm-new-email' => ['POST'],
'change-lang' => ['POST'],
'accept-rules' => ['POST'],
];
}
@ -185,4 +187,20 @@ class AccountsController extends Controller {
];
}
public function actionAcceptRules() {
$account = Yii::$app->user->identity;
$model = new AcceptRulesForm($account);
$model->load(Yii::$app->request->post());
if (!$model->agreeWithLatestRules()) {
return [
'success' => false,
'errors' => $this->normalizeModelErrors($model->getErrors()),
];
}
return [
'success' => true,
];
}
}