yii2-netdisk/controllers/SiteController.php

95 lines
2.2 KiB
PHP
Raw Normal View History

2013-05-24 22:14:49 +08:00
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
2013-05-24 22:14:49 +08:00
use yii\web\Controller;
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'],
],
],
];
}
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();
}
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');
}
}