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;
|
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
|
|
|
|
{
|
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
|
|
|
|
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
|
|
|
|
2014-03-16 12:46:16 +08:00
|
|
|
public function actionIndex()
|
|
|
|
{
|
|
|
|
return $this->render('index');
|
|
|
|
}
|
2013-05-24 22:14:49 +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();
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public function actionAbout()
|
|
|
|
{
|
|
|
|
return $this->render('about');
|
|
|
|
}
|
2014-02-16 10:14:28 +08:00
|
|
|
}
|