SiteController.php 1.1 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
	}

	public function actionLogin()
	{
		$model = new LoginForm();
29 30
		if ($model->load($_POST) && $model->login()) {
			return $this->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 $this->redirect(array('site/index'));
42 43 44 45 46
	}

	public function actionContact()
	{
		$model = new ContactForm;
47
		if ($model->load($_POST) && $model->contact(Yii::$app->params['adminEmail'])) {
48
			Yii::$app->session->setFlash('contactFormSubmitted');
49
			return $this->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
	}
}