SiteController.php 1.15 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 15 16
	public function actions()
	{
		return array(
			'captcha' => array(
				'class' => 'yii\web\CaptchaAction',
17
				'fixedVerifyCode' => YII_ENV === 'test' ? 'testme' : null,
18 19 20 21
			),
		);
	}

Qiang Xue committed
22 23
	public function actionIndex()
	{
24
		return $this->render('index');
Qiang Xue committed
25 26 27 28
	}

	public function actionLogin()
	{
Qiang Xue committed
29
		$model = new LoginForm();
30 31
		if ($model->load($_POST) && $model->login()) {
			return $this->redirect(array('site/index'));
32
		} else {
33
			return $this->render('login', array(
34 35
				'model' => $model,
			));
Qiang Xue committed
36
		}
Qiang Xue committed
37 38 39 40
	}

	public function actionLogout()
	{
41
		Yii::$app->user->logout();
42
		return $this->redirect(array('site/index'));
Qiang Xue committed
43
	}
Qiang Xue committed
44 45 46

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

	public function actionAbout()
	{
60
		return $this->render('about');
Qiang Xue committed
61
	}
Zander Baldwin committed
62
}