|
@@ -2,6 +2,7 @@
|
2
|
2
|
|
3
|
3
|
namespace Luticate\Auth\Business;
|
4
|
4
|
|
|
5
|
+use Illuminate\Support\Facades\DB;
|
5
|
6
|
use Luticate\Auth\DBO\LuticatePermissions;
|
6
|
7
|
use Luticate\Auth\DBO\LuticateUsersLoginDbo;
|
7
|
8
|
use Luticate\Utils\LuBusiness;
|
|
@@ -12,6 +13,7 @@ class LuticateUsersBusiness extends LuBusiness {
|
12
|
13
|
|
13
|
14
|
const KEY_USER_ID = "user_id";
|
14
|
15
|
const KEY_SALT = "salt";
|
|
16
|
+ const KEY_DATA = "data";
|
15
|
17
|
|
16
|
18
|
protected static function getDataAccess()
|
17
|
19
|
{
|
|
@@ -33,16 +35,8 @@ class LuticateUsersBusiness extends LuBusiness {
|
33
|
35
|
return password_verify($password, $hash);
|
34
|
36
|
}
|
35
|
37
|
|
36
|
|
- /**
|
37
|
|
- * @param $user LuticateUsersDbo
|
38
|
|
- * @param int $length
|
39
|
|
- * @return string
|
40
|
|
- */
|
41
|
|
- public static function getSalt($user, $length = 10)
|
|
38
|
+ public static function getSalt($length = 10)
|
42
|
39
|
{
|
43
|
|
- if ($user->getId() == 0) {
|
44
|
|
- return "";
|
45
|
|
- }
|
46
|
40
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
47
|
41
|
$charactersLength = strlen($characters);
|
48
|
42
|
$randomString = '';
|
|
@@ -54,13 +48,15 @@ class LuticateUsersBusiness extends LuBusiness {
|
54
|
48
|
|
55
|
49
|
/**
|
56
|
50
|
* @param $user LuticateUsersDbo
|
|
51
|
+ * @param $data mixed
|
57
|
52
|
* @return string
|
58
|
53
|
*/
|
59
|
|
- public static function getToken($user)
|
|
54
|
+ public static function getToken($user, $data = null)
|
60
|
55
|
{
|
61
|
56
|
return JwtHelper::encode(array(
|
62
|
57
|
self::KEY_USER_ID => $user->getId(),
|
63
|
|
- self::KEY_SALT => $user->getSalt()
|
|
58
|
+ self::KEY_SALT => $user->getSalt(),
|
|
59
|
+ self::KEY_DATA => $data
|
64
|
60
|
));
|
65
|
61
|
}
|
66
|
62
|
|
|
@@ -83,8 +79,10 @@ class LuticateUsersBusiness extends LuBusiness {
|
83
|
79
|
*/
|
84
|
80
|
public static function logout($user)
|
85
|
81
|
{
|
86
|
|
- $user->setSalt(self::getSalt($user));
|
87
|
|
- LuticateUsersDataAccess::editById($user->getId(), $user);
|
|
82
|
+ if ($user->getId() != 0) {
|
|
83
|
+ $user->setSalt(self::getSalt());
|
|
84
|
+ LuticateUsersDataAccess::editById($user->getId(), $user);
|
|
85
|
+ }
|
88
|
86
|
return true;
|
89
|
87
|
}
|
90
|
88
|
|
|
@@ -108,6 +106,15 @@ class LuticateUsersBusiness extends LuBusiness {
|
108
|
106
|
$user->setUsername($username);
|
109
|
107
|
$user->setSalt(self::getSalt());
|
110
|
108
|
|
111
|
|
- return LuticateUsersDataAccess::addId($user);
|
|
109
|
+ DB::beginTransaction();
|
|
110
|
+
|
|
111
|
+ $user_id = LuticateUsersDataAccess::addId($user);
|
|
112
|
+
|
|
113
|
+ if (!is_null(LuticateGroupsBusiness::getById(0))) {
|
|
114
|
+ LuticateGroupsBusiness::addUserToGroup($user_id, 0);
|
|
115
|
+ }
|
|
116
|
+ DB::commit();
|
|
117
|
+
|
|
118
|
+ return $user_id;
|
112
|
119
|
}
|
113
|
120
|
}
|