@@ -2,22 +2,22 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * List of error messages used in core module. |
|
7 | - */ |
|
8 | - 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | - 'tokenExpired' => 'انتهت صلاحية الدخول', |
|
10 | - 'noPermissions' => 'لا توجد صلاحية', |
|
11 | - 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | - 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
13 | - 'dbQueryError' => 'خطا في البيانات', |
|
14 | - 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
15 | - 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
16 | - 'userIsBlocked' => 'لقد تم حظرك', |
|
17 | - 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
18 | - 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
19 | - 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
20 | - 'notFound' => 'ال :replace المطلوب غير موجود', |
|
21 | - 'generalError' => 'حدث خطا ما', |
|
5 | + /** |
|
6 | + * List of error messages used in core module. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | + 'tokenExpired' => 'انتهت صلاحية الدخول', |
|
10 | + 'noPermissions' => 'لا توجد صلاحية', |
|
11 | + 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | + 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
13 | + 'dbQueryError' => 'خطا في البيانات', |
|
14 | + 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
15 | + 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
16 | + 'userIsBlocked' => 'لقد تم حظرك', |
|
17 | + 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
18 | + 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
19 | + 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
20 | + 'notFound' => 'ال :replace المطلوب غير موجود', |
|
21 | + 'generalError' => 'حدث خطا ما', |
|
22 | 22 | |
23 | 23 | ]; |
24 | 24 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Authentication Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'failed' => 'These credentials do not match our records.', |
|
17 | - 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', |
|
16 | + 'failed' => 'These credentials do not match our records.', |
|
17 | + 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', |
|
18 | 18 | |
19 | 19 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Validation Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,74 +13,74 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'accepted' => 'The :attribute must be accepted.', |
|
17 | - 'active_url' => 'The :attribute is not a valid URL.', |
|
18 | - 'after' => 'The :attribute must be a date after :date.', |
|
19 | - 'alpha' => 'The :attribute may only contain letters.', |
|
20 | - 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', |
|
21 | - 'alpha_num' => 'The :attribute may only contain letters and numbers.', |
|
22 | - 'array' => 'The :attribute must be an array.', |
|
23 | - 'before' => 'The :attribute must be a date before :date.', |
|
24 | - 'between' => [ |
|
25 | - 'numeric' => 'The :attribute must be between :min and :max.', |
|
26 | - 'file' => 'The :attribute must be between :min and :max kilobytes.', |
|
27 | - 'string' => 'The :attribute must be between :min and :max characters.', |
|
28 | - 'array' => 'The :attribute must have between :min and :max items.', |
|
29 | - ], |
|
30 | - 'boolean' => 'The :attribute field must be true or false.', |
|
31 | - 'confirmed' => 'The :attribute confirmation does not match.', |
|
32 | - 'date' => 'The :attribute is not a valid date.', |
|
33 | - 'date_format' => 'The :attribute does not match the format :format.', |
|
34 | - 'different' => 'The :attribute and :other must be different.', |
|
35 | - 'digits' => 'The :attribute must be :digits digits.', |
|
36 | - 'digits_between' => 'The :attribute must be between :min and :max digits.', |
|
37 | - 'distinct' => 'The :attribute field has a duplicate value.', |
|
38 | - 'email' => 'The :attribute must be a valid email address.', |
|
39 | - 'exists' => 'The selected :attribute is invalid.', |
|
40 | - 'filled' => 'The :attribute field is required.', |
|
41 | - 'image' => 'The :attribute must be an image.', |
|
42 | - 'in' => 'The selected :attribute is invalid.', |
|
43 | - 'in_array' => 'The :attribute field does not exist in :other.', |
|
44 | - 'integer' => 'The :attribute must be an integer.', |
|
45 | - 'ip' => 'The :attribute must be a valid IP address.', |
|
46 | - 'json' => 'The :attribute must be a valid JSON string.', |
|
47 | - 'max' => [ |
|
48 | - 'numeric' => 'The :attribute may not be greater than :max.', |
|
49 | - 'file' => 'The :attribute may not be greater than :max kilobytes.', |
|
50 | - 'string' => 'The :attribute may not be greater than :max characters.', |
|
51 | - 'array' => 'The :attribute may not have more than :max items.', |
|
52 | - ], |
|
53 | - 'mimes' => 'The :attribute must be a file of type: :values.', |
|
54 | - 'min' => [ |
|
55 | - 'numeric' => 'The :attribute must be at least :min.', |
|
56 | - 'file' => 'The :attribute must be at least :min kilobytes.', |
|
57 | - 'string' => 'The :attribute must be at least :min characters.', |
|
58 | - 'array' => 'The :attribute must have at least :min items.', |
|
59 | - ], |
|
60 | - 'not_in' => 'The selected :attribute is invalid.', |
|
61 | - 'numeric' => 'The :attribute must be a number.', |
|
62 | - 'present' => 'The :attribute field must be present.', |
|
63 | - 'regex' => 'The :attribute format is invalid.', |
|
64 | - 'required' => 'The :attribute field is required.', |
|
65 | - 'required_if' => 'The :attribute field is required when :other is :value.', |
|
66 | - 'required_unless' => 'The :attribute field is required unless :other is in :values.', |
|
67 | - 'required_with' => 'The :attribute field is required when :values is present.', |
|
68 | - 'required_with_all' => 'The :attribute field is required when :values is present.', |
|
69 | - 'required_without' => 'The :attribute field is required when :values is not present.', |
|
70 | - 'required_without_all' => 'The :attribute field is required when none of :values are present.', |
|
71 | - 'same' => 'The :attribute and :other must match.', |
|
72 | - 'size' => [ |
|
73 | - 'numeric' => 'The :attribute must be :size.', |
|
74 | - 'file' => 'The :attribute must be :size kilobytes.', |
|
75 | - 'string' => 'The :attribute must be :size characters.', |
|
76 | - 'array' => 'The :attribute must contain :size items.', |
|
77 | - ], |
|
78 | - 'string' => 'The :attribute must be a string.', |
|
79 | - 'timezone' => 'The :attribute must be a valid zone.', |
|
80 | - 'unique' => 'The :attribute has already been taken.', |
|
81 | - 'url' => 'The :attribute format is invalid.', |
|
16 | + 'accepted' => 'The :attribute must be accepted.', |
|
17 | + 'active_url' => 'The :attribute is not a valid URL.', |
|
18 | + 'after' => 'The :attribute must be a date after :date.', |
|
19 | + 'alpha' => 'The :attribute may only contain letters.', |
|
20 | + 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', |
|
21 | + 'alpha_num' => 'The :attribute may only contain letters and numbers.', |
|
22 | + 'array' => 'The :attribute must be an array.', |
|
23 | + 'before' => 'The :attribute must be a date before :date.', |
|
24 | + 'between' => [ |
|
25 | + 'numeric' => 'The :attribute must be between :min and :max.', |
|
26 | + 'file' => 'The :attribute must be between :min and :max kilobytes.', |
|
27 | + 'string' => 'The :attribute must be between :min and :max characters.', |
|
28 | + 'array' => 'The :attribute must have between :min and :max items.', |
|
29 | + ], |
|
30 | + 'boolean' => 'The :attribute field must be true or false.', |
|
31 | + 'confirmed' => 'The :attribute confirmation does not match.', |
|
32 | + 'date' => 'The :attribute is not a valid date.', |
|
33 | + 'date_format' => 'The :attribute does not match the format :format.', |
|
34 | + 'different' => 'The :attribute and :other must be different.', |
|
35 | + 'digits' => 'The :attribute must be :digits digits.', |
|
36 | + 'digits_between' => 'The :attribute must be between :min and :max digits.', |
|
37 | + 'distinct' => 'The :attribute field has a duplicate value.', |
|
38 | + 'email' => 'The :attribute must be a valid email address.', |
|
39 | + 'exists' => 'The selected :attribute is invalid.', |
|
40 | + 'filled' => 'The :attribute field is required.', |
|
41 | + 'image' => 'The :attribute must be an image.', |
|
42 | + 'in' => 'The selected :attribute is invalid.', |
|
43 | + 'in_array' => 'The :attribute field does not exist in :other.', |
|
44 | + 'integer' => 'The :attribute must be an integer.', |
|
45 | + 'ip' => 'The :attribute must be a valid IP address.', |
|
46 | + 'json' => 'The :attribute must be a valid JSON string.', |
|
47 | + 'max' => [ |
|
48 | + 'numeric' => 'The :attribute may not be greater than :max.', |
|
49 | + 'file' => 'The :attribute may not be greater than :max kilobytes.', |
|
50 | + 'string' => 'The :attribute may not be greater than :max characters.', |
|
51 | + 'array' => 'The :attribute may not have more than :max items.', |
|
52 | + ], |
|
53 | + 'mimes' => 'The :attribute must be a file of type: :values.', |
|
54 | + 'min' => [ |
|
55 | + 'numeric' => 'The :attribute must be at least :min.', |
|
56 | + 'file' => 'The :attribute must be at least :min kilobytes.', |
|
57 | + 'string' => 'The :attribute must be at least :min characters.', |
|
58 | + 'array' => 'The :attribute must have at least :min items.', |
|
59 | + ], |
|
60 | + 'not_in' => 'The selected :attribute is invalid.', |
|
61 | + 'numeric' => 'The :attribute must be a number.', |
|
62 | + 'present' => 'The :attribute field must be present.', |
|
63 | + 'regex' => 'The :attribute format is invalid.', |
|
64 | + 'required' => 'The :attribute field is required.', |
|
65 | + 'required_if' => 'The :attribute field is required when :other is :value.', |
|
66 | + 'required_unless' => 'The :attribute field is required unless :other is in :values.', |
|
67 | + 'required_with' => 'The :attribute field is required when :values is present.', |
|
68 | + 'required_with_all' => 'The :attribute field is required when :values is present.', |
|
69 | + 'required_without' => 'The :attribute field is required when :values is not present.', |
|
70 | + 'required_without_all' => 'The :attribute field is required when none of :values are present.', |
|
71 | + 'same' => 'The :attribute and :other must match.', |
|
72 | + 'size' => [ |
|
73 | + 'numeric' => 'The :attribute must be :size.', |
|
74 | + 'file' => 'The :attribute must be :size kilobytes.', |
|
75 | + 'string' => 'The :attribute must be :size characters.', |
|
76 | + 'array' => 'The :attribute must contain :size items.', |
|
77 | + ], |
|
78 | + 'string' => 'The :attribute must be a string.', |
|
79 | + 'timezone' => 'The :attribute must be a valid zone.', |
|
80 | + 'unique' => 'The :attribute has already been taken.', |
|
81 | + 'url' => 'The :attribute format is invalid.', |
|
82 | 82 | |
83 | - /* |
|
83 | + /* |
|
84 | 84 | |-------------------------------------------------------------------------- |
85 | 85 | | Custom Validation Language Lines |
86 | 86 | |-------------------------------------------------------------------------- |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | | |
92 | 92 | */ |
93 | 93 | |
94 | - 'custom' => [ |
|
95 | - 'attribute-name' => [ |
|
96 | - 'rule-name' => 'custom-message', |
|
97 | - ], |
|
98 | - ], |
|
94 | + 'custom' => [ |
|
95 | + 'attribute-name' => [ |
|
96 | + 'rule-name' => 'custom-message', |
|
97 | + ], |
|
98 | + ], |
|
99 | 99 | |
100 | - /* |
|
100 | + /* |
|
101 | 101 | |-------------------------------------------------------------------------- |
102 | 102 | | Custom Validation Attributes |
103 | 103 | |-------------------------------------------------------------------------- |
@@ -108,6 +108,6 @@ discard block |
||
108 | 108 | | |
109 | 109 | */ |
110 | 110 | |
111 | - 'attributes' => [], |
|
111 | + 'attributes' => [], |
|
112 | 112 | |
113 | 113 | ]; |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * Here goes your notification messages. |
|
7 | - */ |
|
5 | + /** |
|
6 | + * Here goes your notification messages. |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | ]; |
10 | 10 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Password Reset Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'password' => 'Passwords must be at least six characters and match the confirmation.', |
|
17 | - 'reset' => 'Your password has been reset!', |
|
18 | - 'sent' => 'We have e-mailed your password reset link!', |
|
19 | - 'token' => 'This password reset token is invalid.', |
|
20 | - 'user' => "We can't find a user with that e-mail address.", |
|
16 | + 'password' => 'Passwords must be at least six characters and match the confirmation.', |
|
17 | + 'reset' => 'Your password has been reset!', |
|
18 | + 'sent' => 'We have e-mailed your password reset link!', |
|
19 | + 'token' => 'This password reset token is invalid.', |
|
20 | + 'user' => "We can't find a user with that e-mail address.", |
|
21 | 21 | |
22 | 22 | ]; |
@@ -2,22 +2,22 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * List of error messages used in core module. |
|
7 | - */ |
|
8 | - 'unAuthorized' => 'Please login before any action', |
|
9 | - 'tokenExpired' => 'Login token expired', |
|
10 | - 'noPermissions' => 'No permissions', |
|
11 | - 'loginFailed' => 'Wrong mail or password', |
|
12 | - 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
13 | - 'dbQueryError' => 'Please check the given inputes', |
|
14 | - 'cannotCreateSetting' => 'Can\'t create setting', |
|
15 | - 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
16 | - 'userIsBlocked' => 'You have been blocked', |
|
17 | - 'invalidResetToken' => 'Reset password token is invalid', |
|
18 | - 'invalidResetPassword' => 'Reset password is invalid', |
|
19 | - 'invalidOldPassword' => 'Old password is invalid', |
|
20 | - 'notFound' => 'The requested :replace not found', |
|
21 | - 'generalError' => 'Something went wrong', |
|
5 | + /** |
|
6 | + * List of error messages used in core module. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'Please login before any action', |
|
9 | + 'tokenExpired' => 'Login token expired', |
|
10 | + 'noPermissions' => 'No permissions', |
|
11 | + 'loginFailed' => 'Wrong mail or password', |
|
12 | + 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
13 | + 'dbQueryError' => 'Please check the given inputes', |
|
14 | + 'cannotCreateSetting' => 'Can\'t create setting', |
|
15 | + 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
16 | + 'userIsBlocked' => 'You have been blocked', |
|
17 | + 'invalidResetToken' => 'Reset password token is invalid', |
|
18 | + 'invalidResetPassword' => 'Reset password is invalid', |
|
19 | + 'invalidOldPassword' => 'Old password is invalid', |
|
20 | + 'notFound' => 'The requested :replace not found', |
|
21 | + 'generalError' => 'Something went wrong', |
|
22 | 22 | |
23 | 23 | ]; |
24 | 24 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Pagination Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'previous' => '« Previous', |
|
17 | - 'next' => 'Next »', |
|
16 | + 'previous' => '« Previous', |
|
17 | + 'next' => 'Next »', |
|
18 | 18 | |
19 | 19 | ]; |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * Here goes your notification messages. |
|
7 | - */ |
|
5 | + /** |
|
6 | + * Here goes your notification messages. |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | ]; |
10 | 10 | \ No newline at end of file |
@@ -4,316 +4,316 @@ |
||
4 | 4 | |
5 | 5 | class UserRepository extends AbstractRepository |
6 | 6 | { |
7 | - /** |
|
8 | - * Return the model full namespace. |
|
9 | - * |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - protected function getModel() |
|
13 | - { |
|
14 | - return 'App\Modules\V1\Acl\AclUser'; |
|
15 | - } |
|
16 | - |
|
17 | - /** |
|
18 | - * Return the logged in user account. |
|
19 | - * |
|
20 | - * @param array $relations |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function account($relations = []) |
|
24 | - { |
|
25 | - $permissions = []; |
|
26 | - $user = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations); |
|
27 | - foreach ($user->groups()->get() as $group) |
|
28 | - { |
|
29 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
30 | - $permissions[$permission->model][$permission->id] = $permission->name; |
|
31 | - }); |
|
32 | - } |
|
33 | - $user->permissions = $permissions; |
|
34 | - |
|
35 | - return $user; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Check if the logged in user or the given user |
|
40 | - * has the given permissions on the given model. |
|
41 | - * |
|
42 | - * @param string $nameOfPermission |
|
43 | - * @param string $model |
|
44 | - * @param boolean $user |
|
45 | - * @return boolean |
|
46 | - */ |
|
47 | - public function can($nameOfPermission, $model, $user = false ) |
|
48 | - { |
|
49 | - $user = $user ?: \JWTAuth::parseToken()->authenticate(); |
|
50 | - $permissions = []; |
|
51 | - |
|
52 | - if ( ! $user = $this->find($user->id, ['groups.permissions'])) |
|
53 | - { |
|
54 | - \ErrorHandler::tokenExpired(); |
|
55 | - } |
|
56 | - |
|
57 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
58 | - $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
59 | - }); |
|
7 | + /** |
|
8 | + * Return the model full namespace. |
|
9 | + * |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + protected function getModel() |
|
13 | + { |
|
14 | + return 'App\Modules\V1\Acl\AclUser'; |
|
15 | + } |
|
16 | + |
|
17 | + /** |
|
18 | + * Return the logged in user account. |
|
19 | + * |
|
20 | + * @param array $relations |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function account($relations = []) |
|
24 | + { |
|
25 | + $permissions = []; |
|
26 | + $user = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations); |
|
27 | + foreach ($user->groups()->get() as $group) |
|
28 | + { |
|
29 | + $group->permissions->each(function ($permission) use (&$permissions){ |
|
30 | + $permissions[$permission->model][$permission->id] = $permission->name; |
|
31 | + }); |
|
32 | + } |
|
33 | + $user->permissions = $permissions; |
|
34 | + |
|
35 | + return $user; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Check if the logged in user or the given user |
|
40 | + * has the given permissions on the given model. |
|
41 | + * |
|
42 | + * @param string $nameOfPermission |
|
43 | + * @param string $model |
|
44 | + * @param boolean $user |
|
45 | + * @return boolean |
|
46 | + */ |
|
47 | + public function can($nameOfPermission, $model, $user = false ) |
|
48 | + { |
|
49 | + $user = $user ?: \JWTAuth::parseToken()->authenticate(); |
|
50 | + $permissions = []; |
|
51 | + |
|
52 | + if ( ! $user = $this->find($user->id, ['groups.permissions'])) |
|
53 | + { |
|
54 | + \ErrorHandler::tokenExpired(); |
|
55 | + } |
|
56 | + |
|
57 | + $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
58 | + $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
59 | + }); |
|
60 | 60 | |
61 | - return in_array($nameOfPermission, $permissions); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Check if the logged in user has the given group. |
|
66 | - * |
|
67 | - * @param string $groupName |
|
68 | - * @return boolean |
|
69 | - */ |
|
70 | - public function hasGroup($groupName) |
|
71 | - { |
|
72 | - $groups = $this->find(\JWTAuth::parseToken()->authenticate()->id)->groups; |
|
73 | - return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Assign the given group ids to the given user. |
|
78 | - * |
|
79 | - * @param integer $user_id |
|
80 | - * @param array $group_ids |
|
81 | - * @return object |
|
82 | - */ |
|
83 | - public function assignGroups($user_id, $group_ids) |
|
84 | - { |
|
85 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
86 | - $user = $this->find($user_id); |
|
87 | - $user->groups()->detach(); |
|
88 | - $user->groups()->attach($group_ids); |
|
89 | - }); |
|
90 | - |
|
91 | - return $this->find($user_id); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Handle a login request to the application. |
|
96 | - * |
|
97 | - * @param array $credentials |
|
98 | - * @param boolean $adminLogin |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function login($credentials, $adminLogin = false) |
|
102 | - { |
|
103 | - if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
104 | - { |
|
105 | - \ErrorHandler::loginFailed(); |
|
106 | - } |
|
107 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
108 | - { |
|
109 | - \ErrorHandler::loginFailed(); |
|
110 | - } |
|
111 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
112 | - { |
|
113 | - \ErrorHandler::loginFailed(); |
|
114 | - } |
|
115 | - else if ($user->blocked) |
|
116 | - { |
|
117 | - \ErrorHandler::userIsBlocked(); |
|
118 | - } |
|
119 | - else if ($token = \JWTAuth::attempt($credentials)) |
|
120 | - { |
|
121 | - return ['token' => $token]; |
|
122 | - } |
|
123 | - else |
|
124 | - { |
|
125 | - \ErrorHandler::loginFailed(); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Handle a social login request of the none admin to the application. |
|
131 | - * |
|
132 | - * @param array $credentials |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function loginSocial($credentials) |
|
136 | - { |
|
137 | - $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
138 | - $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
139 | - |
|
140 | - if ( ! $user->email) |
|
141 | - { |
|
142 | - \ErrorHandler::noSocialEmail(); |
|
143 | - } |
|
144 | - |
|
145 | - if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
146 | - { |
|
147 | - $data = ['email' => $user->email, 'password' => '']; |
|
148 | - return $this->register($data); |
|
149 | - } |
|
150 | - else |
|
151 | - { |
|
152 | - if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
153 | - { |
|
154 | - \ErrorHandler::userAlreadyRegistered(); |
|
155 | - } |
|
156 | - return $this->login(['email' => $registeredUser->email, 'password' => ''], false); |
|
157 | - } |
|
158 | - } |
|
61 | + return in_array($nameOfPermission, $permissions); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Check if the logged in user has the given group. |
|
66 | + * |
|
67 | + * @param string $groupName |
|
68 | + * @return boolean |
|
69 | + */ |
|
70 | + public function hasGroup($groupName) |
|
71 | + { |
|
72 | + $groups = $this->find(\JWTAuth::parseToken()->authenticate()->id)->groups; |
|
73 | + return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Assign the given group ids to the given user. |
|
78 | + * |
|
79 | + * @param integer $user_id |
|
80 | + * @param array $group_ids |
|
81 | + * @return object |
|
82 | + */ |
|
83 | + public function assignGroups($user_id, $group_ids) |
|
84 | + { |
|
85 | + \DB::transaction(function () use ($user_id, $group_ids) { |
|
86 | + $user = $this->find($user_id); |
|
87 | + $user->groups()->detach(); |
|
88 | + $user->groups()->attach($group_ids); |
|
89 | + }); |
|
90 | + |
|
91 | + return $this->find($user_id); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Handle a login request to the application. |
|
96 | + * |
|
97 | + * @param array $credentials |
|
98 | + * @param boolean $adminLogin |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function login($credentials, $adminLogin = false) |
|
102 | + { |
|
103 | + if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
104 | + { |
|
105 | + \ErrorHandler::loginFailed(); |
|
106 | + } |
|
107 | + else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
108 | + { |
|
109 | + \ErrorHandler::loginFailed(); |
|
110 | + } |
|
111 | + else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
112 | + { |
|
113 | + \ErrorHandler::loginFailed(); |
|
114 | + } |
|
115 | + else if ($user->blocked) |
|
116 | + { |
|
117 | + \ErrorHandler::userIsBlocked(); |
|
118 | + } |
|
119 | + else if ($token = \JWTAuth::attempt($credentials)) |
|
120 | + { |
|
121 | + return ['token' => $token]; |
|
122 | + } |
|
123 | + else |
|
124 | + { |
|
125 | + \ErrorHandler::loginFailed(); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Handle a social login request of the none admin to the application. |
|
131 | + * |
|
132 | + * @param array $credentials |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function loginSocial($credentials) |
|
136 | + { |
|
137 | + $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
138 | + $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
139 | + |
|
140 | + if ( ! $user->email) |
|
141 | + { |
|
142 | + \ErrorHandler::noSocialEmail(); |
|
143 | + } |
|
144 | + |
|
145 | + if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
146 | + { |
|
147 | + $data = ['email' => $user->email, 'password' => '']; |
|
148 | + return $this->register($data); |
|
149 | + } |
|
150 | + else |
|
151 | + { |
|
152 | + if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
153 | + { |
|
154 | + \ErrorHandler::userAlreadyRegistered(); |
|
155 | + } |
|
156 | + return $this->login(['email' => $registeredUser->email, 'password' => ''], false); |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * Handle a registration request. |
|
162 | - * |
|
163 | - * @param array $credentials |
|
164 | - * @return array |
|
165 | - */ |
|
166 | - public function register($credentials) |
|
167 | - { |
|
168 | - return ['token' => \JWTAuth::fromUser($this->model->create($credentials))]; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Logout the user. |
|
173 | - * |
|
174 | - * @return boolean |
|
175 | - */ |
|
176 | - public function logout() |
|
177 | - { |
|
178 | - return \JWTAuth::invalidate(\JWTAuth::getToken()); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Block the user. |
|
183 | - * |
|
184 | - * @param integer $user_id |
|
185 | - * @return object |
|
186 | - */ |
|
187 | - public function block($user_id) |
|
188 | - { |
|
189 | - if ( ! $user = $this->find($user_id)) |
|
190 | - { |
|
191 | - \ErrorHandler::notFound('user'); |
|
192 | - } |
|
193 | - if ( ! $this->hasGroup('Admin')) |
|
194 | - { |
|
195 | - \ErrorHandler::noPermissions(); |
|
196 | - } |
|
197 | - else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
198 | - { |
|
199 | - \ErrorHandler::noPermissions(); |
|
200 | - } |
|
201 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
202 | - { |
|
203 | - \ErrorHandler::noPermissions(); |
|
204 | - } |
|
205 | - |
|
206 | - $user->blocked = 1; |
|
207 | - $user->save(); |
|
160 | + /** |
|
161 | + * Handle a registration request. |
|
162 | + * |
|
163 | + * @param array $credentials |
|
164 | + * @return array |
|
165 | + */ |
|
166 | + public function register($credentials) |
|
167 | + { |
|
168 | + return ['token' => \JWTAuth::fromUser($this->model->create($credentials))]; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Logout the user. |
|
173 | + * |
|
174 | + * @return boolean |
|
175 | + */ |
|
176 | + public function logout() |
|
177 | + { |
|
178 | + return \JWTAuth::invalidate(\JWTAuth::getToken()); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Block the user. |
|
183 | + * |
|
184 | + * @param integer $user_id |
|
185 | + * @return object |
|
186 | + */ |
|
187 | + public function block($user_id) |
|
188 | + { |
|
189 | + if ( ! $user = $this->find($user_id)) |
|
190 | + { |
|
191 | + \ErrorHandler::notFound('user'); |
|
192 | + } |
|
193 | + if ( ! $this->hasGroup('Admin')) |
|
194 | + { |
|
195 | + \ErrorHandler::noPermissions(); |
|
196 | + } |
|
197 | + else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
198 | + { |
|
199 | + \ErrorHandler::noPermissions(); |
|
200 | + } |
|
201 | + else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
202 | + { |
|
203 | + \ErrorHandler::noPermissions(); |
|
204 | + } |
|
205 | + |
|
206 | + $user->blocked = 1; |
|
207 | + $user->save(); |
|
208 | 208 | |
209 | - return $user; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Unblock the user. |
|
214 | - * |
|
215 | - * @param integer $user_id |
|
216 | - * @return object |
|
217 | - */ |
|
218 | - public function unblock($user_id) |
|
219 | - { |
|
220 | - if ( ! $this->hasGroup('Admin')) |
|
221 | - { |
|
222 | - \ErrorHandler::noPermissions(); |
|
223 | - } |
|
224 | - |
|
225 | - $user = $this->find($user_id); |
|
226 | - $user->blocked = 0; |
|
227 | - $user->save(); |
|
228 | - |
|
229 | - return $user; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Send a reset link to the given user. |
|
234 | - * |
|
235 | - * @param string $url |
|
236 | - * @param string $email |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - public function sendReset($email, $url) |
|
240 | - { |
|
241 | - view()->composer('auth.emails.password', function($view) use ($url) { |
|
242 | - $view->with(['url' => $url]); |
|
243 | - }); |
|
244 | - |
|
245 | - $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
246 | - $message->subject('Your Password Reset Link'); |
|
247 | - }); |
|
248 | - |
|
249 | - switch ($response) |
|
250 | - { |
|
251 | - case \Password::INVALID_USER: |
|
252 | - \ErrorHandler::notFound('email'); |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Reset the given user's password. |
|
258 | - * |
|
259 | - * @param array $credentials |
|
260 | - * @return array |
|
261 | - */ |
|
262 | - public function resetPassword($credentials) |
|
263 | - { |
|
264 | - $token = false; |
|
265 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
266 | - $user->password = bcrypt($password); |
|
267 | - $user->save(); |
|
268 | - |
|
269 | - $token = \JWTAuth::fromUser($user); |
|
270 | - }); |
|
271 | - |
|
272 | - switch ($response) { |
|
273 | - case \Password::PASSWORD_RESET: |
|
274 | - return ['token' => $token]; |
|
209 | + return $user; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Unblock the user. |
|
214 | + * |
|
215 | + * @param integer $user_id |
|
216 | + * @return object |
|
217 | + */ |
|
218 | + public function unblock($user_id) |
|
219 | + { |
|
220 | + if ( ! $this->hasGroup('Admin')) |
|
221 | + { |
|
222 | + \ErrorHandler::noPermissions(); |
|
223 | + } |
|
224 | + |
|
225 | + $user = $this->find($user_id); |
|
226 | + $user->blocked = 0; |
|
227 | + $user->save(); |
|
228 | + |
|
229 | + return $user; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Send a reset link to the given user. |
|
234 | + * |
|
235 | + * @param string $url |
|
236 | + * @param string $email |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + public function sendReset($email, $url) |
|
240 | + { |
|
241 | + view()->composer('auth.emails.password', function($view) use ($url) { |
|
242 | + $view->with(['url' => $url]); |
|
243 | + }); |
|
244 | + |
|
245 | + $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
246 | + $message->subject('Your Password Reset Link'); |
|
247 | + }); |
|
248 | + |
|
249 | + switch ($response) |
|
250 | + { |
|
251 | + case \Password::INVALID_USER: |
|
252 | + \ErrorHandler::notFound('email'); |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Reset the given user's password. |
|
258 | + * |
|
259 | + * @param array $credentials |
|
260 | + * @return array |
|
261 | + */ |
|
262 | + public function resetPassword($credentials) |
|
263 | + { |
|
264 | + $token = false; |
|
265 | + $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
266 | + $user->password = bcrypt($password); |
|
267 | + $user->save(); |
|
268 | + |
|
269 | + $token = \JWTAuth::fromUser($user); |
|
270 | + }); |
|
271 | + |
|
272 | + switch ($response) { |
|
273 | + case \Password::PASSWORD_RESET: |
|
274 | + return ['token' => $token]; |
|
275 | 275 | |
276 | - case \Password::INVALID_TOKEN: |
|
277 | - \ErrorHandler::invalidResetToken('token'); |
|
278 | - |
|
279 | - case \Password::INVALID_PASSWORD: |
|
280 | - \ErrorHandler::invalidResetPassword('email'); |
|
281 | - |
|
282 | - case \Password::INVALID_USER: |
|
283 | - \ErrorHandler::notFound('user'); |
|
284 | - |
|
285 | - default: |
|
286 | - \ErrorHandler::generalError(); |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Change the logged in user password. |
|
292 | - * |
|
293 | - * @param array $credentials |
|
294 | - * @return void |
|
295 | - */ |
|
296 | - public function changePassword($credentials) |
|
297 | - { |
|
298 | - $user = $this->find(\JWTAuth::parseToken()->authenticate()->id, $relations); |
|
299 | - if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
300 | - { |
|
301 | - \ErrorHandler::invalidOldPassword(); |
|
302 | - } |
|
303 | - |
|
304 | - $user->password = $credentials['password']; |
|
305 | - $user->save(); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Refresh the expired login token. |
|
310 | - * |
|
311 | - * @return array |
|
312 | - */ |
|
313 | - public function refreshtoken() |
|
314 | - { |
|
315 | - $token = \JWTAuth::parseToken()->refresh(); |
|
316 | - |
|
317 | - return ['token' => $token]; |
|
318 | - } |
|
276 | + case \Password::INVALID_TOKEN: |
|
277 | + \ErrorHandler::invalidResetToken('token'); |
|
278 | + |
|
279 | + case \Password::INVALID_PASSWORD: |
|
280 | + \ErrorHandler::invalidResetPassword('email'); |
|
281 | + |
|
282 | + case \Password::INVALID_USER: |
|
283 | + \ErrorHandler::notFound('user'); |
|
284 | + |
|
285 | + default: |
|
286 | + \ErrorHandler::generalError(); |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Change the logged in user password. |
|
292 | + * |
|
293 | + * @param array $credentials |
|
294 | + * @return void |
|
295 | + */ |
|
296 | + public function changePassword($credentials) |
|
297 | + { |
|
298 | + $user = $this->find(\JWTAuth::parseToken()->authenticate()->id, $relations); |
|
299 | + if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
300 | + { |
|
301 | + \ErrorHandler::invalidOldPassword(); |
|
302 | + } |
|
303 | + |
|
304 | + $user->password = $credentials['password']; |
|
305 | + $user->save(); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Refresh the expired login token. |
|
310 | + * |
|
311 | + * @return array |
|
312 | + */ |
|
313 | + public function refreshtoken() |
|
314 | + { |
|
315 | + $token = \JWTAuth::parseToken()->refresh(); |
|
316 | + |
|
317 | + return ['token' => $token]; |
|
318 | + } |
|
319 | 319 | } |