Browse Source

用户auth追加权限

lizhen_gitee 1 year ago
parent
commit
c5738df4b9
2 changed files with 31 additions and 0 deletions
  1. 18 0
      application/common/library/Auth.php
  2. 13 0
      application/common/model/UserPower.php

+ 18 - 0
application/common/library/Auth.php

@@ -3,6 +3,7 @@
 namespace app\common\library;
 
 use app\common\model\User;
+use app\common\model\UserPower;
 use app\common\model\UserRule;
 use fast\Random;
 use think\Config;
@@ -99,6 +100,16 @@ class Auth
                 $this->setError('Account is locked');
                 return false;
             }
+
+            //追加权限
+            $userpower = UserPower::getByUserId($user_id);
+            if(!$userpower){
+                $this->setError('Account not exist');
+                return false;
+            }
+            $user->power = $userpower;
+
+
             $this->_user = $user;
             $this->_logined = true;
             $this->_token = $token;
@@ -319,6 +330,12 @@ class Auth
     {
         $user = User::getById($user_id);
         if ($user) {
+
+            $userpower = UserPower::getByUserId($user_id);
+            if(!$userpower){
+                return false;
+            }
+
             Db::startTrans();
             try {
                 // 微信内置浏览器时不请空用户的token,APP才清除所有token
@@ -335,6 +352,7 @@ class Auth
 
                 $user->save();
 
+                $user->power = $userpower;// 追加权限
                 $this->_user = $user;
 
                 $this->_token = Random::uuid();

+ 13 - 0
application/common/model/UserPower.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+class UserPower extends Model
+{
+
+    // 表名
+    protected $name = 'user_power';
+
+}