Browse Source

fixed login

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
0a26975d51

+ 8
- 0
src/Auth/Business/LuticateUsersBusiness.php View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 namespace Luticate\Auth\Business;
4 4
 
5
+use Luticate\Auth\DBO\LuticateUsersLoginDbo;
5 6
 use Luticate\Utils\LuBusiness;
6 7
 use Luticate\Auth\DataAccess\LuticateUsersDataAccess;
7 8
 use Luticate\Auth\DBO\LuticateUsersDbo;
@@ -39,6 +40,11 @@ class LuticateUsersBusiness extends LuBusiness {
39 40
         return $randomString;
40 41
     }
41 42
 
43
+    public static function getToken($user)
44
+    {
45
+        return JwtHelper::encode(array(JwtHelper::USER_KEY => $user->getId()));
46
+    }
47
+
42 48
     public static function login($username, $password)
43 49
     {
44 50
         $user = LuticateUsersDataAccess::getByUsernameOrEmail($username);
@@ -46,6 +52,8 @@ class LuticateUsersBusiness extends LuBusiness {
46 52
             self::badPassword();
47 53
         if (!self::verifyPassword($password, $user->getPassword()))
48 54
             self::badPassword();
55
+        $user = LuticateUsersLoginDbo::fromUserDbo($user);
56
+        $user->setToken(self::getToken($user));
49 57
         return $user;
50 58
     }
51 59
 

+ 51
- 0
src/Auth/DBO/LuticateUsersLoginDbo.php View File

@@ -0,0 +1,51 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/15
6
+ * Time: 8:46 PM
7
+ */
8
+
9
+namespace Luticate\Auth\DBO;
10
+
11
+
12
+class LuticateUsersLoginDbo extends LuticateUsersDbo
13
+{
14
+    /**
15
+     * @param $user LuticateUsersDbo
16
+     * @return LuticateUsersLoginDbo|null
17
+     */
18
+    public static function fromUserDbo($user)
19
+    {
20
+        return $user->castAs('LuticateUsersLoginDbo');
21
+    }
22
+
23
+    /**
24
+     * @var string
25
+     */
26
+    protected $_token;
27
+    /**
28
+     * @return string
29
+     */
30
+    public function getToken()
31
+    {
32
+        return $this->_token;
33
+    }
34
+    /**
35
+     * @param string $token
36
+     */
37
+    public function setToken($token)
38
+    {
39
+        $this->_token = $token;
40
+    }
41
+
42
+    public function jsonSerialize()
43
+    {
44
+        $array = parent::jsonSerialize();
45
+        unset($array["Password"]);
46
+        unset($array["Salt"]);
47
+        $array["Token"] = $this->_token;
48
+        return $array;
49
+    }
50
+
51
+}

Loading…
Cancel
Save