2013-05-24 10:14:49 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\controllers;
|
|
|
|
|
2024-02-09 12:15:09 +08:00
|
|
|
use app\models\EntryForm;
|
2013-05-24 10:14:49 -04:00
|
|
|
use Yii;
|
2014-04-05 01:00:14 -04:00
|
|
|
use yii\filters\AccessControl;
|
2013-05-24 10:14:49 -04:00
|
|
|
use yii\web\Controller;
|
2014-04-05 01:00:14 -04:00
|
|
|
use yii\filters\VerbFilter;
|
2013-05-24 10:14:49 -04:00
|
|
|
|
|
|
|
class SiteController extends Controller
|
|
|
|
{
|
2016-06-19 16:56:22 +03:00
|
|
|
/**
|
2018-02-19 00:29:21 +02:00
|
|
|
* {@inheritdoc}
|
2016-06-19 16:56:22 +03:00
|
|
|
*/
|
2024-03-17 15:37:13 +08:00
|
|
|
public function behaviors(): array
|
2014-03-16 10:46:16 +06:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'access' => [
|
2022-02-25 14:58:50 +00:00
|
|
|
'class' => AccessControl::class,
|
2014-03-16 10:46:16 +06:00
|
|
|
'only' => ['logout'],
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'actions' => ['logout'],
|
|
|
|
'allow' => true,
|
|
|
|
'roles' => ['@'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'verbs' => [
|
2022-02-25 14:58:50 +00:00
|
|
|
'class' => VerbFilter::class,
|
2014-03-16 10:46:16 +06:00
|
|
|
'actions' => [
|
|
|
|
'logout' => ['post'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2024-03-21 14:00:10 +08:00
|
|
|
public function init(): void
|
|
|
|
{
|
|
|
|
parent::init();
|
2013-09-16 02:41:19 +04:00
|
|
|
|
2024-03-21 14:00:10 +08:00
|
|
|
if (Yii::$app->user->can('admin')) {
|
|
|
|
$this->layout = 'admin_main';
|
|
|
|
}elseif (Yii::$app->user->isGuest) {
|
|
|
|
$this->layout = 'guest_main';
|
|
|
|
} else {
|
|
|
|
$this->layout = 'main';
|
|
|
|
}
|
|
|
|
}
|
2016-06-19 16:56:22 +03:00
|
|
|
/**
|
2018-02-19 00:29:21 +02:00
|
|
|
* {@inheritdoc}
|
2016-06-19 16:56:22 +03:00
|
|
|
*/
|
2024-03-17 15:37:13 +08:00
|
|
|
public function actions(): array
|
2014-03-16 10:46:16 +06:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'error' => [
|
|
|
|
'class' => 'yii\web\ErrorAction',
|
|
|
|
],
|
|
|
|
'captcha' => [
|
|
|
|
'class' => 'yii\captcha\CaptchaAction',
|
|
|
|
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2013-05-24 10:14:49 -04:00
|
|
|
|
2016-06-19 16:56:22 +03:00
|
|
|
/**
|
|
|
|
* Displays homepage.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2024-03-17 15:37:13 +08:00
|
|
|
public function actionIndex(): string
|
2014-03-16 10:46:16 +06:00
|
|
|
{
|
|
|
|
return $this->render('index');
|
|
|
|
}
|
2013-05-24 10:14:49 -04:00
|
|
|
|
2024-02-09 12:15:09 +08:00
|
|
|
|
2024-03-17 15:37:13 +08:00
|
|
|
public function actionEntry(): string
|
2024-02-09 12:15:09 +08:00
|
|
|
{
|
|
|
|
$model = new EntryForm();
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
|
|
|
return $this->render('entry-confirm', ['model' => $model]);
|
|
|
|
} else {
|
|
|
|
return $this->render('entry', ['model' => $model]);
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 03:14:28 +01:00
|
|
|
}
|