Отрефакторены тесты

Удалено тестовое окружение acceptance
Удалена часть потенциально ненужных тестов
Добавлена логика для формы регистрации
Добавлена таблица для хранения ключей активации по E-mail
Добавлены тесты для формы регистрации
Реорганизован роутинг
Добавлен компонент для ReCaptcha2
This commit is contained in:
ErickSkrauch
2016-01-15 12:21:27 +03:00
parent 45c31dfbbe
commit 44aaea2c08
56 changed files with 1075 additions and 972 deletions

View 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,
];
}
}

View File

@ -1,8 +1,10 @@
<?php
namespace api\controllers;
use api\traits\ApiNormalize;
class Controller extends \yii\rest\Controller {
use ApiNormalize;
public $enableCsrfValidation = true;

View 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,
];
}
}

View File

@ -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.
*