SiteController.php 1.13 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 23 24 25 26 27
	public function actionIndex()
	{
		echo $this->render('index');
	}

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

	public function actionLogout()
	{
		Yii::$app->getUser()->logout();
		Yii::$app->getResponse()->redirect(array('site/index'));
	}
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 50 51 52 53 54
			Yii::$app->response->refresh();
		} else {
			echo $this->render('contact', array(
				'model' => $model,
			));
		}
Qiang Xue committed
55 56 57 58 59 60
	}

	public function actionAbout()
	{
		echo $this->render('about');
	}
Zander Baldwin committed
61
}