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;
|
2017-04-11 15:47:45 +03:00
|
|
|
use yii\web\Response;
|
2014-04-05 01:00:14 -04:00
|
|
|
use yii\filters\VerbFilter;
|
2013-05-24 10:14:49 -04:00
|
|
|
use app\models\LoginForm;
|
|
|
|
use app\models\ContactForm;
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2014-03-16 10:46:16 +06:00
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
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'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2013-09-16 02:41:19 +04:00
|
|
|
|
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
|
|
|
*/
|
2014-03-16 10:46:16 +06:00
|
|
|
public function actions()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
2014-03-16 10:46:16 +06:00
|
|
|
public function actionIndex()
|
|
|
|
{
|
|
|
|
return $this->render('index');
|
|
|
|
}
|
2013-05-24 10:14:49 -04:00
|
|
|
|
2016-06-19 16:56:22 +03:00
|
|
|
/**
|
|
|
|
* Login action.
|
|
|
|
*
|
2017-04-11 15:47:45 +03:00
|
|
|
* @return Response|string
|
2016-06-19 16:56:22 +03:00
|
|
|
*/
|
2014-03-16 10:46:16 +06:00
|
|
|
public function actionLogin()
|
|
|
|
{
|
2016-03-09 18:47:19 +03:00
|
|
|
if (!Yii::$app->user->isGuest) {
|
2014-03-16 10:46:16 +06:00
|
|
|
return $this->goHome();
|
|
|
|
}
|
2013-11-07 01:19:36 +04:00
|
|
|
|
2014-03-16 10:46:16 +06:00
|
|
|
$model = new LoginForm();
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
|
|
|
return $this->goBack();
|
|
|
|
}
|
2017-11-16 14:33:46 +05:30
|
|
|
|
|
|
|
$model->password = '';
|
2015-06-05 17:39:43 +03:00
|
|
|
return $this->render('login', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
2014-03-16 10:46:16 +06:00
|
|
|
}
|
2013-05-24 10:14:49 -04:00
|
|
|
|
2016-06-19 16:56:22 +03:00
|
|
|
/**
|
|
|
|
* Logout action.
|
|
|
|
*
|
2017-04-11 15:47:45 +03:00
|
|
|
* @return Response
|
2016-06-19 16:56:22 +03:00
|
|
|
*/
|
2014-03-16 10:46:16 +06:00
|
|
|
public function actionLogout()
|
|
|
|
{
|
|
|
|
Yii::$app->user->logout();
|
2013-05-24 10:14:49 -04:00
|
|
|
|
2014-03-16 10:46:16 +06:00
|
|
|
return $this->goHome();
|
|
|
|
}
|
2013-05-24 10:14:49 -04:00
|
|
|
|
2016-06-19 16:56:22 +03:00
|
|
|
/**
|
|
|
|
* Displays contact page.
|
|
|
|
*
|
2017-04-11 15:47:45 +03:00
|
|
|
* @return Response|string
|
2016-06-19 16:56:22 +03:00
|
|
|
*/
|
2014-03-16 10:46:16 +06:00
|
|
|
public function actionContact()
|
|
|
|
{
|
|
|
|
$model = new ContactForm();
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
|
|
|
|
Yii::$app->session->setFlash('contactFormSubmitted');
|
|
|
|
|
|
|
|
return $this->refresh();
|
|
|
|
}
|
2015-06-05 17:39:43 +03:00
|
|
|
return $this->render('contact', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
2014-03-16 10:46:16 +06:00
|
|
|
}
|
|
|
|
|
2016-06-19 16:56:22 +03:00
|
|
|
/**
|
|
|
|
* Displays about page.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-03-16 10:46:16 +06:00
|
|
|
public function actionAbout()
|
|
|
|
{
|
|
|
|
return $this->render('about');
|
|
|
|
}
|
2024-02-09 12:15:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays hello page.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function actionSay($message = 'hello')
|
|
|
|
{
|
|
|
|
return $this->render('say', ['message' => $message]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionEntry()
|
|
|
|
{
|
|
|
|
$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
|
|
|
}
|