1196281550 2017-12-29 15:08:30 3544次浏览 0条评论 0 0 0
<?php

namespace app\modules\controllers;
header("content-type:text/html;charset=utf-8");
use yii;
use app\modules\models\Admin;

use yii\web\Controller;

/**
 * Default controller for the `admin` module
 */
class AuthController extends Controller
{
    /**
     * Renders the index view for the module
     * @return string
     */
    public $layout = false;
    public function actionSignIn()
    {
        $request = yii::$app->request;
        $admin = new Admin(['scenario'=>'login']);
        $session = yii::$app->session;
        if($request->isPost)
        {
            $post = $request->post();
//            var_dump($post);
            if($admin->load($post) && $admin->validate())
            {
                if($adminInfo = $admin->checkLogin())
                {
                    $leftTime = ($admin->remember) ? 3*24*3600:0;

                    session_set_cookie_params($leftTime);
                    //登录成功

                    $session['admin'] = $adminInfo;
                    $this->redirect(['default/index']);
                }
                else
                {
                    //登录失败
                    return $this->render('signin',['admin'=>$admin]);
                }
            }
            else
            {
                return $this->render('signin',['admin'=>$admin]);
            }
        }
        else
        {
            if($session->get('admin'))
            {
                $this->redirect(['default/index']);
            }
            return $this->render('signin',['admin'=>$admin]);
        }
    }
    /**
     * 管理员退出
     */
    public function actionSignOut()
    {
        //清除SESSION
        $session = yii::$app->session;
        $session->remove('admin');
        $session->destroy();
        $this->redirect(['auth/sign-in']);
    }
}
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册