2018-10-11 11:15:09 +03:00
|
|
|
<?php
|
|
|
|
namespace backend\controllers;
|
|
|
|
|
|
|
|
use Yii;
|
|
|
|
use yii\web\Controller;
|
|
|
|
use yii\filters\VerbFilter;
|
|
|
|
use yii\filters\AccessControl;
|
|
|
|
use common\models\LoginForm;
|
2020-01-29 11:26:01 +03:00
|
|
|
use yii\helpers\Url;
|
2018-10-11 11:15:09 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Site controller
|
|
|
|
*/
|
|
|
|
class SiteController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'verbs' => [
|
|
|
|
'class' => VerbFilter::className(),
|
|
|
|
'actions' => [
|
|
|
|
'logout' => ['post'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function actions()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'error' => [
|
|
|
|
'class' => 'yii\web\ErrorAction',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays homepage.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function actionIndex()
|
|
|
|
{
|
|
|
|
return $this->render('index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Login action.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function actionLogin()
|
|
|
|
{
|
|
|
|
if (!Yii::$app->user->isGuest) {
|
|
|
|
return $this->goHome();
|
|
|
|
}
|
|
|
|
|
|
|
|
$model = new LoginForm();
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
2020-01-29 11:26:01 +03:00
|
|
|
if (\Yii::$app->user->can('secure')) {
|
|
|
|
return $this->goBack();
|
|
|
|
} else {
|
|
|
|
Yii::$app->user->logout();
|
|
|
|
return $this->redirect(Url::to('/card/user-card'));
|
|
|
|
}
|
2018-10-11 11:15:09 +03:00
|
|
|
} else {
|
|
|
|
$model->password = '';
|
|
|
|
return $this->render('login', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logout action.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function actionLogout()
|
|
|
|
{
|
|
|
|
Yii::$app->user->logout();
|
|
|
|
|
|
|
|
return $this->goHome();
|
|
|
|
}
|
|
|
|
}
|