SiteController.php 1.17 KB
Newer Older
Qiang Xue committed
1 2
<?php

3 4
namespace app\controllers;

5
use Yii;
6
use yii\web\Controller;
Qiang Xue committed
7
use app\models\LoginForm;
8
use app\models\ContactForm;
Qiang Xue committed
9

10
class SiteController extends Controller
Qiang Xue committed
11
{
12 13 14
	public function actions()
	{
		return array(
Qiang Xue committed
15 16 17
			'error' => array(
				'class' => 'yii\web\ErrorAction',
			),
18
			'captcha' => array(
Qiang Xue committed
19
				'class' => 'yii\captcha\CaptchaAction',
Qiang Xue committed
20
				'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
21 22 23 24
			),
		);
	}

Qiang Xue committed
25
	public function actionIndex()
Qiang Xue committed
26
	{
27
		return $this->render('index');
Qiang Xue committed
28 29 30 31
	}

	public function actionLogin()
	{
Qiang Xue committed
32
		$model = new LoginForm();
33
		if ($model->load($_POST) && $model->login()) {
Qiang Xue committed
34
			return $this->goHome();
35
		} else {
36
			return $this->render('login', array(
37 38
				'model' => $model,
			));
Qiang Xue committed
39
		}
Qiang Xue committed
40 41 42 43
	}

	public function actionLogout()
	{
44
		Yii::$app->user->logout();
Qiang Xue committed
45
		return $this->goHome();
Qiang Xue committed
46
	}
Qiang Xue committed
47 48 49

	public function actionContact()
	{
50
		$model = new ContactForm;
51
		if ($model->load($_POST) && $model->contact(Yii::$app->params['adminEmail'])) {
Qiang Xue committed
52
			Yii::$app->session->setFlash('contactFormSubmitted');
53
			return $this->refresh();
54
		} else {
55
			return $this->render('contact', array(
56 57 58
				'model' => $model,
			));
		}
Qiang Xue committed
59 60 61 62
	}

	public function actionAbout()
	{
63
		return $this->render('about');
Qiang Xue committed
64
	}
Zander Baldwin committed
65
}