What should I do if the backend system of thinkphp6 does not perform login redirection one after another?
与时赛跑
与时赛跑 2022-08-27 17:38:37
0
1
1152

class BaseAdmin extends Controller

{

public function __construct(){

// There is __construct magic method in Controller, we directly inherit and call it

parent::__construct();

// 1. First use the public method to see if you are logged in. Not logged in, go to the login page.

// You need to create a login page and method

$this->_admin = session('admin');

// Unlogged users are not allowed to access

if(!$this->_admin){

header('Location: /admins/Account/login');

exit;

}

$this->assign('admin',$this->_admin);

// Determine whether the user has permission

$this-> ;db = new Sysdb;

$group = $this->db->table('admin_groups')->where(array('gid'=>$this->_admin[ 'gid']))->item();

if(!$group){

$this->request_error('Sorry, you don't have permission');

}

$rights = json_decode($group['rights']);

// Current access menu

// 99, request()- >controller(); Get the current file

// 99, request()->action(); Get the current method

$controller = request()->controller() ;

$action = request()->action();

// 99, query the menu table (admin_menus) and find the menu with the same file name and method name. Note: Do not repeat the method name and file name of the menu

$res = $this->db->table('admin_menus')->where(array('controller'=>$controller ,'method'=>$action))->item();

if(!$res){

$this->request_error('Sorry, you visited Function does not exist');

}

if($res['status']==1){

$this->request_error('Sorry, the Function disabled');

}

if(!in_array($res['mid'],$rights)){

$this->request_error ('Sorry, you don't have permission');

}

}

与时赛跑
与时赛跑

reply all(1)
手机用户6999042

Question and Answer

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template