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 17 18 19 20
	public function actions()
	{
		return array(
			'captcha' => array(
				'class' => 'yii\web\CaptchaAction',
			),
		);
	}

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

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

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

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

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