mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Отрефакторены тесты
Удалено тестовое окружение acceptance Удалена часть потенциально ненужных тестов Добавлена логика для формы регистрации Добавлена таблица для хранения ключей активации по E-mail Добавлены тесты для формы регистрации Реорганизован роутинг Добавлен компонент для ReCaptcha2
This commit is contained in:
48
api/controllers/AuthenticationController.php
Normal file
48
api/controllers/AuthenticationController.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use api\models\LoginForm;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
|
||||
class AuthenticationController extends Controller {
|
||||
|
||||
public function behaviors() {
|
||||
return array_merge(parent::behaviors(), [
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'only' => ['login'],
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['login', 'register'],
|
||||
'allow' => true,
|
||||
'roles' => ['?'],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function verbs() {
|
||||
return [
|
||||
'login' => ['post'],
|
||||
'register' => ['post'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionLogin() {
|
||||
$model = new LoginForm();
|
||||
$model->load(Yii::$app->request->post());
|
||||
if (!$model->login()) {
|
||||
return [
|
||||
'success' => false,
|
||||
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use api\traits\ApiNormalize;
|
||||
|
||||
class Controller extends \yii\rest\Controller {
|
||||
use ApiNormalize;
|
||||
|
||||
public $enableCsrfValidation = true;
|
||||
|
||||
|
41
api/controllers/SignupController.php
Normal file
41
api/controllers/SignupController.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use api\models\RegistrationForm;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
|
||||
class SignupController extends Controller {
|
||||
|
||||
public function behaviors() {
|
||||
return array_merge(parent::behaviors(), [
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'only' => ['register'],
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['register'],
|
||||
'allow' => true,
|
||||
'roles' => ['?'],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionRegister() {
|
||||
$model = new RegistrationForm();
|
||||
$model->load(Yii::$app->request->post());
|
||||
if (!$model->signup()) {
|
||||
return [
|
||||
'success' => false,
|
||||
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
namespace api\controllers;
|
||||
|
||||
use api\models\ContactForm;
|
||||
use api\models\LoginForm;
|
||||
use api\models\PasswordResetRequestForm;
|
||||
use api\models\ResetPasswordForm;
|
||||
use api\models\SignupForm;
|
||||
@ -11,12 +10,11 @@ use yii\base\InvalidParamException;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Site controller
|
||||
*/
|
||||
class SiteController extends Controller
|
||||
class SiteController extends \yii\web\Controller
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -75,27 +73,6 @@ class SiteController extends Controller
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in a user.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionLogin()
|
||||
{
|
||||
if (!\Yii::$app->user->isGuest) {
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
$model = new LoginForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
||||
return $this->goBack();
|
||||
} else {
|
||||
return $this->render('login', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out the current user.
|
||||
*
|
||||
|
Reference in New Issue
Block a user