Browse Source

added setting for user session duration

tags/0.1.2
Robin Thoni 8 years ago
parent
commit
4b0bd6b0e0

+ 2
- 2
src/Auth/Business/JwtHelper.php View File

@@ -31,10 +31,10 @@ class JwtHelper
31 31
         return $data;
32 32
     }
33 33
 
34
-    public static function encode($data)
34
+    public static function encode($data, $session_time)
35 35
     {
36 36
         $date = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
37
-        $date->modify("+30 day");
37
+        $date->modify("+${session_time} day");
38 38
         $data[self::EXPIRATION_KEY] = $date->getTimestamp();
39 39
 
40 40
         return base64_encode(mcrypt_encrypt(MCRYPT_TRIPLEDES, env("MCRYPT_KEY"), \JWT::encode($data, env("JWT_KEY")), "ecb"));

+ 16
- 4
src/Auth/Business/LuticateSettingsBusiness.php View File

@@ -99,6 +99,12 @@ class LuticateSettingsBusiness extends LuBusiness {
99 99
         return $setting;
100 100
     }
101 101
 
102
+    public static function getEffectiveSettingValue($user_id, $setting_name)
103
+    {
104
+        $setting = self::getEffectiveSetting($user_id, $setting_name);
105
+        return $setting["Value"];
106
+    }
107
+
102 108
     public static function getAllEffectiveSetting($user_id)
103 109
     {
104 110
         return LuticateSettingsDataAccess::getAllEffectiveSetting($user_id)->map(function($value)
@@ -111,12 +117,18 @@ class LuticateSettingsBusiness extends LuBusiness {
111 117
 
112 118
     public static function get($setting_name)
113 119
     {
114
-        $perm = LuticateSettingsDataAccess::getByName($setting_name);
115
-        if (is_null($perm)) {
120
+        $setting = LuticateSettingsDataAccess::getByName($setting_name);
121
+        if (is_null($setting)) {
116 122
             self::notFound("Permission not found");
117 123
         }
118
-        $perm->setValue(json_decode($perm->getValue()));
119
-        return $perm;
124
+        $setting->setValue(json_decode($setting->getValue()));
125
+        return $setting;
126
+    }
127
+
128
+    public static function getValue($setting_name)
129
+    {
130
+        $setting = self::get($setting_name);
131
+        return $setting->getValue();
120 132
     }
121 133
 
122 134
     /**

+ 2
- 1
src/Auth/Business/LuticateUsersBusiness.php View File

@@ -55,11 +55,12 @@ class LuticateUsersBusiness extends LuBusiness {
55 55
      */
56 56
     public static function getToken($user, $data = null)
57 57
     {
58
+        $session_time = LuticateSettingsBusiness::getValue("LU_SESSION_DAYS");
58 59
         return JwtHelper::encode(array(
59 60
             self::KEY_USER_ID => $user->getId(),
60 61
             self::KEY_SALT => $user->getSalt(),
61 62
             self::KEY_DATA => $data
62
-            ));
63
+            ), $session_time);
63 64
     }
64 65
 
65 66
     /**

Loading…
Cancel
Save