2013-05-24 22:14:49 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\controllers;
|
|
|
|
|
|
|
|
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;
|
2017-04-11 20:47:45 +08:00
|
|
|
use yii\web\Response;
|
2014-04-05 13:00:14 +08:00
|
|
|
use yii\filters\VerbFilter;
|
2013-05-24 22:14:49 +08:00
|
|
|
use app\models\LoginForm;
|
|
|
|
use app\models\ContactForm;
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2014-03-16 12:46:16 +08:00
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'access' => [
|
|
|
|
'class' => AccessControl::className(),
|
|
|
|
'only' => ['logout'],
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'actions' => ['logout'],
|
|
|
|
'allow' => true,
|
|
|
|
'roles' => ['@'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'verbs' => [
|
|
|
|
'class' => VerbFilter::className(),
|
|
|
|
'actions' => [
|
|
|
|
'logout' => ['post'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2013-09-16 06:41:19 +08:00
|
|
|
|
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
|
|
|
*/
|
2014-03-16 12:46:16 +08:00
|
|
|
public function actions()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
2014-03-16 12:46:16 +08:00
|
|
|
public function actionIndex()
|
|
|
|
{
|
|
|
|
return $this->render('index');
|
|
|
|
}
|
2013-05-24 22:14:49 +08:00
|
|
|
|
2016-06-19 21:56:22 +08:00
|
|
|
/**
|
|
|
|
* Login action.
|
|
|
|
*
|
2017-04-11 20:47:45 +08:00
|
|
|
* @return Response|string
|
2016-06-19 21:56:22 +08:00
|
|
|
*/
|
2014-03-16 12:46:16 +08:00
|
|
|
public function actionLogin()
|
|
|
|
{
|
2016-03-09 23:47:19 +08:00
|
|
|
if (!Yii::$app->user->isGuest) {
|
2014-03-16 12:46:16 +08:00
|
|
|
return $this->goHome();
|
|
|
|
}
|
2013-11-07 05:19:36 +08:00
|
|
|
|
2014-03-16 12:46:16 +08:00
|
|
|
$model = new LoginForm();
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
|
|
|
return $this->goBack();
|
|
|
|
}
|
2017-11-16 17:03:46 +08:00
|
|
|
|
|
|
|
$model->password = '';
|
2015-06-05 22:39:43 +08:00
|
|
|
return $this->render('login', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
2014-03-16 12:46:16 +08:00
|
|
|
}
|
2013-05-24 22:14:49 +08:00
|
|
|
|
2016-06-19 21:56:22 +08:00
|
|
|
/**
|
|
|
|
* Logout action.
|
|
|
|
*
|
2017-04-11 20:47:45 +08:00
|
|
|
* @return Response
|
2016-06-19 21:56:22 +08:00
|
|
|
*/
|
2014-03-16 12:46:16 +08:00
|
|
|
public function actionLogout()
|
|
|
|
{
|
|
|
|
Yii::$app->user->logout();
|
2013-05-24 22:14:49 +08:00
|
|
|
|
2014-03-16 12:46:16 +08:00
|
|
|
return $this->goHome();
|
|
|
|
}
|
2013-05-24 22:14:49 +08:00
|
|
|
|
2016-06-19 21:56:22 +08:00
|
|
|
/**
|
|
|
|
* Displays contact page.
|
|
|
|
*
|
2017-04-11 20:47:45 +08:00
|
|
|
* @return Response|string
|
2016-06-19 21:56:22 +08:00
|
|
|
*/
|
2014-03-16 12:46:16 +08: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 22:39:43 +08:00
|
|
|
return $this->render('contact', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
2014-03-16 12:46:16 +08:00
|
|
|
}
|
|
|
|
|
2016-06-19 21:56:22 +08:00
|
|
|
/**
|
|
|
|
* Displays about page.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-03-16 12:46:16 +08:00
|
|
|
public function actionAbout()
|
|
|
|
{
|
|
|
|
return $this->render('about');
|
|
|
|
}
|
2014-02-16 10:14:28 +08:00
|
|
|
}
|