yii2-netdisk/controllers/SiteController.php

97 lines
2.2 KiB
PHP
Raw Normal View History

2013-05-24 10:14:49 -04:00
<?php
namespace app\controllers;
use Yii;
use yii\web\AccessControl;
2013-05-24 10:14:49 -04:00
use yii\web\Controller;
use yii\web\VerbFilter;
2013-05-24 10:14:49 -04:00
use app\models\LoginForm;
use app\models\ContactForm;
class SiteController extends Controller
{
2014-03-16 10:46:16 +06: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 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
2014-03-16 10:46:16 +06:00
public function actionIndex()
{
return $this->render('index');
}
2013-05-24 10:14:49 -04:00
2014-03-16 10:46:16 +06:00
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
2014-03-16 10:46:16 +06:00
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
}
}
2013-05-24 10:14:49 -04: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
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();
} else {
return $this->render('contact', [
'model' => $model,
]);
}
}
public function actionAbout()
{
return $this->render('about');
}
}