SiteController.php 1000 Bytes
Newer Older
Qiang Xue committed
1 2
<?php

3
use yii\web\Controller;
Qiang Xue committed
4
use app\models\LoginForm;
5
use app\models\ContactForm;
Qiang Xue committed
6

7
class SiteController extends Controller
Qiang Xue committed
8 9 10 11 12 13 14 15
{
	public function actionIndex()
	{
		echo $this->render('index');
	}

	public function actionLogin()
	{
Qiang Xue committed
16
		$model = new LoginForm();
17
		if ($this->populate($_POST, $model) && $model->login()) {
18
			Yii::$app->response->redirect(array('site/index'));
19 20 21 22
		} else {
			echo $this->render('login', array(
				'model' => $model,
			));
Qiang Xue committed
23
		}
Qiang Xue committed
24 25 26 27 28 29 30
	}

	public function actionLogout()
	{
		Yii::$app->getUser()->logout();
		Yii::$app->getResponse()->redirect(array('site/index'));
	}
Qiang Xue committed
31 32 33

	public function actionContact()
	{
34 35
		$model = new ContactForm;
		if ($this->populate($_POST, $model) && $model->contact(Yii::$app->params['adminEmail'])) {
Qiang Xue committed
36
			Yii::$app->session->setFlash('contactFormSubmitted');
37 38 39 40 41 42
			Yii::$app->response->refresh();
		} else {
			echo $this->render('contact', array(
				'model' => $model,
			));
		}
Qiang Xue committed
43 44 45 46 47 48
	}

	public function actionAbout()
	{
		echo $this->render('about');
	}
Qiang Xue committed
49
}