yii2-netdisk/controllers/SiteController.php

150 lines
3.2 KiB
PHP
Raw Normal View History

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;
use yii\filters\AccessControl;
2013-05-24 10:14:49 -04:00
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
2013-05-24 10:14:49 -04:00
use app\models\LoginForm;
use app\models\ContactForm;
class SiteController extends Controller
{
/**
2018-02-19 00:29:21 +02:00
* {@inheritdoc}
*/
2014-03-16 10:46:16 +06:00
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
2014-03-16 10:46:16 +06:00
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
2014-03-16 10:46:16 +06:00
'actions' => [
'logout' => ['post'],
],
],
];
}
/**
2018-02-19 00:29:21 +02:00
* {@inheritdoc}
*/
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
/**
* 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
/**
* Login action.
*
* @return Response|string
*/
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();
}
2014-03-16 10:46:16 +06:00
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
$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
/**
* Logout action.
*
* @return Response
*/
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
/**
* Displays contact page.
*
* @return Response|string
*/
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
}
/**
* 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]);
}
}
}