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