SiteController.php 1.42 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
use common\models\User;
10 11 12 13 14 15 16 17 18 19 20 21 22 23

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

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

	public function actionLogin()
	{
		$model = new LoginForm();
30 31
		if ($model->load($_POST) && $model->login()) {
			return $this->redirect(array('site/index'));
32
		} else {
33
			return $this->render('login', array(
34 35 36 37 38 39 40
				'model' => $model,
			));
		}
	}

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

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

	public function actionAbout()
	{
60
		return $this->render('about');
61
	}
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

	public function actionSignup()
	{
		$model = new User();
		$model->setScenario('signup');
		if ($model->load($_POST) && $model->save()) {
			if (Yii::$app->getUser()->login($model)) {
				$this->redirect('index');
			}
		}

		return $this->render('signup', array(
			'model' => $model,
		));
	}
77
}