1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace app\bug\controller;
- use app\bug\model\UserRole;use think\App;
- class Base extends \app\BaseController{
- protected $noLogin=[];
- protected $uid=0;
- protected $uname='system';
- protected $roleid=0;
- protected $level=0;
- protected $token='';
- protected $model=null;
- public function __construct(App $app) {
- parent::__construct($app);
- $this->token = $this->request->param('token','','trim');
- if (!action_in_arr($this->noLogin)){
- if($this->token=='')throw new \Exception('token不能为空',101);
- $this->Auth();
- }
- }
- /**授权token鉴定
- * @return \think\response\Json|void
- */
- public function Auth(){
- $User = \app\common\User::instance();
- $User->init($this->token);
- if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
- $this->uid = $User->id;
- $this->uname = $User->nickname;
- $this->level = $User->level;
- $this->roleid = (new UserRole())->RoleIdByUid($this->uid);
- if($this->roleid==0) throw new \Exception('账户未设置角色!',101);
- }
-
- }
|