SiteController.php 1.17 KB
Newer Older
1 2
<?php

3
namespace frontend\controllers;
4 5 6

use Yii;
use yii\web\Controller;
7 8
use common\models\LoginForm;
use frontend\models\ContactForm;
9 10 11 12 13 14 15 16 17 18 19 20 21 22

class SiteController extends Controller
{
	public function actions()
	{
		return array(
			'captcha' => array(
				'class' => 'yii\web\CaptchaAction',
			),
		);
	}

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

	public function actionLogin()
	{
		$model = new LoginForm();
		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 35 36 37 38 39
				'model' => $model,
			));
		}
	}

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

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

	public function actionAbout()
	{
59
		return $this->render('about');
60 61
	}
}