mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Код модели подтверждения через email теперь является первичным ключом тамблицы
Реализована форма подтверждения email, обмазана тестами Слегка отрефакторена форма регистрации и авторизации в пользу выноса части логики в общего родителя Проект зачищен от стандартных тестовых параметров Пофикшены методы доступа к API
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use api\models\ConfirmEmailForm;
|
||||
use api\models\RegistrationForm;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
@ -10,11 +11,10 @@ class SignupController extends Controller {
|
||||
public function behaviors() {
|
||||
return array_merge(parent::behaviors(), [
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'only' => ['register'],
|
||||
'class' => AccessControl::class,
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['register'],
|
||||
'actions' => ['register', 'confirm'],
|
||||
'allow' => true,
|
||||
'roles' => ['?'],
|
||||
],
|
||||
@ -23,6 +23,13 @@ class SignupController extends Controller {
|
||||
]);
|
||||
}
|
||||
|
||||
public function verbs() {
|
||||
return [
|
||||
'register' => ['POST'],
|
||||
'confirm' => ['POST'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionRegister() {
|
||||
$model = new RegistrationForm();
|
||||
$model->load(Yii::$app->request->post());
|
||||
@ -38,4 +45,24 @@ class SignupController extends Controller {
|
||||
];
|
||||
}
|
||||
|
||||
public function actionConfirm() {
|
||||
$model = new ConfirmEmailForm();
|
||||
$model->load(Yii::$app->request->post());
|
||||
if (!$model->confirm()) {
|
||||
return [
|
||||
'success' => false,
|
||||
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
||||
];
|
||||
}
|
||||
|
||||
// TODO: не уверен, что логин должен быть здесь + нужно разобраться с параметрами установки куки авторизации и сессии
|
||||
$activationCode = $model->getActivationCodeModel();
|
||||
$account = $activationCode->account;
|
||||
Yii::$app->user->login($account);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user