<?php
/**
 * @link      http://www.u-bo.com
 * @copyright 南京友博网络科技有限公司 
 * @license   http://www.u-bo.com/license/
 */

namespace qcbase\controllers;

use Yii;
use qcbase\models\LoginForm;

/**
 * 后台公共控制器
 * 
 * @author legendjw http://blog.u-bo.com
 * @since 0.1
 */
class PublicController extends \yii\web\Controller
{
    public function actions()
    {
        return [
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'minLength' => 4,
                'maxLength' => 4,
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

	/**
	 * 登录页面 
	 */
    public function actionLogin()
    {
		if (!Yii::$app->user->isGuest) {
            return $this->goHome();
        }
		$model = new LoginForm();

        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goHome();
        } else {
			return $this->renderPartial('login', [
                'model' => $model,
			]);
        }
    }

	/**
	 * 退出
	 */
	public function actionLogout()
    {
        Yii::$app->user->logout();

        return $this->goHome();
    }

}
