115 lines
2.4 KiB
PHP
Executable File
115 lines
2.4 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* @Author: fm453
|
|
* @Date: 2018-04-23 14:29:56
|
|
* @Last Modified by: fm453
|
|
* @Last Modified time: 2021-09-08 13:28:31
|
|
* @Email: fm453@lukegzs.com
|
|
*/
|
|
|
|
namespace backend\controllers;
|
|
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use yii\filters\VerbFilter;
|
|
use yii\filters\AccessControl;
|
|
use backend\models\LoginForm;
|
|
use backend\models\Menu;
|
|
|
|
use backend\components\Helper;
|
|
|
|
/**
|
|
* Site controller
|
|
*/
|
|
class SiteController extends Controller
|
|
{
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function behaviors()
|
|
{
|
|
return [
|
|
'access' => [
|
|
'class' => AccessControl::className(),
|
|
'rules' => [
|
|
[
|
|
'actions' => ['login', 'error'],
|
|
'allow' => true,
|
|
],
|
|
[
|
|
'actions' => ['logout', 'index'],
|
|
'allow' => true,
|
|
'roles' => ['@'],
|
|
],
|
|
],
|
|
],
|
|
'verbs' => [
|
|
'class' => VerbFilter::className(),
|
|
'actions' => [
|
|
'logout' => ['get'],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function actions()
|
|
{
|
|
return [
|
|
'error' => [
|
|
'class' => 'yii\web\ErrorAction',
|
|
],
|
|
];
|
|
}
|
|
|
|
public function actionIndex()
|
|
{
|
|
$user_id=Yii::$app->user->identity->getId();
|
|
$user_info = Yii::$app->authManager->getRolesByUser($user_id);
|
|
$menu = new Menu();
|
|
$menu = $menu->getLeftMenuList();
|
|
return $this->render('index',[
|
|
'menu' => $menu,
|
|
'user_info' => key($user_info)
|
|
]);
|
|
}
|
|
|
|
public function actionList()
|
|
{
|
|
return $this->render('list');
|
|
}
|
|
|
|
public function actionLogin()
|
|
{
|
|
if (!Yii::$app->user->isGuest) {
|
|
return $this->goHome();
|
|
}
|
|
|
|
$model = new LoginForm();
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
|
$model->loginLog(); //将登陆记录到日志表
|
|
return $this->goBack();
|
|
} else {
|
|
return $this->render('login', [
|
|
'model' => $model,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function actionLogout()
|
|
{
|
|
Yii::$app->user->logout();
|
|
|
|
return $this->goHome();
|
|
}
|
|
|
|
public function actionError($e){
|
|
echo $e;
|
|
}
|
|
|
|
}
|