@@ -6,400 +6,400 @@ |
||
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 | - } |
|
19 | - |
|
20 | - /** |
|
21 | - * Return the logged in user account. |
|
22 | - * |
|
23 | - * @param array $relations |
|
24 | - * @return boolean |
|
25 | - */ |
|
26 | - public function account($relations = []) |
|
27 | - { |
|
28 | - $permissions = []; |
|
29 | - $user = $this->find(\Auth::id(), $relations); |
|
30 | - foreach ($user->roles()->get() as $role) { |
|
31 | - $role->permissions->each(function ($permission) use (&$permissions) { |
|
32 | - $permissions[$permission->model][$permission->id] = $permission->name; |
|
33 | - }); |
|
34 | - } |
|
35 | - $user->permissions = $permissions; |
|
36 | - |
|
37 | - return $user; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Check if the logged in user or the given user |
|
42 | - * has the given permissions on the given model. |
|
43 | - * |
|
44 | - * @param string $nameOfPermission |
|
45 | - * @param string $model |
|
46 | - * @param mixed $user |
|
47 | - * @return boolean |
|
48 | - */ |
|
49 | - public function can($nameOfPermission, $model, $user = false) |
|
50 | - { |
|
51 | - $user = $user ?: $this->find(\Auth::id(), ['roles.permissions']); |
|
52 | - $permissions = []; |
|
53 | - |
|
54 | - $user->roles->pluck('permissions')->each(function ($permission) use (&$permissions, $model) { |
|
55 | - $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
56 | - }); |
|
57 | - |
|
58 | - return in_array($nameOfPermission, $permissions); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Check if the logged in user has the given role. |
|
63 | - * |
|
64 | - * @param string[] $roles |
|
65 | - * @param mixed $user |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function hasRole($roles, $user = false) |
|
69 | - { |
|
70 | - $user = $user ?: $this->find(\Auth::id()); |
|
71 | - return $user->roles->whereIn('name', $roles)->count() ? true : false; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Assign the given role ids to the given user. |
|
76 | - * |
|
77 | - * @param integer $userId |
|
78 | - * @param array $roleIds |
|
79 | - * @return object |
|
80 | - */ |
|
81 | - public function assignRoles($userId, $roleIds) |
|
82 | - { |
|
83 | - \DB::transaction(function () use ($userId, $roleIds) { |
|
84 | - $user = $this->find($userId); |
|
85 | - $user->roles()->detach(); |
|
86 | - $user->roles()->attach($roleIds); |
|
87 | - }); |
|
88 | - |
|
89 | - return $this->find($userId); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Handle a login request to the application. |
|
95 | - * |
|
96 | - * @param array $credentials |
|
97 | - * @param boolean $adminLogin |
|
98 | - * @return object |
|
99 | - */ |
|
100 | - public function login($credentials, $adminLogin = false) |
|
101 | - { |
|
102 | - if (! $user = $this->first(['email' => $credentials['email']])) { |
|
103 | - \ErrorHandler::loginFailed(); |
|
104 | - } elseif ($adminLogin && ! $user->roles->whereIn('name', ['Admin'])->count()) { |
|
105 | - \ErrorHandler::loginFailed(); |
|
106 | - } elseif (! $adminLogin && $user->roles->whereIn('name', ['Admin'])->count()) { |
|
107 | - \ErrorHandler::loginFailed(); |
|
108 | - } elseif ($user->blocked) { |
|
109 | - \ErrorHandler::userIsBlocked(); |
|
110 | - } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
111 | - \ErrorHandler::emailNotConfirmed(); |
|
112 | - } |
|
113 | - |
|
114 | - return $user; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Handle a social login request of the none admin to the application. |
|
119 | - * |
|
120 | - * @param string $authCode |
|
121 | - * @param string $accessToken |
|
122 | - * @param string $type |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function loginSocial($authCode, $accessToken, $type) |
|
126 | - { |
|
127 | - $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
|
128 | - $user = \Socialite::driver($type)->userFromToken($access_token); |
|
129 | - |
|
130 | - if (! $user->email) { |
|
131 | - \ErrorHandler::noSocialEmail(); |
|
132 | - } |
|
133 | - |
|
134 | - if (! $this->model->where('email', $user->email)->first()) { |
|
135 | - $this->register(['email' => $user->email, 'password' => ''], true); |
|
136 | - } |
|
137 | - |
|
138 | - $loginProxy = \App::make('App\Modules\Users\Proxy\LoginProxy'); |
|
139 | - return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0); |
|
140 | - } |
|
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 | + |
|
20 | + /** |
|
21 | + * Return the logged in user account. |
|
22 | + * |
|
23 | + * @param array $relations |
|
24 | + * @return boolean |
|
25 | + */ |
|
26 | + public function account($relations = []) |
|
27 | + { |
|
28 | + $permissions = []; |
|
29 | + $user = $this->find(\Auth::id(), $relations); |
|
30 | + foreach ($user->roles()->get() as $role) { |
|
31 | + $role->permissions->each(function ($permission) use (&$permissions) { |
|
32 | + $permissions[$permission->model][$permission->id] = $permission->name; |
|
33 | + }); |
|
34 | + } |
|
35 | + $user->permissions = $permissions; |
|
36 | + |
|
37 | + return $user; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Check if the logged in user or the given user |
|
42 | + * has the given permissions on the given model. |
|
43 | + * |
|
44 | + * @param string $nameOfPermission |
|
45 | + * @param string $model |
|
46 | + * @param mixed $user |
|
47 | + * @return boolean |
|
48 | + */ |
|
49 | + public function can($nameOfPermission, $model, $user = false) |
|
50 | + { |
|
51 | + $user = $user ?: $this->find(\Auth::id(), ['roles.permissions']); |
|
52 | + $permissions = []; |
|
53 | + |
|
54 | + $user->roles->pluck('permissions')->each(function ($permission) use (&$permissions, $model) { |
|
55 | + $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
56 | + }); |
|
57 | + |
|
58 | + return in_array($nameOfPermission, $permissions); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Check if the logged in user has the given role. |
|
63 | + * |
|
64 | + * @param string[] $roles |
|
65 | + * @param mixed $user |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function hasRole($roles, $user = false) |
|
69 | + { |
|
70 | + $user = $user ?: $this->find(\Auth::id()); |
|
71 | + return $user->roles->whereIn('name', $roles)->count() ? true : false; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Assign the given role ids to the given user. |
|
76 | + * |
|
77 | + * @param integer $userId |
|
78 | + * @param array $roleIds |
|
79 | + * @return object |
|
80 | + */ |
|
81 | + public function assignRoles($userId, $roleIds) |
|
82 | + { |
|
83 | + \DB::transaction(function () use ($userId, $roleIds) { |
|
84 | + $user = $this->find($userId); |
|
85 | + $user->roles()->detach(); |
|
86 | + $user->roles()->attach($roleIds); |
|
87 | + }); |
|
88 | + |
|
89 | + return $this->find($userId); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Handle a login request to the application. |
|
95 | + * |
|
96 | + * @param array $credentials |
|
97 | + * @param boolean $adminLogin |
|
98 | + * @return object |
|
99 | + */ |
|
100 | + public function login($credentials, $adminLogin = false) |
|
101 | + { |
|
102 | + if (! $user = $this->first(['email' => $credentials['email']])) { |
|
103 | + \ErrorHandler::loginFailed(); |
|
104 | + } elseif ($adminLogin && ! $user->roles->whereIn('name', ['Admin'])->count()) { |
|
105 | + \ErrorHandler::loginFailed(); |
|
106 | + } elseif (! $adminLogin && $user->roles->whereIn('name', ['Admin'])->count()) { |
|
107 | + \ErrorHandler::loginFailed(); |
|
108 | + } elseif ($user->blocked) { |
|
109 | + \ErrorHandler::userIsBlocked(); |
|
110 | + } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
111 | + \ErrorHandler::emailNotConfirmed(); |
|
112 | + } |
|
113 | + |
|
114 | + return $user; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Handle a social login request of the none admin to the application. |
|
119 | + * |
|
120 | + * @param string $authCode |
|
121 | + * @param string $accessToken |
|
122 | + * @param string $type |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function loginSocial($authCode, $accessToken, $type) |
|
126 | + { |
|
127 | + $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
|
128 | + $user = \Socialite::driver($type)->userFromToken($access_token); |
|
129 | + |
|
130 | + if (! $user->email) { |
|
131 | + \ErrorHandler::noSocialEmail(); |
|
132 | + } |
|
133 | + |
|
134 | + if (! $this->model->where('email', $user->email)->first()) { |
|
135 | + $this->register(['email' => $user->email, 'password' => ''], true); |
|
136 | + } |
|
137 | + |
|
138 | + $loginProxy = \App::make('App\Modules\Users\Proxy\LoginProxy'); |
|
139 | + return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Handle a registration request. |
|
144 | - * |
|
145 | - * @param array $credentials |
|
146 | - * @param boolean $skipConfirmEmail |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public function register($credentials, $skipConfirmEmail = false) |
|
150 | - { |
|
151 | - $user = $this->save($credentials); |
|
152 | - |
|
153 | - if ($skipConfirmEmail) { |
|
154 | - $user->confirmed = 1; |
|
155 | - $user->save(); |
|
156 | - } elseif (! config('skeleton.disable_confirm_email')) { |
|
157 | - $this->sendConfirmationEmail($user->email); |
|
158 | - } |
|
159 | - |
|
160 | - return $user; |
|
161 | - } |
|
142 | + /** |
|
143 | + * Handle a registration request. |
|
144 | + * |
|
145 | + * @param array $credentials |
|
146 | + * @param boolean $skipConfirmEmail |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public function register($credentials, $skipConfirmEmail = false) |
|
150 | + { |
|
151 | + $user = $this->save($credentials); |
|
152 | + |
|
153 | + if ($skipConfirmEmail) { |
|
154 | + $user->confirmed = 1; |
|
155 | + $user->save(); |
|
156 | + } elseif (! config('skeleton.disable_confirm_email')) { |
|
157 | + $this->sendConfirmationEmail($user->email); |
|
158 | + } |
|
159 | + |
|
160 | + return $user; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Block the user. |
|
165 | - * |
|
166 | - * @param integer $userId |
|
167 | - * @return object |
|
168 | - */ |
|
169 | - public function block($userId) |
|
170 | - { |
|
171 | - if (! $user = $this->find($userId)) { |
|
172 | - \ErrorHandler::notFound('user'); |
|
173 | - } |
|
174 | - if (! $this->hasRole(['Admin'])) { |
|
175 | - \ErrorHandler::noPermissions(); |
|
176 | - } elseif (\Auth::id() == $userId) { |
|
177 | - \ErrorHandler::noPermissions(); |
|
178 | - } elseif ($user->roles->pluck('name')->search('Admin', true) !== false) { |
|
179 | - \ErrorHandler::noPermissions(); |
|
180 | - } |
|
181 | - |
|
182 | - $user->blocked = 1; |
|
183 | - $user->save(); |
|
163 | + /** |
|
164 | + * Block the user. |
|
165 | + * |
|
166 | + * @param integer $userId |
|
167 | + * @return object |
|
168 | + */ |
|
169 | + public function block($userId) |
|
170 | + { |
|
171 | + if (! $user = $this->find($userId)) { |
|
172 | + \ErrorHandler::notFound('user'); |
|
173 | + } |
|
174 | + if (! $this->hasRole(['Admin'])) { |
|
175 | + \ErrorHandler::noPermissions(); |
|
176 | + } elseif (\Auth::id() == $userId) { |
|
177 | + \ErrorHandler::noPermissions(); |
|
178 | + } elseif ($user->roles->pluck('name')->search('Admin', true) !== false) { |
|
179 | + \ErrorHandler::noPermissions(); |
|
180 | + } |
|
181 | + |
|
182 | + $user->blocked = 1; |
|
183 | + $user->save(); |
|
184 | 184 | |
185 | - return $user; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Unblock the user. |
|
190 | - * |
|
191 | - * @param integer $userId |
|
192 | - * @return object |
|
193 | - */ |
|
194 | - public function unblock($userId) |
|
195 | - { |
|
196 | - if (! $this->hasRole(['Admin'])) { |
|
197 | - \ErrorHandler::noPermissions(); |
|
198 | - } |
|
199 | - |
|
200 | - $user = $this->find($userId); |
|
201 | - $user->blocked = 0; |
|
202 | - $user->save(); |
|
203 | - |
|
204 | - return $user; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Send a reset link to the given user. |
|
209 | - * |
|
210 | - * @param string $email |
|
211 | - * @return void |
|
212 | - */ |
|
213 | - public function sendReset($email) |
|
214 | - { |
|
215 | - if (! $user = $this->model->where('email', $email)->first()) { |
|
216 | - \ErrorHandler::notFound('email'); |
|
217 | - } |
|
218 | - |
|
219 | - $token = \Password::getRepository()->create($user); |
|
220 | - \Core::notifications()->notify($user, 'ResetPassword', $token); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Reset the given user's password. |
|
225 | - * |
|
226 | - * @param string $email |
|
227 | - * @param string $password |
|
228 | - * @param string $passwordConfirmation |
|
229 | - * @param string $token |
|
230 | - * @return string|void |
|
231 | - */ |
|
232 | - public function resetPassword($email, $password, $passwordConfirmation, $token) |
|
233 | - { |
|
234 | - $response = \Password::reset([ |
|
235 | - 'email' => $email, |
|
236 | - 'password' => $password, |
|
237 | - 'password_confirmation' => $passwordConfirmation, |
|
238 | - 'token' => $token |
|
239 | - ], function ($user, $password) { |
|
240 | - $user->password = $password; |
|
241 | - $user->save(); |
|
242 | - }); |
|
243 | - |
|
244 | - switch ($response) { |
|
245 | - case \Password::PASSWORD_RESET: |
|
246 | - return 'success'; |
|
247 | - |
|
248 | - case \Password::INVALID_TOKEN: |
|
249 | - \ErrorHandler::invalidResetToken('token'); |
|
250 | - //no break |
|
251 | - |
|
252 | - case \Password::INVALID_PASSWORD: |
|
253 | - \ErrorHandler::invalidResetPassword('email'); |
|
254 | - //no break |
|
255 | - |
|
256 | - case \Password::INVALID_USER: |
|
257 | - \ErrorHandler::notFound('user'); |
|
258 | - //no break |
|
259 | - |
|
260 | - default: |
|
261 | - \ErrorHandler::generalError(); |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Change the logged in user password. |
|
267 | - * |
|
268 | - * @param string $password |
|
269 | - * @param string $oldPassword |
|
270 | - * @return void |
|
271 | - */ |
|
272 | - public function changePassword($password, $oldPassword) |
|
273 | - { |
|
274 | - $user = \Auth::user(); |
|
275 | - if (! \Hash::check($oldPassword, $user->password)) { |
|
276 | - \ErrorHandler::invalidOldPassword(); |
|
277 | - } |
|
278 | - |
|
279 | - $user->password = $password; |
|
280 | - $user->save(); |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Confirm email using the confirmation code. |
|
285 | - * |
|
286 | - * @param string $confirmationCode |
|
287 | - * @return void |
|
288 | - */ |
|
289 | - public function confirmEmail($confirmationCode) |
|
290 | - { |
|
291 | - if (! $user = $this->first(['confirmation_code' => $confirmationCode])) { |
|
292 | - \ErrorHandler::invalidConfirmationCode(); |
|
293 | - } |
|
294 | - |
|
295 | - $user->confirmed = 1; |
|
296 | - $user->confirmation_code = null; |
|
297 | - $user->save(); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Send the confirmation mail. |
|
302 | - * |
|
303 | - * @param string $email |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - public function sendConfirmationEmail($email) |
|
307 | - { |
|
308 | - $user = $this->first(['email' => $email]); |
|
309 | - if ($user->confirmed) { |
|
310 | - \ErrorHandler::emailAlreadyConfirmed(); |
|
311 | - } |
|
312 | - |
|
313 | - $user->confirmed = 0; |
|
314 | - $user->confirmation_code = sha1(microtime()); |
|
315 | - $user->save(); |
|
316 | - \Core::notifications()->notify($user, 'ConfirmEmail'); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Paginate all users in the given role based on the given conditions. |
|
321 | - * |
|
322 | - * @param string $roleName |
|
323 | - * @param array $relations |
|
324 | - * @param integer $perPage |
|
325 | - * @param string $sortBy |
|
326 | - * @param boolean $desc |
|
327 | - * @return \Illuminate\Http\Response |
|
328 | - */ |
|
329 | - public function role($conditions, $roleName, $relations, $perPage, $sortBy, $desc) |
|
330 | - { |
|
331 | - unset($conditions['page']); |
|
332 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
333 | - $sort = $desc ? 'desc' : 'asc'; |
|
334 | - $model = $this->model->with($relations); |
|
335 | - |
|
336 | - $model->whereHas('roles', function ($q) use ($roleName) { |
|
337 | - $q->where('name', $roleName); |
|
338 | - }); |
|
185 | + return $user; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Unblock the user. |
|
190 | + * |
|
191 | + * @param integer $userId |
|
192 | + * @return object |
|
193 | + */ |
|
194 | + public function unblock($userId) |
|
195 | + { |
|
196 | + if (! $this->hasRole(['Admin'])) { |
|
197 | + \ErrorHandler::noPermissions(); |
|
198 | + } |
|
199 | + |
|
200 | + $user = $this->find($userId); |
|
201 | + $user->blocked = 0; |
|
202 | + $user->save(); |
|
203 | + |
|
204 | + return $user; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Send a reset link to the given user. |
|
209 | + * |
|
210 | + * @param string $email |
|
211 | + * @return void |
|
212 | + */ |
|
213 | + public function sendReset($email) |
|
214 | + { |
|
215 | + if (! $user = $this->model->where('email', $email)->first()) { |
|
216 | + \ErrorHandler::notFound('email'); |
|
217 | + } |
|
218 | + |
|
219 | + $token = \Password::getRepository()->create($user); |
|
220 | + \Core::notifications()->notify($user, 'ResetPassword', $token); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Reset the given user's password. |
|
225 | + * |
|
226 | + * @param string $email |
|
227 | + * @param string $password |
|
228 | + * @param string $passwordConfirmation |
|
229 | + * @param string $token |
|
230 | + * @return string|void |
|
231 | + */ |
|
232 | + public function resetPassword($email, $password, $passwordConfirmation, $token) |
|
233 | + { |
|
234 | + $response = \Password::reset([ |
|
235 | + 'email' => $email, |
|
236 | + 'password' => $password, |
|
237 | + 'password_confirmation' => $passwordConfirmation, |
|
238 | + 'token' => $token |
|
239 | + ], function ($user, $password) { |
|
240 | + $user->password = $password; |
|
241 | + $user->save(); |
|
242 | + }); |
|
243 | + |
|
244 | + switch ($response) { |
|
245 | + case \Password::PASSWORD_RESET: |
|
246 | + return 'success'; |
|
247 | + |
|
248 | + case \Password::INVALID_TOKEN: |
|
249 | + \ErrorHandler::invalidResetToken('token'); |
|
250 | + //no break |
|
251 | + |
|
252 | + case \Password::INVALID_PASSWORD: |
|
253 | + \ErrorHandler::invalidResetPassword('email'); |
|
254 | + //no break |
|
255 | + |
|
256 | + case \Password::INVALID_USER: |
|
257 | + \ErrorHandler::notFound('user'); |
|
258 | + //no break |
|
259 | + |
|
260 | + default: |
|
261 | + \ErrorHandler::generalError(); |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Change the logged in user password. |
|
267 | + * |
|
268 | + * @param string $password |
|
269 | + * @param string $oldPassword |
|
270 | + * @return void |
|
271 | + */ |
|
272 | + public function changePassword($password, $oldPassword) |
|
273 | + { |
|
274 | + $user = \Auth::user(); |
|
275 | + if (! \Hash::check($oldPassword, $user->password)) { |
|
276 | + \ErrorHandler::invalidOldPassword(); |
|
277 | + } |
|
278 | + |
|
279 | + $user->password = $password; |
|
280 | + $user->save(); |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Confirm email using the confirmation code. |
|
285 | + * |
|
286 | + * @param string $confirmationCode |
|
287 | + * @return void |
|
288 | + */ |
|
289 | + public function confirmEmail($confirmationCode) |
|
290 | + { |
|
291 | + if (! $user = $this->first(['confirmation_code' => $confirmationCode])) { |
|
292 | + \ErrorHandler::invalidConfirmationCode(); |
|
293 | + } |
|
294 | + |
|
295 | + $user->confirmed = 1; |
|
296 | + $user->confirmation_code = null; |
|
297 | + $user->save(); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Send the confirmation mail. |
|
302 | + * |
|
303 | + * @param string $email |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + public function sendConfirmationEmail($email) |
|
307 | + { |
|
308 | + $user = $this->first(['email' => $email]); |
|
309 | + if ($user->confirmed) { |
|
310 | + \ErrorHandler::emailAlreadyConfirmed(); |
|
311 | + } |
|
312 | + |
|
313 | + $user->confirmed = 0; |
|
314 | + $user->confirmation_code = sha1(microtime()); |
|
315 | + $user->save(); |
|
316 | + \Core::notifications()->notify($user, 'ConfirmEmail'); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Paginate all users in the given role based on the given conditions. |
|
321 | + * |
|
322 | + * @param string $roleName |
|
323 | + * @param array $relations |
|
324 | + * @param integer $perPage |
|
325 | + * @param string $sortBy |
|
326 | + * @param boolean $desc |
|
327 | + * @return \Illuminate\Http\Response |
|
328 | + */ |
|
329 | + public function role($conditions, $roleName, $relations, $perPage, $sortBy, $desc) |
|
330 | + { |
|
331 | + unset($conditions['page']); |
|
332 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
333 | + $sort = $desc ? 'desc' : 'asc'; |
|
334 | + $model = $this->model->with($relations); |
|
335 | + |
|
336 | + $model->whereHas('roles', function ($q) use ($roleName) { |
|
337 | + $q->where('name', $roleName); |
|
338 | + }); |
|
339 | 339 | |
340 | 340 | |
341 | - if (count($conditions['conditionValues'])) { |
|
342 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
343 | - } |
|
344 | - |
|
345 | - if ($perPage) { |
|
346 | - return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
347 | - } |
|
348 | - |
|
349 | - return $model->orderBy($sortBy, $sort)->get(); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Save the given data to the logged in user. |
|
354 | - * |
|
355 | - * @param array $data |
|
356 | - * @return void |
|
357 | - */ |
|
358 | - public function saveProfile($data) |
|
359 | - { |
|
360 | - if (Arr::has($data, 'profile_picture')) { |
|
361 | - $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures'); |
|
362 | - } |
|
341 | + if (count($conditions['conditionValues'])) { |
|
342 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
343 | + } |
|
344 | + |
|
345 | + if ($perPage) { |
|
346 | + return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
347 | + } |
|
348 | + |
|
349 | + return $model->orderBy($sortBy, $sort)->get(); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Save the given data to the logged in user. |
|
354 | + * |
|
355 | + * @param array $data |
|
356 | + * @return void |
|
357 | + */ |
|
358 | + public function saveProfile($data) |
|
359 | + { |
|
360 | + if (Arr::has($data, 'profile_picture')) { |
|
361 | + $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures'); |
|
362 | + } |
|
363 | 363 | |
364 | - $data['id'] = \Auth::id(); |
|
365 | - return $this->save($data); |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Ensure access token hasn't expired or revoked. |
|
370 | - * |
|
371 | - * @param string $accessToken |
|
372 | - * @return boolean |
|
373 | - */ |
|
374 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
375 | - { |
|
376 | - $accessTokenId = json_decode($accessToken, true)['id']; |
|
377 | - $accessToken = \DB::table('oauth_access_tokens') |
|
378 | - ->where('id', $accessTokenId) |
|
379 | - ->first(); |
|
364 | + $data['id'] = \Auth::id(); |
|
365 | + return $this->save($data); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Ensure access token hasn't expired or revoked. |
|
370 | + * |
|
371 | + * @param string $accessToken |
|
372 | + * @return boolean |
|
373 | + */ |
|
374 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
375 | + { |
|
376 | + $accessTokenId = json_decode($accessToken, true)['id']; |
|
377 | + $accessToken = \DB::table('oauth_access_tokens') |
|
378 | + ->where('id', $accessTokenId) |
|
379 | + ->first(); |
|
380 | 380 | |
381 | - if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) { |
|
382 | - return true; |
|
383 | - } |
|
384 | - |
|
385 | - return false; |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Revoke the given access token and all |
|
390 | - * associated refresh tokens. |
|
391 | - * |
|
392 | - * @param oject $accessToken |
|
393 | - * @return void |
|
394 | - */ |
|
395 | - public function revokeAccessToken($accessToken) |
|
396 | - { |
|
397 | - \DB::table('oauth_refresh_tokens') |
|
398 | - ->where('access_token_id', $accessToken->id) |
|
399 | - ->update([ |
|
400 | - 'revoked' => true |
|
401 | - ]); |
|
402 | - |
|
403 | - $accessToken->revoke(); |
|
404 | - } |
|
381 | + if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) { |
|
382 | + return true; |
|
383 | + } |
|
384 | + |
|
385 | + return false; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Revoke the given access token and all |
|
390 | + * associated refresh tokens. |
|
391 | + * |
|
392 | + * @param oject $accessToken |
|
393 | + * @return void |
|
394 | + */ |
|
395 | + public function revokeAccessToken($accessToken) |
|
396 | + { |
|
397 | + \DB::table('oauth_refresh_tokens') |
|
398 | + ->where('access_token_id', $accessToken->id) |
|
399 | + ->update([ |
|
400 | + 'revoked' => true |
|
401 | + ]); |
|
402 | + |
|
403 | + $accessToken->revoke(); |
|
404 | + } |
|
405 | 405 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $permissions = []; |
29 | 29 | $user = $this->find(\Auth::id(), $relations); |
30 | 30 | foreach ($user->roles()->get() as $role) { |
31 | - $role->permissions->each(function ($permission) use (&$permissions) { |
|
31 | + $role->permissions->each(function($permission) use (&$permissions) { |
|
32 | 32 | $permissions[$permission->model][$permission->id] = $permission->name; |
33 | 33 | }); |
34 | 34 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $user = $user ?: $this->find(\Auth::id(), ['roles.permissions']); |
52 | 52 | $permissions = []; |
53 | 53 | |
54 | - $user->roles->pluck('permissions')->each(function ($permission) use (&$permissions, $model) { |
|
54 | + $user->roles->pluck('permissions')->each(function($permission) use (&$permissions, $model) { |
|
55 | 55 | $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
56 | 56 | }); |
57 | 57 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function assignRoles($userId, $roleIds) |
82 | 82 | { |
83 | - \DB::transaction(function () use ($userId, $roleIds) { |
|
83 | + \DB::transaction(function() use ($userId, $roleIds) { |
|
84 | 84 | $user = $this->find($userId); |
85 | 85 | $user->roles()->detach(); |
86 | 86 | $user->roles()->attach($roleIds); |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function login($credentials, $adminLogin = false) |
101 | 101 | { |
102 | - if (! $user = $this->first(['email' => $credentials['email']])) { |
|
102 | + if ( ! $user = $this->first(['email' => $credentials['email']])) { |
|
103 | 103 | \ErrorHandler::loginFailed(); |
104 | 104 | } elseif ($adminLogin && ! $user->roles->whereIn('name', ['Admin'])->count()) { |
105 | 105 | \ErrorHandler::loginFailed(); |
106 | - } elseif (! $adminLogin && $user->roles->whereIn('name', ['Admin'])->count()) { |
|
106 | + } elseif ( ! $adminLogin && $user->roles->whereIn('name', ['Admin'])->count()) { |
|
107 | 107 | \ErrorHandler::loginFailed(); |
108 | 108 | } elseif ($user->blocked) { |
109 | 109 | \ErrorHandler::userIsBlocked(); |
110 | - } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
110 | + } elseif ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
111 | 111 | \ErrorHandler::emailNotConfirmed(); |
112 | 112 | } |
113 | 113 | |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
128 | 128 | $user = \Socialite::driver($type)->userFromToken($access_token); |
129 | 129 | |
130 | - if (! $user->email) { |
|
130 | + if ( ! $user->email) { |
|
131 | 131 | \ErrorHandler::noSocialEmail(); |
132 | 132 | } |
133 | 133 | |
134 | - if (! $this->model->where('email', $user->email)->first()) { |
|
134 | + if ( ! $this->model->where('email', $user->email)->first()) { |
|
135 | 135 | $this->register(['email' => $user->email, 'password' => ''], true); |
136 | 136 | } |
137 | 137 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | if ($skipConfirmEmail) { |
154 | 154 | $user->confirmed = 1; |
155 | 155 | $user->save(); |
156 | - } elseif (! config('skeleton.disable_confirm_email')) { |
|
156 | + } elseif ( ! config('skeleton.disable_confirm_email')) { |
|
157 | 157 | $this->sendConfirmationEmail($user->email); |
158 | 158 | } |
159 | 159 | |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function block($userId) |
170 | 170 | { |
171 | - if (! $user = $this->find($userId)) { |
|
171 | + if ( ! $user = $this->find($userId)) { |
|
172 | 172 | \ErrorHandler::notFound('user'); |
173 | 173 | } |
174 | - if (! $this->hasRole(['Admin'])) { |
|
174 | + if ( ! $this->hasRole(['Admin'])) { |
|
175 | 175 | \ErrorHandler::noPermissions(); |
176 | 176 | } elseif (\Auth::id() == $userId) { |
177 | 177 | \ErrorHandler::noPermissions(); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function unblock($userId) |
195 | 195 | { |
196 | - if (! $this->hasRole(['Admin'])) { |
|
196 | + if ( ! $this->hasRole(['Admin'])) { |
|
197 | 197 | \ErrorHandler::noPermissions(); |
198 | 198 | } |
199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function sendReset($email) |
214 | 214 | { |
215 | - if (! $user = $this->model->where('email', $email)->first()) { |
|
215 | + if ( ! $user = $this->model->where('email', $email)->first()) { |
|
216 | 216 | \ErrorHandler::notFound('email'); |
217 | 217 | } |
218 | 218 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | 'password' => $password, |
237 | 237 | 'password_confirmation' => $passwordConfirmation, |
238 | 238 | 'token' => $token |
239 | - ], function ($user, $password) { |
|
239 | + ], function($user, $password) { |
|
240 | 240 | $user->password = $password; |
241 | 241 | $user->save(); |
242 | 242 | }); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | public function changePassword($password, $oldPassword) |
273 | 273 | { |
274 | 274 | $user = \Auth::user(); |
275 | - if (! \Hash::check($oldPassword, $user->password)) { |
|
275 | + if ( ! \Hash::check($oldPassword, $user->password)) { |
|
276 | 276 | \ErrorHandler::invalidOldPassword(); |
277 | 277 | } |
278 | 278 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | public function confirmEmail($confirmationCode) |
290 | 290 | { |
291 | - if (! $user = $this->first(['confirmation_code' => $confirmationCode])) { |
|
291 | + if ( ! $user = $this->first(['confirmation_code' => $confirmationCode])) { |
|
292 | 292 | \ErrorHandler::invalidConfirmationCode(); |
293 | 293 | } |
294 | 294 | |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $sort = $desc ? 'desc' : 'asc'; |
334 | 334 | $model = $this->model->with($relations); |
335 | 335 | |
336 | - $model->whereHas('roles', function ($q) use ($roleName) { |
|
336 | + $model->whereHas('roles', function($q) use ($roleName) { |
|
337 | 337 | $q->where('name', $roleName); |
338 | 338 | }); |
339 | 339 |
@@ -24,239 +24,239 @@ |
||
24 | 24 | |
25 | 25 | class UserController extends BaseApiController |
26 | 26 | { |
27 | - /** |
|
28 | - * List of all route actions that the base api controller |
|
29 | - * will skip permissions check for them. |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile']; |
|
27 | + /** |
|
28 | + * List of all route actions that the base api controller |
|
29 | + * will skip permissions check for them. |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile']; |
|
33 | 33 | |
34 | - /** |
|
35 | - * List of all route actions that the base api controller |
|
36 | - * will skip login check for them. |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation']; |
|
34 | + /** |
|
35 | + * List of all route actions that the base api controller |
|
36 | + * will skip login check for them. |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation']; |
|
40 | 40 | |
41 | - /** |
|
42 | - * The loginProxy implementation. |
|
43 | - * |
|
44 | - * @var App\Modules\Users\Proxy\LoginProxy |
|
45 | - */ |
|
46 | - protected $loginProxy; |
|
41 | + /** |
|
42 | + * The loginProxy implementation. |
|
43 | + * |
|
44 | + * @var App\Modules\Users\Proxy\LoginProxy |
|
45 | + */ |
|
46 | + protected $loginProxy; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Init new object. |
|
50 | - * |
|
51 | - * @param LoginProxy $loginProxy |
|
52 | - * @param UserRepository $repo |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function __construct(LoginProxy $loginProxy, UserRepository $repo) |
|
56 | - { |
|
57 | - $this->loginProxy = $loginProxy; |
|
58 | - parent::__construct($repo, 'App\Modules\Users\Http\Resources\AclUser'); |
|
59 | - } |
|
48 | + /** |
|
49 | + * Init new object. |
|
50 | + * |
|
51 | + * @param LoginProxy $loginProxy |
|
52 | + * @param UserRepository $repo |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function __construct(LoginProxy $loginProxy, UserRepository $repo) |
|
56 | + { |
|
57 | + $this->loginProxy = $loginProxy; |
|
58 | + parent::__construct($repo, 'App\Modules\Users\Http\Resources\AclUser'); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Insert the given model to storage. |
|
63 | - * |
|
64 | - * @param InsertUser $request |
|
65 | - * @return \Illuminate\Http\Response |
|
66 | - */ |
|
67 | - public function insert(InsertUser $request) |
|
68 | - { |
|
69 | - return new $this->modelResource($this->repo->save($request->all())); |
|
70 | - } |
|
61 | + /** |
|
62 | + * Insert the given model to storage. |
|
63 | + * |
|
64 | + * @param InsertUser $request |
|
65 | + * @return \Illuminate\Http\Response |
|
66 | + */ |
|
67 | + public function insert(InsertUser $request) |
|
68 | + { |
|
69 | + return new $this->modelResource($this->repo->save($request->all())); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Update the given model to storage. |
|
74 | - * |
|
75 | - * @param UpdateUser $request |
|
76 | - * @return \Illuminate\Http\Response |
|
77 | - */ |
|
78 | - public function update(UpdateUser $request) |
|
79 | - { |
|
80 | - return new $this->modelResource($this->repo->save($request->all())); |
|
81 | - } |
|
72 | + /** |
|
73 | + * Update the given model to storage. |
|
74 | + * |
|
75 | + * @param UpdateUser $request |
|
76 | + * @return \Illuminate\Http\Response |
|
77 | + */ |
|
78 | + public function update(UpdateUser $request) |
|
79 | + { |
|
80 | + return new $this->modelResource($this->repo->save($request->all())); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Return the logged in user account. |
|
85 | - * |
|
86 | - * @param Request $request |
|
87 | - * @return \Illuminate\Http\Response |
|
88 | - */ |
|
89 | - public function account(Request $request) |
|
90 | - { |
|
91 | - return new $this->modelResource($this->repo->account($request->relations)); |
|
92 | - } |
|
83 | + /** |
|
84 | + * Return the logged in user account. |
|
85 | + * |
|
86 | + * @param Request $request |
|
87 | + * @return \Illuminate\Http\Response |
|
88 | + */ |
|
89 | + public function account(Request $request) |
|
90 | + { |
|
91 | + return new $this->modelResource($this->repo->account($request->relations)); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Block the user. |
|
96 | - * |
|
97 | - * @param integer $id Id of the user. |
|
98 | - * @return \Illuminate\Http\Response |
|
99 | - */ |
|
100 | - public function block($id) |
|
101 | - { |
|
102 | - return new $this->modelResource($this->repo->block($id)); |
|
103 | - } |
|
94 | + /** |
|
95 | + * Block the user. |
|
96 | + * |
|
97 | + * @param integer $id Id of the user. |
|
98 | + * @return \Illuminate\Http\Response |
|
99 | + */ |
|
100 | + public function block($id) |
|
101 | + { |
|
102 | + return new $this->modelResource($this->repo->block($id)); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Unblock the user. |
|
107 | - * |
|
108 | - * @param integer $id Id of the user. |
|
109 | - * @return \Illuminate\Http\Response |
|
110 | - */ |
|
111 | - public function unblock($id) |
|
112 | - { |
|
113 | - return new $this->modelResource($this->repo->unblock($id)); |
|
114 | - } |
|
105 | + /** |
|
106 | + * Unblock the user. |
|
107 | + * |
|
108 | + * @param integer $id Id of the user. |
|
109 | + * @return \Illuminate\Http\Response |
|
110 | + */ |
|
111 | + public function unblock($id) |
|
112 | + { |
|
113 | + return new $this->modelResource($this->repo->unblock($id)); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Logout the user. |
|
118 | - * |
|
119 | - * @return \Illuminate\Http\Response |
|
120 | - */ |
|
121 | - public function logout() |
|
122 | - { |
|
123 | - return new GeneralResource($this->loginProxy->logout()); |
|
124 | - } |
|
116 | + /** |
|
117 | + * Logout the user. |
|
118 | + * |
|
119 | + * @return \Illuminate\Http\Response |
|
120 | + */ |
|
121 | + public function logout() |
|
122 | + { |
|
123 | + return new GeneralResource($this->loginProxy->logout()); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Handle a registration request. |
|
128 | - * |
|
129 | - * @param Register $request |
|
130 | - * @return \Illuminate\Http\Response |
|
131 | - */ |
|
132 | - public function register(Register $request) |
|
133 | - { |
|
134 | - return new $this->modelResource($this->repo->register($request->only('name', 'email', 'password'))); |
|
135 | - } |
|
126 | + /** |
|
127 | + * Handle a registration request. |
|
128 | + * |
|
129 | + * @param Register $request |
|
130 | + * @return \Illuminate\Http\Response |
|
131 | + */ |
|
132 | + public function register(Register $request) |
|
133 | + { |
|
134 | + return new $this->modelResource($this->repo->register($request->only('name', 'email', 'password'))); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Handle a login request to the application. |
|
139 | - * |
|
140 | - * @param Login $request |
|
141 | - * @return \Illuminate\Http\Response |
|
142 | - */ |
|
143 | - public function login(Login $request) |
|
144 | - { |
|
145 | - $result = $this->loginProxy->login($request->only('email', 'password'), $request->get('admin')); |
|
137 | + /** |
|
138 | + * Handle a login request to the application. |
|
139 | + * |
|
140 | + * @param Login $request |
|
141 | + * @return \Illuminate\Http\Response |
|
142 | + */ |
|
143 | + public function login(Login $request) |
|
144 | + { |
|
145 | + $result = $this->loginProxy->login($request->only('email', 'password'), $request->get('admin')); |
|
146 | 146 | |
147 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
148 | - } |
|
147 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Handle a social login request of the none admin to the application. |
|
152 | - * |
|
153 | - * @param LoginSocial $request |
|
154 | - * @return \Illuminate\Http\Response |
|
155 | - */ |
|
156 | - public function loginSocial(LoginSocial $request) |
|
157 | - { |
|
158 | - $result = $this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
150 | + /** |
|
151 | + * Handle a social login request of the none admin to the application. |
|
152 | + * |
|
153 | + * @param LoginSocial $request |
|
154 | + * @return \Illuminate\Http\Response |
|
155 | + */ |
|
156 | + public function loginSocial(LoginSocial $request) |
|
157 | + { |
|
158 | + $result = $this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
159 | 159 | |
160 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
161 | - } |
|
160 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Assign the given roles to the given user. |
|
165 | - * |
|
166 | - * @param AssignRoles $request |
|
167 | - * @return \Illuminate\Http\Response |
|
168 | - */ |
|
169 | - public function assignRoles(AssignRoles $request) |
|
170 | - { |
|
171 | - return new $this->modelResource($this->repo->assignRoles($request->get('user_id'), $request->get('role_ids'))); |
|
172 | - } |
|
163 | + /** |
|
164 | + * Assign the given roles to the given user. |
|
165 | + * |
|
166 | + * @param AssignRoles $request |
|
167 | + * @return \Illuminate\Http\Response |
|
168 | + */ |
|
169 | + public function assignRoles(AssignRoles $request) |
|
170 | + { |
|
171 | + return new $this->modelResource($this->repo->assignRoles($request->get('user_id'), $request->get('role_ids'))); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Send a reset link to the given user. |
|
176 | - * |
|
177 | - * @param SendReset $request |
|
178 | - * @return \Illuminate\Http\Response |
|
179 | - */ |
|
180 | - public function sendReset(SendReset $request) |
|
181 | - { |
|
182 | - return new GeneralResource($this->repo->sendReset($request->get('email'))); |
|
183 | - } |
|
174 | + /** |
|
175 | + * Send a reset link to the given user. |
|
176 | + * |
|
177 | + * @param SendReset $request |
|
178 | + * @return \Illuminate\Http\Response |
|
179 | + */ |
|
180 | + public function sendReset(SendReset $request) |
|
181 | + { |
|
182 | + return new GeneralResource($this->repo->sendReset($request->get('email'))); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Reset the given user's password. |
|
187 | - * |
|
188 | - * @param ResetPassword $request |
|
189 | - * @return \Illuminate\Http\Response |
|
190 | - */ |
|
191 | - public function resetPassword(ResetPassword $request) |
|
192 | - { |
|
193 | - return new GeneralResource($this->repo->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token'))); |
|
194 | - } |
|
185 | + /** |
|
186 | + * Reset the given user's password. |
|
187 | + * |
|
188 | + * @param ResetPassword $request |
|
189 | + * @return \Illuminate\Http\Response |
|
190 | + */ |
|
191 | + public function resetPassword(ResetPassword $request) |
|
192 | + { |
|
193 | + return new GeneralResource($this->repo->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token'))); |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Change the logged in user password. |
|
198 | - * |
|
199 | - * @param ChangePassword $request |
|
200 | - * @return \Illuminate\Http\Response |
|
201 | - */ |
|
202 | - public function changePassword(ChangePassword $request) |
|
203 | - { |
|
204 | - return new GeneralResource($this->repo->changePassword($request->get('password') , $request->get('old_password'))); |
|
205 | - } |
|
196 | + /** |
|
197 | + * Change the logged in user password. |
|
198 | + * |
|
199 | + * @param ChangePassword $request |
|
200 | + * @return \Illuminate\Http\Response |
|
201 | + */ |
|
202 | + public function changePassword(ChangePassword $request) |
|
203 | + { |
|
204 | + return new GeneralResource($this->repo->changePassword($request->get('password') , $request->get('old_password'))); |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Confirm email using the confirmation code. |
|
209 | - * |
|
210 | - * @param ConfirmEmail $request |
|
211 | - * @return \Illuminate\Http\Response |
|
212 | - */ |
|
213 | - public function confirmEmail(ConfirmEmail $request) |
|
214 | - { |
|
215 | - return new GeneralResource($this->repo->confirmEmail($request->only('confirmation_code'))); |
|
216 | - } |
|
207 | + /** |
|
208 | + * Confirm email using the confirmation code. |
|
209 | + * |
|
210 | + * @param ConfirmEmail $request |
|
211 | + * @return \Illuminate\Http\Response |
|
212 | + */ |
|
213 | + public function confirmEmail(ConfirmEmail $request) |
|
214 | + { |
|
215 | + return new GeneralResource($this->repo->confirmEmail($request->only('confirmation_code'))); |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * Resend the email confirmation mail. |
|
220 | - * |
|
221 | - * @param ResendEmailConfirmation $request |
|
222 | - * @return \Illuminate\Http\Response |
|
223 | - */ |
|
224 | - public function resendEmailConfirmation(ResendEmailConfirmation $request) |
|
225 | - { |
|
226 | - return new GeneralResource($this->repo->sendConfirmationEmail($request->get('email'))); |
|
227 | - } |
|
218 | + /** |
|
219 | + * Resend the email confirmation mail. |
|
220 | + * |
|
221 | + * @param ResendEmailConfirmation $request |
|
222 | + * @return \Illuminate\Http\Response |
|
223 | + */ |
|
224 | + public function resendEmailConfirmation(ResendEmailConfirmation $request) |
|
225 | + { |
|
226 | + return new GeneralResource($this->repo->sendConfirmationEmail($request->get('email'))); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Refresh the expired login token. |
|
231 | - * |
|
232 | - * @param RefreshToken $request |
|
233 | - * @return \Illuminate\Http\Response |
|
234 | - */ |
|
235 | - public function refreshToken(RefreshToken $request) |
|
236 | - { |
|
237 | - return new GeneralResource($this->loginProxy->refreshToken($request->get('refresh_token'))); |
|
238 | - } |
|
229 | + /** |
|
230 | + * Refresh the expired login token. |
|
231 | + * |
|
232 | + * @param RefreshToken $request |
|
233 | + * @return \Illuminate\Http\Response |
|
234 | + */ |
|
235 | + public function refreshToken(RefreshToken $request) |
|
236 | + { |
|
237 | + return new GeneralResource($this->loginProxy->refreshToken($request->get('refresh_token'))); |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * Paginate all users with in the given role. |
|
242 | - * |
|
243 | - * @param Request $request |
|
244 | - * @param string $roleName The name of the requested role. |
|
245 | - * @return \Illuminate\Http\Response |
|
246 | - */ |
|
247 | - public function role(Request $request, $roleName) |
|
248 | - { |
|
249 | - return $this->modelResource::collection($this->repo->role($request->all(), $roleName, $request->relations, $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
250 | - } |
|
240 | + /** |
|
241 | + * Paginate all users with in the given role. |
|
242 | + * |
|
243 | + * @param Request $request |
|
244 | + * @param string $roleName The name of the requested role. |
|
245 | + * @return \Illuminate\Http\Response |
|
246 | + */ |
|
247 | + public function role(Request $request, $roleName) |
|
248 | + { |
|
249 | + return $this->modelResource::collection($this->repo->role($request->all(), $roleName, $request->relations, $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * Save the given data to the logged in user. |
|
254 | - * |
|
255 | - * @param SaveProfile $request |
|
256 | - * @return \Illuminate\Http\Response |
|
257 | - */ |
|
258 | - public function saveProfile(SaveProfile $request) |
|
259 | - { |
|
260 | - return new $this->modelResource($this->repo->saveProfile($request->only('name', 'email', 'profile_picture'))); |
|
261 | - } |
|
252 | + /** |
|
253 | + * Save the given data to the logged in user. |
|
254 | + * |
|
255 | + * @param SaveProfile $request |
|
256 | + * @return \Illuminate\Http\Response |
|
257 | + */ |
|
258 | + public function saveProfile(SaveProfile $request) |
|
259 | + { |
|
260 | + return new $this->modelResource($this->repo->saveProfile($request->only('name', 'email', 'profile_picture'))); |
|
261 | + } |
|
262 | 262 | } |
@@ -201,7 +201,7 @@ |
||
201 | 201 | */ |
202 | 202 | public function changePassword(ChangePassword $request) |
203 | 203 | { |
204 | - return new GeneralResource($this->repo->changePassword($request->get('password') , $request->get('old_password'))); |
|
204 | + return new GeneralResource($this->repo->changePassword($request->get('password'), $request->get('old_password'))); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -2,107 +2,107 @@ |
||
2 | 2 | |
3 | 3 | interface BaseRepositoryInterface |
4 | 4 | { |
5 | - /** |
|
6 | - * Fetch all records with relations from the storage. |
|
7 | - * |
|
8 | - * @param array $relations |
|
9 | - * @param array $sortBy |
|
10 | - * @param array $desc |
|
11 | - * @param array $columns |
|
12 | - * @return collection |
|
13 | - */ |
|
14 | - public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
5 | + /** |
|
6 | + * Fetch all records with relations from the storage. |
|
7 | + * |
|
8 | + * @param array $relations |
|
9 | + * @param array $sortBy |
|
10 | + * @param array $desc |
|
11 | + * @param array $columns |
|
12 | + * @return collection |
|
13 | + */ |
|
14 | + public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
15 | 15 | |
16 | - /** |
|
17 | - * Fetch all records with relations from storage in pages |
|
18 | - * that matche the given query. |
|
19 | - * |
|
20 | - * @param string $query |
|
21 | - * @param integer $perPage |
|
22 | - * @param array $relations |
|
23 | - * @param array $sortBy |
|
24 | - * @param array $desc |
|
25 | - * @param array $columns |
|
26 | - * @return collection |
|
27 | - */ |
|
28 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
16 | + /** |
|
17 | + * Fetch all records with relations from storage in pages |
|
18 | + * that matche the given query. |
|
19 | + * |
|
20 | + * @param string $query |
|
21 | + * @param integer $perPage |
|
22 | + * @param array $relations |
|
23 | + * @param array $sortBy |
|
24 | + * @param array $desc |
|
25 | + * @param array $columns |
|
26 | + * @return collection |
|
27 | + */ |
|
28 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
29 | 29 | |
30 | - /** |
|
31 | - * Fetch all records with relations from storage in pages. |
|
32 | - * |
|
33 | - * @param integer $perPage |
|
34 | - * @param array $relations |
|
35 | - * @param array $sortBy |
|
36 | - * @param array $desc |
|
37 | - * @param array $columns |
|
38 | - * @return collection |
|
39 | - */ |
|
40 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
30 | + /** |
|
31 | + * Fetch all records with relations from storage in pages. |
|
32 | + * |
|
33 | + * @param integer $perPage |
|
34 | + * @param array $relations |
|
35 | + * @param array $sortBy |
|
36 | + * @param array $desc |
|
37 | + * @param array $columns |
|
38 | + * @return collection |
|
39 | + */ |
|
40 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Fetch all records with relations based on |
|
44 | - * the given condition from storage in pages. |
|
45 | - * |
|
46 | - * @param array $conditions array of conditions |
|
47 | - * @param integer $perPage |
|
48 | - * @param array $relations |
|
49 | - * @param array $sortBy |
|
50 | - * @param array $desc |
|
51 | - * @param array $columns |
|
52 | - * @return collection |
|
53 | - */ |
|
54 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
42 | + /** |
|
43 | + * Fetch all records with relations based on |
|
44 | + * the given condition from storage in pages. |
|
45 | + * |
|
46 | + * @param array $conditions array of conditions |
|
47 | + * @param integer $perPage |
|
48 | + * @param array $relations |
|
49 | + * @param array $sortBy |
|
50 | + * @param array $desc |
|
51 | + * @param array $columns |
|
52 | + * @return collection |
|
53 | + */ |
|
54 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Save the given model/models to the storage. |
|
58 | - * |
|
59 | - * @param array $data |
|
60 | - * @return mixed |
|
61 | - */ |
|
62 | - public function save(array $data); |
|
56 | + /** |
|
57 | + * Save the given model/models to the storage. |
|
58 | + * |
|
59 | + * @param array $data |
|
60 | + * @return mixed |
|
61 | + */ |
|
62 | + public function save(array $data); |
|
63 | 63 | |
64 | - /** |
|
65 | - * Delete record from the storage based on the given |
|
66 | - * condition. |
|
67 | - * |
|
68 | - * @param var $value condition value |
|
69 | - * @param string $attribute condition column name |
|
70 | - * @return integer affected rows |
|
71 | - */ |
|
72 | - public function delete($value, $attribute = 'id'); |
|
64 | + /** |
|
65 | + * Delete record from the storage based on the given |
|
66 | + * condition. |
|
67 | + * |
|
68 | + * @param var $value condition value |
|
69 | + * @param string $attribute condition column name |
|
70 | + * @return integer affected rows |
|
71 | + */ |
|
72 | + public function delete($value, $attribute = 'id'); |
|
73 | 73 | |
74 | - /** |
|
75 | - * Fetch records from the storage based on the given |
|
76 | - * id. |
|
77 | - * |
|
78 | - * @param integer $id |
|
79 | - * @param array $relations |
|
80 | - * @param array $columns |
|
81 | - * @return object |
|
82 | - */ |
|
83 | - public function find($id, $relations = [], $columns = array('*')); |
|
74 | + /** |
|
75 | + * Fetch records from the storage based on the given |
|
76 | + * id. |
|
77 | + * |
|
78 | + * @param integer $id |
|
79 | + * @param array $relations |
|
80 | + * @param array $columns |
|
81 | + * @return object |
|
82 | + */ |
|
83 | + public function find($id, $relations = [], $columns = array('*')); |
|
84 | 84 | |
85 | - /** |
|
86 | - * Fetch records from the storage based on the given |
|
87 | - * condition. |
|
88 | - * |
|
89 | - * @param array $conditions array of conditions |
|
90 | - * @param array $relations |
|
91 | - * @param array $sortBy |
|
92 | - * @param array $desc |
|
93 | - * @param array $columns |
|
94 | - * @return collection |
|
95 | - */ |
|
96 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
85 | + /** |
|
86 | + * Fetch records from the storage based on the given |
|
87 | + * condition. |
|
88 | + * |
|
89 | + * @param array $conditions array of conditions |
|
90 | + * @param array $relations |
|
91 | + * @param array $sortBy |
|
92 | + * @param array $desc |
|
93 | + * @param array $columns |
|
94 | + * @return collection |
|
95 | + */ |
|
96 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
97 | 97 | |
98 | - /** |
|
99 | - * Fetch the first record fro the storage based on the given |
|
100 | - * condition. |
|
101 | - * |
|
102 | - * @param array $conditions array of conditions |
|
103 | - * @param array $relations |
|
104 | - * @param array $columns |
|
105 | - * @return object |
|
106 | - */ |
|
107 | - public function first($conditions, $relations = [], $columns = array('*')); |
|
98 | + /** |
|
99 | + * Fetch the first record fro the storage based on the given |
|
100 | + * condition. |
|
101 | + * |
|
102 | + * @param array $conditions array of conditions |
|
103 | + * @param array $relations |
|
104 | + * @param array $columns |
|
105 | + * @return object |
|
106 | + */ |
|
107 | + public function first($conditions, $relations = [], $columns = array('*')); |
|
108 | 108 | } |