Browse Source

begin auth filter

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
dcceb9825f
1 changed files with 9 additions and 16 deletions
  1. 9
    16
      src/Auth/Business/LuticateUsersBusiness.php

+ 9
- 16
src/Auth/Business/LuticateUsersBusiness.php View File

6
 use Luticate\Utils\LuBusiness;
6
 use Luticate\Utils\LuBusiness;
7
 use Luticate\Auth\DataAccess\LuticateUsersDataAccess;
7
 use Luticate\Auth\DataAccess\LuticateUsersDataAccess;
8
 use Luticate\Auth\DBO\LuticateUsersDbo;
8
 use Luticate\Auth\DBO\LuticateUsersDbo;
9
-use Luticate\Utils\LuRoute;
10
 
9
 
11
 class LuticateUsersBusiness extends LuBusiness {
10
 class LuticateUsersBusiness extends LuBusiness {
12
     /**
11
     /**
34
     public static function authFilter($permissions, $request)
33
     public static function authFilter($permissions, $request)
35
     {
34
     {
36
         $token = $request->header(self::TOKEN_HEADER);
35
         $token = $request->header(self::TOKEN_HEADER);
37
-        if ($token == null)
38
-        {
39
-            return false;
36
+        if ($token != null && $token != "") {
37
+            $data = JwtHelper::decode($token);
38
+            if ($data != null) {
39
+                $user_id = $data[JwtHelper::USER_KEY];
40
+                self::$_currentUser = LuticateUsersBusiness::getById($user_id);
41
+            }
40
         }
42
         }
41
-        $data = JwtHelper::decode($token);
42
-        if ($data == null)
43
-        {
43
+
44
+        if (self::$_currentUser == null && count($permissions) != 0) {
44
             return false;
45
             return false;
45
         }
46
         }
46
-        $user_id = $data[JwtHelper::USER_KEY];
47
 
47
 
48
         foreach ($permissions as $permission) {
48
         foreach ($permissions as $permission) {
49
-            if (!LuticatePermissionsBusiness::getUserPermission($user_id, $permission)) {
49
+            if (!LuticatePermissionsBusiness::getUserPermission(self::$_currentUser->getId(), $permission)) {
50
                 return false;
50
                 return false;
51
             }
51
             }
52
         }
52
         }
53
-
54
-        $user = LuticateUsersBusiness::getById($user_id);
55
-        if ($user == null)
56
-        {
57
-            return false;
58
-        }
59
-        self::$_currentUser = $user;
60
         return true;
53
         return true;
61
     }
54
     }
62
 }
55
 }

Loading…
Cancel
Save