@@ -4,46 +4,46 @@ |
||
4 | 4 | |
5 | 5 | trait Translatable |
6 | 6 | { |
7 | - /** |
|
8 | - * Create a new model instance that is existing. |
|
9 | - * |
|
10 | - * @param array $attributes |
|
11 | - * @param string|null $connection |
|
12 | - * @return static |
|
13 | - */ |
|
14 | - public function newFromBuilder($attributes = [], $connection = null) |
|
15 | - { |
|
16 | - $model = parent::newFromBuilder($attributes, $connection); |
|
17 | - |
|
18 | - foreach ($model->attributes as $key => $value) { |
|
19 | - if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
20 | - $model->$key = $this->getTranslatedAttribute($value); |
|
21 | - } |
|
22 | - } |
|
23 | - |
|
24 | - return $model; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Returns a translatable model attribute based on the application's locale settings. |
|
29 | - * |
|
30 | - * @param $values |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - protected function getTranslatedAttribute($values) |
|
34 | - { |
|
35 | - $values = json_decode($values); |
|
36 | - $primaryLocale = \Session::get('locale'); |
|
37 | - $fallbackLocale = 'en'; |
|
38 | - |
|
39 | - if ($primaryLocale == 'all') { |
|
40 | - return $values; |
|
41 | - } |
|
42 | - |
|
43 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
44 | - return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
45 | - } |
|
46 | - |
|
47 | - return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
48 | - } |
|
7 | + /** |
|
8 | + * Create a new model instance that is existing. |
|
9 | + * |
|
10 | + * @param array $attributes |
|
11 | + * @param string|null $connection |
|
12 | + * @return static |
|
13 | + */ |
|
14 | + public function newFromBuilder($attributes = [], $connection = null) |
|
15 | + { |
|
16 | + $model = parent::newFromBuilder($attributes, $connection); |
|
17 | + |
|
18 | + foreach ($model->attributes as $key => $value) { |
|
19 | + if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
20 | + $model->$key = $this->getTranslatedAttribute($value); |
|
21 | + } |
|
22 | + } |
|
23 | + |
|
24 | + return $model; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Returns a translatable model attribute based on the application's locale settings. |
|
29 | + * |
|
30 | + * @param $values |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + protected function getTranslatedAttribute($values) |
|
34 | + { |
|
35 | + $values = json_decode($values); |
|
36 | + $primaryLocale = \Session::get('locale'); |
|
37 | + $fallbackLocale = 'en'; |
|
38 | + |
|
39 | + if ($primaryLocale == 'all') { |
|
40 | + return $values; |
|
41 | + } |
|
42 | + |
|
43 | + if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
44 | + return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
45 | + } |
|
46 | + |
|
47 | + return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
48 | + } |
|
49 | 49 | } |
@@ -4,33 +4,33 @@ |
||
4 | 4 | |
5 | 5 | class CoreErrors |
6 | 6 | { |
7 | - public function connectionError() |
|
8 | - { |
|
9 | - abort(500, trans('core::errors.connectionError')); |
|
10 | - } |
|
7 | + public function connectionError() |
|
8 | + { |
|
9 | + abort(500, trans('core::errors.connectionError')); |
|
10 | + } |
|
11 | 11 | |
12 | - public function redisNotRunning() |
|
13 | - { |
|
14 | - abort(500, trans('core::errors.redisNotRunning')); |
|
15 | - } |
|
12 | + public function redisNotRunning() |
|
13 | + { |
|
14 | + abort(500, trans('core::errors.redisNotRunning')); |
|
15 | + } |
|
16 | 16 | |
17 | - public function dbQueryError() |
|
18 | - { |
|
19 | - abort(500, trans('core::errors.dbQueryError')); |
|
20 | - } |
|
17 | + public function dbQueryError() |
|
18 | + { |
|
19 | + abort(500, trans('core::errors.dbQueryError')); |
|
20 | + } |
|
21 | 21 | |
22 | - public function cannotCreateSetting() |
|
23 | - { |
|
24 | - abort(400, trans('core::errors.cannotCreateSetting')); |
|
25 | - } |
|
22 | + public function cannotCreateSetting() |
|
23 | + { |
|
24 | + abort(400, trans('core::errors.cannotCreateSetting')); |
|
25 | + } |
|
26 | 26 | |
27 | - public function cannotUpdateSettingKey() |
|
28 | - { |
|
29 | - abort(400, trans('core::errors.cannotUpdateSettingKey')); |
|
30 | - } |
|
27 | + public function cannotUpdateSettingKey() |
|
28 | + { |
|
29 | + abort(400, trans('core::errors.cannotUpdateSettingKey')); |
|
30 | + } |
|
31 | 31 | |
32 | - public function notFound($text) |
|
33 | - { |
|
34 | - abort(404, trans('core::errors.notFound', ['replace' => $text])); |
|
35 | - } |
|
32 | + public function notFound($text) |
|
33 | + { |
|
34 | + abort(404, trans('core::errors.notFound', ['replace' => $text])); |
|
35 | + } |
|
36 | 36 | } |
@@ -6,26 +6,26 @@ |
||
6 | 6 | |
7 | 7 | class Errors implements BaseFactoryInterface |
8 | 8 | { |
9 | - /** |
|
10 | - * Construct the repository class name based on |
|
11 | - * the method name called, search in the |
|
12 | - * given namespaces for the class and |
|
13 | - * return an instance. |
|
14 | - * |
|
15 | - * @param string $name the called method name |
|
16 | - * @param array $arguments the method arguments |
|
17 | - * @return object |
|
18 | - */ |
|
19 | - public function __call($name, $arguments) |
|
20 | - { |
|
21 | - foreach (\Module::all() as $module) { |
|
22 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
23 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
9 | + /** |
|
10 | + * Construct the repository class name based on |
|
11 | + * the method name called, search in the |
|
12 | + * given namespaces for the class and |
|
13 | + * return an instance. |
|
14 | + * |
|
15 | + * @param string $name the called method name |
|
16 | + * @param array $arguments the method arguments |
|
17 | + * @return object |
|
18 | + */ |
|
19 | + public function __call($name, $arguments) |
|
20 | + { |
|
21 | + foreach (\Module::all() as $module) { |
|
22 | + $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
23 | + $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
24 | 24 | |
25 | - if (class_exists($class)) { |
|
26 | - $class = \App::make($class); |
|
27 | - if (method_exists($class, $name)) return call_user_func_array([$class, $name], $arguments); |
|
28 | - } |
|
29 | - } |
|
30 | - } |
|
25 | + if (class_exists($class)) { |
|
26 | + $class = \App::make($class); |
|
27 | + if (method_exists($class, $name)) return call_user_func_array([$class, $name], $arguments); |
|
28 | + } |
|
29 | + } |
|
30 | + } |
|
31 | 31 | } |
@@ -7,69 +7,69 @@ |
||
7 | 7 | */ |
8 | 8 | class RoleObserver |
9 | 9 | { |
10 | - public function saving($model) |
|
11 | - { |
|
12 | - // |
|
13 | - } |
|
10 | + public function saving($model) |
|
11 | + { |
|
12 | + // |
|
13 | + } |
|
14 | 14 | |
15 | - public function saved($model) |
|
16 | - { |
|
17 | - // |
|
18 | - } |
|
15 | + public function saved($model) |
|
16 | + { |
|
17 | + // |
|
18 | + } |
|
19 | 19 | |
20 | - public function creating($model) |
|
21 | - { |
|
22 | - // |
|
23 | - } |
|
20 | + public function creating($model) |
|
21 | + { |
|
22 | + // |
|
23 | + } |
|
24 | 24 | |
25 | - public function created($model) |
|
26 | - { |
|
27 | - // |
|
28 | - } |
|
25 | + public function created($model) |
|
26 | + { |
|
27 | + // |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Prevent updating of the admin role. |
|
32 | - * |
|
33 | - * @param object $model the model beign updated. |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function updating($model) |
|
37 | - { |
|
38 | - if ($model->getOriginal('name') == 'Admin') { |
|
39 | - \Errors::noPermissions(); |
|
40 | - } |
|
41 | - } |
|
30 | + /** |
|
31 | + * Prevent updating of the admin role. |
|
32 | + * |
|
33 | + * @param object $model the model beign updated. |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function updating($model) |
|
37 | + { |
|
38 | + if ($model->getOriginal('name') == 'Admin') { |
|
39 | + \Errors::noPermissions(); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - public function updated($model) |
|
44 | - { |
|
45 | - // |
|
46 | - } |
|
43 | + public function updated($model) |
|
44 | + { |
|
45 | + // |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Prevent deleting the admin role. |
|
50 | - * |
|
51 | - * @param object $model the delted model. |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function deleting($model) |
|
55 | - { |
|
56 | - if ($model->getOriginal('name') == 'Admin') { |
|
57 | - \Errors::noPermissions(); |
|
58 | - } |
|
59 | - } |
|
48 | + /** |
|
49 | + * Prevent deleting the admin role. |
|
50 | + * |
|
51 | + * @param object $model the delted model. |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function deleting($model) |
|
55 | + { |
|
56 | + if ($model->getOriginal('name') == 'Admin') { |
|
57 | + \Errors::noPermissions(); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - public function deleted($model) |
|
62 | - { |
|
63 | - // |
|
64 | - } |
|
61 | + public function deleted($model) |
|
62 | + { |
|
63 | + // |
|
64 | + } |
|
65 | 65 | |
66 | - public function restoring($model) |
|
67 | - { |
|
68 | - // |
|
69 | - } |
|
66 | + public function restoring($model) |
|
67 | + { |
|
68 | + // |
|
69 | + } |
|
70 | 70 | |
71 | - public function restored($model) |
|
72 | - { |
|
73 | - // |
|
74 | - } |
|
71 | + public function restored($model) |
|
72 | + { |
|
73 | + // |
|
74 | + } |
|
75 | 75 | } |
@@ -2,21 +2,21 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * Here goes your error messages. |
|
7 | - */ |
|
8 | - 'unAuthorized' => 'Please login before any action', |
|
9 | - 'invalidRefreshToken' => 'Invalid refresh token', |
|
10 | - 'noPermissions' => 'No permissions', |
|
11 | - 'loginFailed' => 'Wrong mail or password', |
|
12 | - 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
13 | - 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
14 | - 'userIsBlocked' => 'You have been blocked', |
|
15 | - 'invalidResetToken' => 'Reset password token is invalid', |
|
16 | - 'invalidResetPassword' => 'Reset password is invalid', |
|
17 | - 'invalidOldPassword' => 'Old password is invalid', |
|
18 | - 'invalidConfirmationCode' => 'Confirmation link expired or already used', |
|
19 | - 'emailNotConfirmed' => 'Your email isn\'t confirmed', |
|
20 | - 'emailAlreadyConfirmed' => 'Your email is already confirmed' |
|
5 | + /** |
|
6 | + * Here goes your error messages. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'Please login before any action', |
|
9 | + 'invalidRefreshToken' => 'Invalid refresh token', |
|
10 | + 'noPermissions' => 'No permissions', |
|
11 | + 'loginFailed' => 'Wrong mail or password', |
|
12 | + 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
13 | + 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
14 | + 'userIsBlocked' => 'You have been blocked', |
|
15 | + 'invalidResetToken' => 'Reset password token is invalid', |
|
16 | + 'invalidResetPassword' => 'Reset password is invalid', |
|
17 | + 'invalidOldPassword' => 'Old password is invalid', |
|
18 | + 'invalidConfirmationCode' => 'Confirmation link expired or already used', |
|
19 | + 'emailNotConfirmed' => 'Your email isn\'t confirmed', |
|
20 | + 'emailAlreadyConfirmed' => 'Your email is already confirmed' |
|
21 | 21 | |
22 | 22 | ]; |
@@ -2,21 +2,21 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * Here goes your error messages. |
|
7 | - */ |
|
8 | - 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | - 'invalidRefreshToken' => 'رمز التحديث غير صالح', |
|
10 | - 'noPermissions' => 'لا توجد صلاحية', |
|
11 | - 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | - 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
13 | - 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
14 | - 'userIsBlocked' => 'لقد تم حظرك', |
|
15 | - 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
16 | - 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
17 | - 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
18 | - 'invalidConfirmationCode' => 'لينك التاكيد غير صالح اة مستخدم من قبل', |
|
19 | - 'emailNotConfirmed' => 'بريدك الاكتروني غير مفعل', |
|
20 | - 'emailAlreadyConfirmed' => 'البريد الاكتروني مفع بالقعل' |
|
5 | + /** |
|
6 | + * Here goes your error messages. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | + 'invalidRefreshToken' => 'رمز التحديث غير صالح', |
|
10 | + 'noPermissions' => 'لا توجد صلاحية', |
|
11 | + 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | + 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
13 | + 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
14 | + 'userIsBlocked' => 'لقد تم حظرك', |
|
15 | + 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
16 | + 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
17 | + 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
18 | + 'invalidConfirmationCode' => 'لينك التاكيد غير صالح اة مستخدم من قبل', |
|
19 | + 'emailNotConfirmed' => 'بريدك الاكتروني غير مفعل', |
|
20 | + 'emailAlreadyConfirmed' => 'البريد الاكتروني مفع بالقعل' |
|
21 | 21 | |
22 | 22 | ]; |
@@ -24,225 +24,225 @@ |
||
24 | 24 | |
25 | 25 | class UserController extends BaseApiController |
26 | 26 | { |
27 | - /** |
|
28 | - * Path of the model resource |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser'; |
|
33 | - |
|
34 | - /** |
|
35 | - * List of all route actions that the base api controller |
|
36 | - * will skip permissions check for them. |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile']; |
|
40 | - |
|
41 | - /** |
|
42 | - * List of all route actions that the base api controller |
|
43 | - * will skip login check for them. |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation']; |
|
47 | - |
|
48 | - /** |
|
49 | - * Init new object. |
|
50 | - * |
|
51 | - * @param UserService $service |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function __construct(UserService $service) |
|
55 | - { |
|
56 | - parent::__construct($service); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Insert the given model to storage. |
|
61 | - * |
|
62 | - * @param InsertUser $request |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function insert(InsertUser $request) |
|
66 | - { |
|
67 | - return new $this->modelResource($this->service->save($request->all())); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Update the given model to storage. |
|
72 | - * |
|
73 | - * @param UpdateUser $request |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function update(UpdateUser $request) |
|
77 | - { |
|
78 | - return new $this->modelResource($this->service->save($request->all())); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Return the logged in user account. |
|
83 | - * |
|
84 | - * @param Request $request |
|
85 | - * @return \Illuminate\Http\Response |
|
86 | - */ |
|
87 | - public function account(Request $request) |
|
88 | - { |
|
89 | - return new $this->modelResource($this->service->account($request->relations)); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Block the user. |
|
94 | - * |
|
95 | - * @param integer $id Id of the user. |
|
96 | - * @return \Illuminate\Http\Response |
|
97 | - */ |
|
98 | - public function block($id) |
|
99 | - { |
|
100 | - return new $this->modelResource($this->service->block($id)); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Unblock the user. |
|
105 | - * |
|
106 | - * @param integer $id Id of the user. |
|
107 | - * @return \Illuminate\Http\Response |
|
108 | - */ |
|
109 | - public function unblock($id) |
|
110 | - { |
|
111 | - return new $this->modelResource($this->service->unblock($id)); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Logout the user. |
|
116 | - * |
|
117 | - * @return \Illuminate\Http\Response |
|
118 | - */ |
|
119 | - public function logout() |
|
120 | - { |
|
121 | - return new GeneralResource($this->service->logout()); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Handle a registration request. |
|
126 | - * |
|
127 | - * @param Register $request |
|
128 | - * @return \Illuminate\Http\Response |
|
129 | - */ |
|
130 | - public function register(Register $request) |
|
131 | - { |
|
132 | - return new $this->modelResource($this->service->register($request->get('name'), $request->get('email'), $request->get('password'))); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Handle a login request to the application. |
|
137 | - * |
|
138 | - * @param Login $request |
|
139 | - * @return \Illuminate\Http\Response |
|
140 | - */ |
|
141 | - public function login(Login $request) |
|
142 | - { |
|
143 | - $result = $this->service->login($request->get('email'), $request->get('password'), $request->get('admin')); |
|
144 | - |
|
145 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Handle a social login request of the none admin to the application. |
|
150 | - * |
|
151 | - * @param LoginSocial $request |
|
152 | - * @return \Illuminate\Http\Response |
|
153 | - */ |
|
154 | - public function loginSocial(LoginSocial $request) |
|
155 | - { |
|
156 | - $result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
157 | - |
|
158 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Assign the given roles to the given user. |
|
163 | - * |
|
164 | - * @param AssignRoles $request |
|
165 | - * @return \Illuminate\Http\Response |
|
166 | - */ |
|
167 | - public function assignRoles(AssignRoles $request) |
|
168 | - { |
|
169 | - return new $this->modelResource($this->service->assignRoles($request->get('user_id'), $request->get('role_ids'))); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Send a reset link to the given user. |
|
174 | - * |
|
175 | - * @param SendReset $request |
|
176 | - * @return \Illuminate\Http\Response |
|
177 | - */ |
|
178 | - public function sendReset(SendReset $request) |
|
179 | - { |
|
180 | - return new GeneralResource($this->service->sendReset($request->get('email'))); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Reset the given user's password. |
|
185 | - * |
|
186 | - * @param ResetPassword $request |
|
187 | - * @return \Illuminate\Http\Response |
|
188 | - */ |
|
189 | - public function resetPassword(ResetPassword $request) |
|
190 | - { |
|
191 | - return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token'))); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Change the logged in user password. |
|
196 | - * |
|
197 | - * @param ChangePassword $request |
|
198 | - * @return \Illuminate\Http\Response |
|
199 | - */ |
|
200 | - public function changePassword(ChangePassword $request) |
|
201 | - { |
|
202 | - return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password'))); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Confirm email using the confirmation code. |
|
207 | - * |
|
208 | - * @param ConfirmEmail $request |
|
209 | - * @return \Illuminate\Http\Response |
|
210 | - */ |
|
211 | - public function confirmEmail(ConfirmEmail $request) |
|
212 | - { |
|
213 | - return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code'))); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Resend the email confirmation mail. |
|
218 | - * |
|
219 | - * @param ResendEmailConfirmation $request |
|
220 | - * @return \Illuminate\Http\Response |
|
221 | - */ |
|
222 | - public function resendEmailConfirmation(ResendEmailConfirmation $request) |
|
223 | - { |
|
224 | - return new GeneralResource($this->service->sendConfirmationEmail($request->get('email'))); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Refresh the expired login token. |
|
229 | - * |
|
230 | - * @param RefreshToken $request |
|
231 | - * @return \Illuminate\Http\Response |
|
232 | - */ |
|
233 | - public function refreshToken(RefreshToken $request) |
|
234 | - { |
|
235 | - return new GeneralResource($this->service->refreshToken($request->get('refresh_token'))); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Save the given data to the logged in user. |
|
240 | - * |
|
241 | - * @param SaveProfile $request |
|
242 | - * @return \Illuminate\Http\Response |
|
243 | - */ |
|
244 | - public function saveProfile(SaveProfile $request) |
|
245 | - { |
|
246 | - return new $this->modelResource($this->service->saveProfile($request->get('name'), $request->get('email'), $request->get('profile_picture'))); |
|
247 | - } |
|
27 | + /** |
|
28 | + * Path of the model resource |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser'; |
|
33 | + |
|
34 | + /** |
|
35 | + * List of all route actions that the base api controller |
|
36 | + * will skip permissions check for them. |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile']; |
|
40 | + |
|
41 | + /** |
|
42 | + * List of all route actions that the base api controller |
|
43 | + * will skip login check for them. |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation']; |
|
47 | + |
|
48 | + /** |
|
49 | + * Init new object. |
|
50 | + * |
|
51 | + * @param UserService $service |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function __construct(UserService $service) |
|
55 | + { |
|
56 | + parent::__construct($service); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Insert the given model to storage. |
|
61 | + * |
|
62 | + * @param InsertUser $request |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function insert(InsertUser $request) |
|
66 | + { |
|
67 | + return new $this->modelResource($this->service->save($request->all())); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Update the given model to storage. |
|
72 | + * |
|
73 | + * @param UpdateUser $request |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function update(UpdateUser $request) |
|
77 | + { |
|
78 | + return new $this->modelResource($this->service->save($request->all())); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Return the logged in user account. |
|
83 | + * |
|
84 | + * @param Request $request |
|
85 | + * @return \Illuminate\Http\Response |
|
86 | + */ |
|
87 | + public function account(Request $request) |
|
88 | + { |
|
89 | + return new $this->modelResource($this->service->account($request->relations)); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Block the user. |
|
94 | + * |
|
95 | + * @param integer $id Id of the user. |
|
96 | + * @return \Illuminate\Http\Response |
|
97 | + */ |
|
98 | + public function block($id) |
|
99 | + { |
|
100 | + return new $this->modelResource($this->service->block($id)); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Unblock the user. |
|
105 | + * |
|
106 | + * @param integer $id Id of the user. |
|
107 | + * @return \Illuminate\Http\Response |
|
108 | + */ |
|
109 | + public function unblock($id) |
|
110 | + { |
|
111 | + return new $this->modelResource($this->service->unblock($id)); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Logout the user. |
|
116 | + * |
|
117 | + * @return \Illuminate\Http\Response |
|
118 | + */ |
|
119 | + public function logout() |
|
120 | + { |
|
121 | + return new GeneralResource($this->service->logout()); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Handle a registration request. |
|
126 | + * |
|
127 | + * @param Register $request |
|
128 | + * @return \Illuminate\Http\Response |
|
129 | + */ |
|
130 | + public function register(Register $request) |
|
131 | + { |
|
132 | + return new $this->modelResource($this->service->register($request->get('name'), $request->get('email'), $request->get('password'))); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Handle a login request to the application. |
|
137 | + * |
|
138 | + * @param Login $request |
|
139 | + * @return \Illuminate\Http\Response |
|
140 | + */ |
|
141 | + public function login(Login $request) |
|
142 | + { |
|
143 | + $result = $this->service->login($request->get('email'), $request->get('password'), $request->get('admin')); |
|
144 | + |
|
145 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Handle a social login request of the none admin to the application. |
|
150 | + * |
|
151 | + * @param LoginSocial $request |
|
152 | + * @return \Illuminate\Http\Response |
|
153 | + */ |
|
154 | + public function loginSocial(LoginSocial $request) |
|
155 | + { |
|
156 | + $result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
157 | + |
|
158 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Assign the given roles to the given user. |
|
163 | + * |
|
164 | + * @param AssignRoles $request |
|
165 | + * @return \Illuminate\Http\Response |
|
166 | + */ |
|
167 | + public function assignRoles(AssignRoles $request) |
|
168 | + { |
|
169 | + return new $this->modelResource($this->service->assignRoles($request->get('user_id'), $request->get('role_ids'))); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Send a reset link to the given user. |
|
174 | + * |
|
175 | + * @param SendReset $request |
|
176 | + * @return \Illuminate\Http\Response |
|
177 | + */ |
|
178 | + public function sendReset(SendReset $request) |
|
179 | + { |
|
180 | + return new GeneralResource($this->service->sendReset($request->get('email'))); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Reset the given user's password. |
|
185 | + * |
|
186 | + * @param ResetPassword $request |
|
187 | + * @return \Illuminate\Http\Response |
|
188 | + */ |
|
189 | + public function resetPassword(ResetPassword $request) |
|
190 | + { |
|
191 | + return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token'))); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Change the logged in user password. |
|
196 | + * |
|
197 | + * @param ChangePassword $request |
|
198 | + * @return \Illuminate\Http\Response |
|
199 | + */ |
|
200 | + public function changePassword(ChangePassword $request) |
|
201 | + { |
|
202 | + return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password'))); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Confirm email using the confirmation code. |
|
207 | + * |
|
208 | + * @param ConfirmEmail $request |
|
209 | + * @return \Illuminate\Http\Response |
|
210 | + */ |
|
211 | + public function confirmEmail(ConfirmEmail $request) |
|
212 | + { |
|
213 | + return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code'))); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Resend the email confirmation mail. |
|
218 | + * |
|
219 | + * @param ResendEmailConfirmation $request |
|
220 | + * @return \Illuminate\Http\Response |
|
221 | + */ |
|
222 | + public function resendEmailConfirmation(ResendEmailConfirmation $request) |
|
223 | + { |
|
224 | + return new GeneralResource($this->service->sendConfirmationEmail($request->get('email'))); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Refresh the expired login token. |
|
229 | + * |
|
230 | + * @param RefreshToken $request |
|
231 | + * @return \Illuminate\Http\Response |
|
232 | + */ |
|
233 | + public function refreshToken(RefreshToken $request) |
|
234 | + { |
|
235 | + return new GeneralResource($this->service->refreshToken($request->get('refresh_token'))); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Save the given data to the logged in user. |
|
240 | + * |
|
241 | + * @param SaveProfile $request |
|
242 | + * @return \Illuminate\Http\Response |
|
243 | + */ |
|
244 | + public function saveProfile(SaveProfile $request) |
|
245 | + { |
|
246 | + return new $this->modelResource($this->service->saveProfile($request->get('name'), $request->get('email'), $request->get('profile_picture'))); |
|
247 | + } |
|
248 | 248 | } |
@@ -6,26 +6,26 @@ |
||
6 | 6 | |
7 | 7 | class AssignRoles extends FormRequest |
8 | 8 | { |
9 | - /** |
|
10 | - * Determine if the user is authorized to make this request. |
|
11 | - * |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public function authorize() |
|
15 | - { |
|
16 | - return true; |
|
17 | - } |
|
9 | + /** |
|
10 | + * Determine if the user is authorized to make this request. |
|
11 | + * |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public function authorize() |
|
15 | + { |
|
16 | + return true; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Get the validation rules that apply to the request. |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function rules() |
|
25 | - { |
|
26 | - return [ |
|
27 | - 'role_ids' => 'required|exists:roles,id', |
|
28 | - 'user_id' => 'required|exists:users,id' |
|
29 | - ]; |
|
30 | - } |
|
19 | + /** |
|
20 | + * Get the validation rules that apply to the request. |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function rules() |
|
25 | + { |
|
26 | + return [ |
|
27 | + 'role_ids' => 'required|exists:roles,id', |
|
28 | + 'user_id' => 'required|exists:users,id' |
|
29 | + ]; |
|
30 | + } |
|
31 | 31 | } |
@@ -6,52 +6,52 @@ |
||
6 | 6 | |
7 | 7 | class UserRepository extends BaseRepository |
8 | 8 | { |
9 | - /** |
|
10 | - * Init new object. |
|
11 | - * |
|
12 | - * @param AclUser $model |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function __construct(AclUser $model) |
|
16 | - { |
|
17 | - parent::__construct($model); |
|
18 | - } |
|
9 | + /** |
|
10 | + * Init new object. |
|
11 | + * |
|
12 | + * @param AclUser $model |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function __construct(AclUser $model) |
|
16 | + { |
|
17 | + parent::__construct($model); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * Detach all roles from the given role. |
|
22 | - * |
|
23 | - * @param mixed $role |
|
24 | - * @return object |
|
25 | - */ |
|
26 | - public function detachRoles($role) |
|
27 | - { |
|
28 | - $role = ! is_int($role) ? $role : $this->find($role); |
|
29 | - $role->roles()->detach(); |
|
30 | - } |
|
20 | + /** |
|
21 | + * Detach all roles from the given role. |
|
22 | + * |
|
23 | + * @param mixed $role |
|
24 | + * @return object |
|
25 | + */ |
|
26 | + public function detachRoles($role) |
|
27 | + { |
|
28 | + $role = ! is_int($role) ? $role : $this->find($role); |
|
29 | + $role->roles()->detach(); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Attach role ids to the given role. |
|
34 | - * |
|
35 | - * @param mixed $role |
|
36 | - * @param array $roleIds |
|
37 | - * @return object |
|
38 | - */ |
|
39 | - public function attachRoles($role, $roleIds) |
|
40 | - { |
|
41 | - $role = ! is_int($role) ? $role : $this->find($role); |
|
42 | - $role->roles()->attach($roleIds); |
|
43 | - } |
|
32 | + /** |
|
33 | + * Attach role ids to the given role. |
|
34 | + * |
|
35 | + * @param mixed $role |
|
36 | + * @param array $roleIds |
|
37 | + * @return object |
|
38 | + */ |
|
39 | + public function attachRoles($role, $roleIds) |
|
40 | + { |
|
41 | + $role = ! is_int($role) ? $role : $this->find($role); |
|
42 | + $role->roles()->attach($roleIds); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Count the given user the given roles. |
|
47 | - * |
|
48 | - * @param mixed $user |
|
49 | - * @param string[] $roles |
|
50 | - * @return boolean |
|
51 | - */ |
|
52 | - public function countRoles($user, $roles) |
|
53 | - { |
|
54 | - $user = ! is_int($user) ? $user : $this->find($user); |
|
55 | - return $user->roles()->whereIn('name', $roles)->count(); |
|
56 | - } |
|
45 | + /** |
|
46 | + * Count the given user the given roles. |
|
47 | + * |
|
48 | + * @param mixed $user |
|
49 | + * @param string[] $roles |
|
50 | + * @return boolean |
|
51 | + */ |
|
52 | + public function countRoles($user, $roles) |
|
53 | + { |
|
54 | + $user = ! is_int($user) ? $user : $this->find($user); |
|
55 | + return $user->roles()->whereIn('name', $roles)->count(); |
|
56 | + } |
|
57 | 57 | } |