search

Home  >  Q&A  >  body text

What should I do if the backend system of thinkphp6 does not perform login redirection one after another?

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');

}

}

与时赛跑与时赛跑825 days ago1155

reply all(1)I'll reply

  • 手机用户6999042

    手机用户69990422022-08-29 09:24:33

    Question and Answer

    reply
    0
  • Cancelreply