<?php<web88@qq.com>
namespace app\user\controller;
use app\common\controller\Base;
use lib\ReturnCode;
use think\facade\Hook;
use app\admin\library\Auth;
class BaseUserController extends Base
{
public function initialize() {
parent::initialize();
$modulename = $this->request->module();
$controllername = strtolower($this->request->controller());
$actionname = strtolower($this->request->action());
$path = $modulename.'/'.str_replace('.', '/', $controllername) . '/' . $actionname;
$this->auth = Auth::instance($this->request->accessToken);
$this->uid=$this->auth->uid;
$this->tenant_id=$this->auth->tenant_id;
if (!$this->auth->match($this->noNeedLogin)) {
if (!$this->auth->isLogin()) {
Hook::listen('admin_nologin', $this);
$this->reError(ReturnCode::LOGIN_OUT);
}
if (!$this->auth->match($this->noNeedRight)) {
if (!$this->auth->check($path)) {
Hook::listen('admin_nopermission', $this);
$this->reError(ReturnCode::NOT_AUTH);
}
}
}
if ($this->model){
$this->model->setConfig(['tenant_id'=>$this->tenant_id,'uid'=>$this->uid]);
}
if ($this->auth->match($this->validateAction)){
$this->validateAuto();
}
Hook::exec('app\\common\\behavior\\SetConfig','');
}
}