@@ -103,24 +103,19 @@ discard block |
||
103 | 103 | if ( ! $user = $this->first(['email' => $credentials['email']])) |
104 | 104 | { |
105 | 105 | \ErrorHandler::loginFailed(); |
106 | - } |
|
107 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
106 | + } else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
108 | 107 | { |
109 | 108 | \ErrorHandler::loginFailed(); |
110 | - } |
|
111 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
109 | + } else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
112 | 110 | { |
113 | 111 | \ErrorHandler::loginFailed(); |
114 | - } |
|
115 | - else if ($user->blocked) |
|
112 | + } else if ($user->blocked) |
|
116 | 113 | { |
117 | 114 | \ErrorHandler::userIsBlocked(); |
118 | - } |
|
119 | - else if ($token = \JWTAuth::attempt($credentials)) |
|
115 | + } else if ($token = \JWTAuth::attempt($credentials)) |
|
120 | 116 | { |
121 | 117 | return ['token' => $token]; |
122 | - } |
|
123 | - else |
|
118 | + } else |
|
124 | 119 | { |
125 | 120 | \ErrorHandler::loginFailed(); |
126 | 121 | } |
@@ -146,8 +141,7 @@ discard block |
||
146 | 141 | { |
147 | 142 | $data = ['email' => $user->email, 'password' => '']; |
148 | 143 | return $this->register($data); |
149 | - } |
|
150 | - else |
|
144 | + } else |
|
151 | 145 | { |
152 | 146 | if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
153 | 147 | { |
@@ -193,12 +187,10 @@ discard block |
||
193 | 187 | if ( ! $this->hasGroup('Admin')) |
194 | 188 | { |
195 | 189 | \ErrorHandler::noPermissions(); |
196 | - } |
|
197 | - else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
190 | + } else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
198 | 191 | { |
199 | 192 | \ErrorHandler::noPermissions(); |
200 | - } |
|
201 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
193 | + } else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
202 | 194 | { |
203 | 195 | \ErrorHandler::noPermissions(); |
204 | 196 | } |
@@ -4,364 +4,364 @@ |
||
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 | - * @param integer $userId |
|
69 | - * @return boolean |
|
70 | - */ |
|
71 | - public function hasGroup($groupName, $userId = fa;se) |
|
72 | - { |
|
73 | - $userId = $userId ?: \JWTAuth::parseToken()->authenticate()->id; |
|
74 | - $groups = $this->find($userId)->groups; |
|
75 | - return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Assign the given group ids to the given user. |
|
80 | - * |
|
81 | - * @param integer $user_id |
|
82 | - * @param array $group_ids |
|
83 | - * @return object |
|
84 | - */ |
|
85 | - public function assignGroups($user_id, $group_ids) |
|
86 | - { |
|
87 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
88 | - $user = $this->find($user_id); |
|
89 | - $user->groups()->detach(); |
|
90 | - $user->groups()->attach($group_ids); |
|
91 | - }); |
|
92 | - |
|
93 | - return $this->find($user_id); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Handle a login request to the application. |
|
98 | - * |
|
99 | - * @param array $credentials |
|
100 | - * @param boolean $adminLogin |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function login($credentials, $adminLogin = false) |
|
104 | - { |
|
105 | - if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
106 | - { |
|
107 | - \ErrorHandler::loginFailed(); |
|
108 | - } |
|
109 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
110 | - { |
|
111 | - \ErrorHandler::loginFailed(); |
|
112 | - } |
|
113 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
114 | - { |
|
115 | - \ErrorHandler::loginFailed(); |
|
116 | - } |
|
117 | - else if ($user->blocked) |
|
118 | - { |
|
119 | - \ErrorHandler::userIsBlocked(); |
|
120 | - } |
|
121 | - else if ($token = \JWTAuth::attempt($credentials)) |
|
122 | - { |
|
123 | - return ['token' => $token]; |
|
124 | - } |
|
125 | - else |
|
126 | - { |
|
127 | - \ErrorHandler::loginFailed(); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Handle a social login request of the none admin to the application. |
|
133 | - * |
|
134 | - * @param array $credentials |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function loginSocial($credentials) |
|
138 | - { |
|
139 | - $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
140 | - $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
141 | - |
|
142 | - if ( ! $user->email) |
|
143 | - { |
|
144 | - \ErrorHandler::noSocialEmail(); |
|
145 | - } |
|
146 | - |
|
147 | - if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
148 | - { |
|
149 | - $data = ['email' => $user->email, 'password' => '']; |
|
150 | - return $this->register($data); |
|
151 | - } |
|
152 | - else |
|
153 | - { |
|
154 | - if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
155 | - { |
|
156 | - \ErrorHandler::userAlreadyRegistered(); |
|
157 | - } |
|
158 | - return $this->login(['email' => $registeredUser->email, 'password' => ''], false); |
|
159 | - } |
|
160 | - } |
|
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 | + * @param integer $userId |
|
69 | + * @return boolean |
|
70 | + */ |
|
71 | + public function hasGroup($groupName, $userId = fa;se) |
|
72 | + { |
|
73 | + $userId = $userId ?: \JWTAuth::parseToken()->authenticate()->id; |
|
74 | + $groups = $this->find($userId)->groups; |
|
75 | + return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Assign the given group ids to the given user. |
|
80 | + * |
|
81 | + * @param integer $user_id |
|
82 | + * @param array $group_ids |
|
83 | + * @return object |
|
84 | + */ |
|
85 | + public function assignGroups($user_id, $group_ids) |
|
86 | + { |
|
87 | + \DB::transaction(function () use ($user_id, $group_ids) { |
|
88 | + $user = $this->find($user_id); |
|
89 | + $user->groups()->detach(); |
|
90 | + $user->groups()->attach($group_ids); |
|
91 | + }); |
|
92 | + |
|
93 | + return $this->find($user_id); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Handle a login request to the application. |
|
98 | + * |
|
99 | + * @param array $credentials |
|
100 | + * @param boolean $adminLogin |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function login($credentials, $adminLogin = false) |
|
104 | + { |
|
105 | + if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
106 | + { |
|
107 | + \ErrorHandler::loginFailed(); |
|
108 | + } |
|
109 | + else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
110 | + { |
|
111 | + \ErrorHandler::loginFailed(); |
|
112 | + } |
|
113 | + else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
114 | + { |
|
115 | + \ErrorHandler::loginFailed(); |
|
116 | + } |
|
117 | + else if ($user->blocked) |
|
118 | + { |
|
119 | + \ErrorHandler::userIsBlocked(); |
|
120 | + } |
|
121 | + else if ($token = \JWTAuth::attempt($credentials)) |
|
122 | + { |
|
123 | + return ['token' => $token]; |
|
124 | + } |
|
125 | + else |
|
126 | + { |
|
127 | + \ErrorHandler::loginFailed(); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Handle a social login request of the none admin to the application. |
|
133 | + * |
|
134 | + * @param array $credentials |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function loginSocial($credentials) |
|
138 | + { |
|
139 | + $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
140 | + $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
141 | + |
|
142 | + if ( ! $user->email) |
|
143 | + { |
|
144 | + \ErrorHandler::noSocialEmail(); |
|
145 | + } |
|
146 | + |
|
147 | + if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
148 | + { |
|
149 | + $data = ['email' => $user->email, 'password' => '']; |
|
150 | + return $this->register($data); |
|
151 | + } |
|
152 | + else |
|
153 | + { |
|
154 | + if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
155 | + { |
|
156 | + \ErrorHandler::userAlreadyRegistered(); |
|
157 | + } |
|
158 | + return $this->login(['email' => $registeredUser->email, 'password' => ''], false); |
|
159 | + } |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Handle a registration request. |
|
164 | - * |
|
165 | - * @param array $credentials |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - public function register($credentials) |
|
169 | - { |
|
170 | - return ['token' => \JWTAuth::fromUser($this->model->create($credentials))]; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Logout the user. |
|
175 | - * |
|
176 | - * @return boolean |
|
177 | - */ |
|
178 | - public function logout() |
|
179 | - { |
|
180 | - return \JWTAuth::invalidate(\JWTAuth::getToken()); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Block the user. |
|
185 | - * |
|
186 | - * @param integer $user_id |
|
187 | - * @return object |
|
188 | - */ |
|
189 | - public function block($user_id) |
|
190 | - { |
|
191 | - if ( ! $user = $this->find($user_id)) |
|
192 | - { |
|
193 | - \ErrorHandler::notFound('user'); |
|
194 | - } |
|
195 | - if ( ! $this->hasGroup('Admin')) |
|
196 | - { |
|
197 | - \ErrorHandler::noPermissions(); |
|
198 | - } |
|
199 | - else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
200 | - { |
|
201 | - \ErrorHandler::noPermissions(); |
|
202 | - } |
|
203 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
204 | - { |
|
205 | - \ErrorHandler::noPermissions(); |
|
206 | - } |
|
207 | - |
|
208 | - $user->blocked = 1; |
|
209 | - $user->save(); |
|
162 | + /** |
|
163 | + * Handle a registration request. |
|
164 | + * |
|
165 | + * @param array $credentials |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + public function register($credentials) |
|
169 | + { |
|
170 | + return ['token' => \JWTAuth::fromUser($this->model->create($credentials))]; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Logout the user. |
|
175 | + * |
|
176 | + * @return boolean |
|
177 | + */ |
|
178 | + public function logout() |
|
179 | + { |
|
180 | + return \JWTAuth::invalidate(\JWTAuth::getToken()); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Block the user. |
|
185 | + * |
|
186 | + * @param integer $user_id |
|
187 | + * @return object |
|
188 | + */ |
|
189 | + public function block($user_id) |
|
190 | + { |
|
191 | + if ( ! $user = $this->find($user_id)) |
|
192 | + { |
|
193 | + \ErrorHandler::notFound('user'); |
|
194 | + } |
|
195 | + if ( ! $this->hasGroup('Admin')) |
|
196 | + { |
|
197 | + \ErrorHandler::noPermissions(); |
|
198 | + } |
|
199 | + else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
200 | + { |
|
201 | + \ErrorHandler::noPermissions(); |
|
202 | + } |
|
203 | + else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
204 | + { |
|
205 | + \ErrorHandler::noPermissions(); |
|
206 | + } |
|
207 | + |
|
208 | + $user->blocked = 1; |
|
209 | + $user->save(); |
|
210 | 210 | |
211 | - return $user; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Unblock the user. |
|
216 | - * |
|
217 | - * @param integer $user_id |
|
218 | - * @return object |
|
219 | - */ |
|
220 | - public function unblock($user_id) |
|
221 | - { |
|
222 | - if ( ! $this->hasGroup('Admin')) |
|
223 | - { |
|
224 | - \ErrorHandler::noPermissions(); |
|
225 | - } |
|
226 | - |
|
227 | - $user = $this->find($user_id); |
|
228 | - $user->blocked = 0; |
|
229 | - $user->save(); |
|
230 | - |
|
231 | - return $user; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Send a reset link to the given user. |
|
236 | - * |
|
237 | - * @param string $email |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function sendReset($email) |
|
241 | - { |
|
242 | - if ( ! $user = $this->model->where('email', $email)->first()) |
|
243 | - { |
|
244 | - \ErrorHandler::notFound('email'); |
|
245 | - } |
|
246 | - |
|
247 | - $url = $this->config['resetLink']; |
|
248 | - $token = \Password::getRepository()->create($user); |
|
211 | + return $user; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Unblock the user. |
|
216 | + * |
|
217 | + * @param integer $user_id |
|
218 | + * @return object |
|
219 | + */ |
|
220 | + public function unblock($user_id) |
|
221 | + { |
|
222 | + if ( ! $this->hasGroup('Admin')) |
|
223 | + { |
|
224 | + \ErrorHandler::noPermissions(); |
|
225 | + } |
|
226 | + |
|
227 | + $user = $this->find($user_id); |
|
228 | + $user->blocked = 0; |
|
229 | + $user->save(); |
|
230 | + |
|
231 | + return $user; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Send a reset link to the given user. |
|
236 | + * |
|
237 | + * @param string $email |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function sendReset($email) |
|
241 | + { |
|
242 | + if ( ! $user = $this->model->where('email', $email)->first()) |
|
243 | + { |
|
244 | + \ErrorHandler::notFound('email'); |
|
245 | + } |
|
246 | + |
|
247 | + $url = $this->config['resetLink']; |
|
248 | + $token = \Password::getRepository()->create($user); |
|
249 | 249 | |
250 | - \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
251 | - $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
|
252 | - }); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Reset the given user's password. |
|
257 | - * |
|
258 | - * @param array $credentials |
|
259 | - * @return array |
|
260 | - */ |
|
261 | - public function resetPassword($credentials) |
|
262 | - { |
|
263 | - $token = false; |
|
264 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
265 | - $user->password = $password; |
|
266 | - $user->save(); |
|
267 | - |
|
268 | - $token = \JWTAuth::fromUser($user); |
|
269 | - }); |
|
270 | - |
|
271 | - switch ($response) { |
|
272 | - case \Password::PASSWORD_RESET: |
|
273 | - return ['token' => $token]; |
|
250 | + \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
251 | + $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
|
252 | + }); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Reset the given user's password. |
|
257 | + * |
|
258 | + * @param array $credentials |
|
259 | + * @return array |
|
260 | + */ |
|
261 | + public function resetPassword($credentials) |
|
262 | + { |
|
263 | + $token = false; |
|
264 | + $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
265 | + $user->password = $password; |
|
266 | + $user->save(); |
|
267 | + |
|
268 | + $token = \JWTAuth::fromUser($user); |
|
269 | + }); |
|
270 | + |
|
271 | + switch ($response) { |
|
272 | + case \Password::PASSWORD_RESET: |
|
273 | + return ['token' => $token]; |
|
274 | 274 | |
275 | - case \Password::INVALID_TOKEN: |
|
276 | - \ErrorHandler::invalidResetToken('token'); |
|
277 | - |
|
278 | - case \Password::INVALID_PASSWORD: |
|
279 | - \ErrorHandler::invalidResetPassword('email'); |
|
280 | - |
|
281 | - case \Password::INVALID_USER: |
|
282 | - \ErrorHandler::notFound('user'); |
|
283 | - |
|
284 | - default: |
|
285 | - \ErrorHandler::generalError(); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Change the logged in user password. |
|
291 | - * |
|
292 | - * @param array $credentials |
|
293 | - * @return void |
|
294 | - */ |
|
295 | - public function changePassword($credentials) |
|
296 | - { |
|
297 | - $user = \JWTAuth::parseToken()->authenticate(); |
|
298 | - if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
299 | - { |
|
300 | - \ErrorHandler::invalidOldPassword(); |
|
301 | - } |
|
302 | - |
|
303 | - $user->password = $credentials['password']; |
|
304 | - $user->save(); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Refresh the expired login token. |
|
309 | - * |
|
310 | - * @return array |
|
311 | - */ |
|
312 | - public function refreshtoken() |
|
313 | - { |
|
314 | - $token = \JWTAuth::parseToken()->refresh(); |
|
315 | - |
|
316 | - return ['token' => $token]; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Paginate all users in the given group based on the given conditions. |
|
321 | - * |
|
322 | - * @param string $groupName |
|
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 group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
330 | - { |
|
331 | - unset($conditions['page']); |
|
332 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
333 | - $sort = $desc ? 'desc' : 'asc'; |
|
334 | - $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
335 | - |
|
336 | - $model->whereHas('groups', function($q) use ($groupName){ |
|
337 | - $q->where('name', $groupName); |
|
338 | - }); |
|
275 | + case \Password::INVALID_TOKEN: |
|
276 | + \ErrorHandler::invalidResetToken('token'); |
|
277 | + |
|
278 | + case \Password::INVALID_PASSWORD: |
|
279 | + \ErrorHandler::invalidResetPassword('email'); |
|
280 | + |
|
281 | + case \Password::INVALID_USER: |
|
282 | + \ErrorHandler::notFound('user'); |
|
283 | + |
|
284 | + default: |
|
285 | + \ErrorHandler::generalError(); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Change the logged in user password. |
|
291 | + * |
|
292 | + * @param array $credentials |
|
293 | + * @return void |
|
294 | + */ |
|
295 | + public function changePassword($credentials) |
|
296 | + { |
|
297 | + $user = \JWTAuth::parseToken()->authenticate(); |
|
298 | + if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
299 | + { |
|
300 | + \ErrorHandler::invalidOldPassword(); |
|
301 | + } |
|
302 | + |
|
303 | + $user->password = $credentials['password']; |
|
304 | + $user->save(); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Refresh the expired login token. |
|
309 | + * |
|
310 | + * @return array |
|
311 | + */ |
|
312 | + public function refreshtoken() |
|
313 | + { |
|
314 | + $token = \JWTAuth::parseToken()->refresh(); |
|
315 | + |
|
316 | + return ['token' => $token]; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Paginate all users in the given group based on the given conditions. |
|
321 | + * |
|
322 | + * @param string $groupName |
|
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 group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
330 | + { |
|
331 | + unset($conditions['page']); |
|
332 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
333 | + $sort = $desc ? 'desc' : 'asc'; |
|
334 | + $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
335 | + |
|
336 | + $model->whereHas('groups', function($q) use ($groupName){ |
|
337 | + $q->where('name', $groupName); |
|
338 | + }); |
|
339 | 339 | |
340 | 340 | |
341 | - if (count($conditions['conditionValues'])) |
|
342 | - { |
|
343 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
344 | - } |
|
345 | - |
|
346 | - if ($perPage) |
|
347 | - { |
|
348 | - return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
349 | - } |
|
350 | - |
|
351 | - return $model->orderBy($sortBy, $sort)->get(); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Save the given data to the logged in user. |
|
356 | - * |
|
357 | - * @param array $credentials |
|
358 | - * @return object |
|
359 | - */ |
|
360 | - public function saveProfile($credentials) |
|
361 | - { |
|
362 | - $user = \JWTAuth::parseToken()->authenticate(); |
|
363 | - $user->save($credentials); |
|
364 | - |
|
365 | - return $user; |
|
366 | - } |
|
341 | + if (count($conditions['conditionValues'])) |
|
342 | + { |
|
343 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
344 | + } |
|
345 | + |
|
346 | + if ($perPage) |
|
347 | + { |
|
348 | + return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
349 | + } |
|
350 | + |
|
351 | + return $model->orderBy($sortBy, $sort)->get(); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Save the given data to the logged in user. |
|
356 | + * |
|
357 | + * @param array $credentials |
|
358 | + * @return object |
|
359 | + */ |
|
360 | + public function saveProfile($credentials) |
|
361 | + { |
|
362 | + $user = \JWTAuth::parseToken()->authenticate(); |
|
363 | + $user->save($credentials); |
|
364 | + |
|
365 | + return $user; |
|
366 | + } |
|
367 | 367 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $user = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations); |
27 | 27 | foreach ($user->groups()->get() as $group) |
28 | 28 | { |
29 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
29 | + $group->permissions->each(function($permission) use (&$permissions){ |
|
30 | 30 | $permissions[$permission->model][$permission->id] = $permission->name; |
31 | 31 | }); |
32 | 32 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param boolean $user |
45 | 45 | * @return boolean |
46 | 46 | */ |
47 | - public function can($nameOfPermission, $model, $user = false ) |
|
47 | + public function can($nameOfPermission, $model, $user = false) |
|
48 | 48 | { |
49 | 49 | $user = $user ?: \JWTAuth::parseToken()->authenticate(); |
50 | 50 | $permissions = []; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | \ErrorHandler::tokenExpired(); |
55 | 55 | } |
56 | 56 | |
57 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
57 | + $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){ |
|
58 | 58 | $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
59 | 59 | }); |
60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param integer $userId |
69 | 69 | * @return boolean |
70 | 70 | */ |
71 | - public function hasGroup($groupName, $userId = fa;se) |
|
71 | + public function hasGroup($groupName, $userId = fa; se) |
|
72 | 72 | { |
73 | 73 | $userId = $userId ?: \JWTAuth::parseToken()->authenticate()->id; |
74 | 74 | $groups = $this->find($userId)->groups; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function assignGroups($user_id, $group_ids) |
86 | 86 | { |
87 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
87 | + \DB::transaction(function() use ($user_id, $group_ids) { |
|
88 | 88 | $user = $this->find($user_id); |
89 | 89 | $user->groups()->detach(); |
90 | 90 | $user->groups()->attach($group_ids); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $url = $this->config['resetLink']; |
248 | 248 | $token = \Password::getRepository()->create($user); |
249 | 249 | |
250 | - \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
250 | + \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function($m) use ($user) { |
|
251 | 251 | $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
252 | 252 | }); |
253 | 253 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | public function resetPassword($credentials) |
262 | 262 | { |
263 | 263 | $token = false; |
264 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
264 | + $response = \Password::reset($credentials, function($user, $password) use (&$token) { |
|
265 | 265 | $user->password = $password; |
266 | 266 | $user->save(); |
267 | 267 |
@@ -8,72 +8,72 @@ |
||
8 | 8 | class RouteServiceProvider extends ServiceProvider |
9 | 9 | { |
10 | 10 | /** |
11 | - * This namespace is applied to your controller routes. |
|
12 | - * |
|
13 | - * In addition, it is set as the URL generator's root namespace. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $namespace = 'App\Modules\V1\Notifications\Http\Controllers'; |
|
11 | + * This namespace is applied to your controller routes. |
|
12 | + * |
|
13 | + * In addition, it is set as the URL generator's root namespace. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $namespace = 'App\Modules\V1\Notifications\Http\Controllers'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Define your route model bindings, pattern filters, etc. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function boot() |
|
25 | - { |
|
26 | - // |
|
19 | + /** |
|
20 | + * Define your route model bindings, pattern filters, etc. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function boot() |
|
25 | + { |
|
26 | + // |
|
27 | 27 | |
28 | - parent::boot(); |
|
29 | - } |
|
28 | + parent::boot(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Define the routes for the module. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function map() |
|
37 | - { |
|
38 | - $this->mapWebRoutes(); |
|
31 | + /** |
|
32 | + * Define the routes for the module. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function map() |
|
37 | + { |
|
38 | + $this->mapWebRoutes(); |
|
39 | 39 | |
40 | - $this->mapApiRoutes(); |
|
40 | + $this->mapApiRoutes(); |
|
41 | 41 | |
42 | - // |
|
43 | - } |
|
42 | + // |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Define the "web" routes for the module. |
|
47 | - * |
|
48 | - * These routes all receive session state, CSRF protection, etc. |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - protected function mapWebRoutes() |
|
53 | - { |
|
54 | - Route::group([ |
|
55 | - 'middleware' => 'web', |
|
56 | - 'namespace' => $this->namespace, |
|
57 | - ], function ($router) { |
|
58 | - require module_path('notifications', 'Routes/web.php'); |
|
59 | - }); |
|
60 | - } |
|
45 | + /** |
|
46 | + * Define the "web" routes for the module. |
|
47 | + * |
|
48 | + * These routes all receive session state, CSRF protection, etc. |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + protected function mapWebRoutes() |
|
53 | + { |
|
54 | + Route::group([ |
|
55 | + 'middleware' => 'web', |
|
56 | + 'namespace' => $this->namespace, |
|
57 | + ], function ($router) { |
|
58 | + require module_path('notifications', 'Routes/web.php'); |
|
59 | + }); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Define the "api" routes for the module. |
|
64 | - * |
|
65 | - * These routes are typically stateless. |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function mapApiRoutes() |
|
70 | - { |
|
71 | - Route::group([ |
|
72 | - 'middleware' => 'api', |
|
73 | - 'namespace' => $this->namespace, |
|
74 | - 'prefix' => 'api', |
|
75 | - ], function ($router) { |
|
76 | - require module_path('notifications', 'Routes/api.php'); |
|
77 | - }); |
|
78 | - } |
|
62 | + /** |
|
63 | + * Define the "api" routes for the module. |
|
64 | + * |
|
65 | + * These routes are typically stateless. |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function mapApiRoutes() |
|
70 | + { |
|
71 | + Route::group([ |
|
72 | + 'middleware' => 'api', |
|
73 | + 'namespace' => $this->namespace, |
|
74 | + 'prefix' => 'api', |
|
75 | + ], function ($router) { |
|
76 | + require module_path('notifications', 'Routes/api.php'); |
|
77 | + }); |
|
78 | + } |
|
79 | 79 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | Route::group([ |
55 | 55 | 'middleware' => 'web', |
56 | 56 | 'namespace' => $this->namespace, |
57 | - ], function ($router) { |
|
57 | + ], function($router) { |
|
58 | 58 | require module_path('notifications', 'Routes/web.php'); |
59 | 59 | }); |
60 | 60 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'middleware' => 'api', |
73 | 73 | 'namespace' => $this->namespace, |
74 | 74 | 'prefix' => 'api', |
75 | - ], function ($router) { |
|
75 | + ], function($router) { |
|
76 | 76 | require module_path('notifications', 'Routes/api.php'); |
77 | 77 | }); |
78 | 78 | } |
@@ -8,72 +8,72 @@ |
||
8 | 8 | class RouteServiceProvider extends ServiceProvider |
9 | 9 | { |
10 | 10 | /** |
11 | - * This namespace is applied to your controller routes. |
|
12 | - * |
|
13 | - * In addition, it is set as the URL generator's root namespace. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $namespace = 'App\Modules\V1\Core\Http\Controllers'; |
|
11 | + * This namespace is applied to your controller routes. |
|
12 | + * |
|
13 | + * In addition, it is set as the URL generator's root namespace. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $namespace = 'App\Modules\V1\Core\Http\Controllers'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Define your route model bindings, pattern filters, etc. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function boot() |
|
25 | - { |
|
26 | - // |
|
19 | + /** |
|
20 | + * Define your route model bindings, pattern filters, etc. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function boot() |
|
25 | + { |
|
26 | + // |
|
27 | 27 | |
28 | - parent::boot(); |
|
29 | - } |
|
28 | + parent::boot(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Define the routes for the module. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function map() |
|
37 | - { |
|
38 | - $this->mapWebRoutes(); |
|
31 | + /** |
|
32 | + * Define the routes for the module. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function map() |
|
37 | + { |
|
38 | + $this->mapWebRoutes(); |
|
39 | 39 | |
40 | - $this->mapApiRoutes(); |
|
40 | + $this->mapApiRoutes(); |
|
41 | 41 | |
42 | - // |
|
43 | - } |
|
42 | + // |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Define the "web" routes for the module. |
|
47 | - * |
|
48 | - * These routes all receive session state, CSRF protection, etc. |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - protected function mapWebRoutes() |
|
53 | - { |
|
54 | - Route::group([ |
|
55 | - 'middleware' => 'web', |
|
56 | - 'namespace' => $this->namespace, |
|
57 | - ], function ($router) { |
|
58 | - require module_path('core', 'Routes/web.php'); |
|
59 | - }); |
|
60 | - } |
|
45 | + /** |
|
46 | + * Define the "web" routes for the module. |
|
47 | + * |
|
48 | + * These routes all receive session state, CSRF protection, etc. |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + protected function mapWebRoutes() |
|
53 | + { |
|
54 | + Route::group([ |
|
55 | + 'middleware' => 'web', |
|
56 | + 'namespace' => $this->namespace, |
|
57 | + ], function ($router) { |
|
58 | + require module_path('core', 'Routes/web.php'); |
|
59 | + }); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Define the "api" routes for the module. |
|
64 | - * |
|
65 | - * These routes are typically stateless. |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function mapApiRoutes() |
|
70 | - { |
|
71 | - Route::group([ |
|
72 | - 'middleware' => 'api', |
|
73 | - 'namespace' => $this->namespace, |
|
74 | - 'prefix' => 'api', |
|
75 | - ], function ($router) { |
|
76 | - require module_path('core', 'Routes/api.php'); |
|
77 | - }); |
|
78 | - } |
|
62 | + /** |
|
63 | + * Define the "api" routes for the module. |
|
64 | + * |
|
65 | + * These routes are typically stateless. |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function mapApiRoutes() |
|
70 | + { |
|
71 | + Route::group([ |
|
72 | + 'middleware' => 'api', |
|
73 | + 'namespace' => $this->namespace, |
|
74 | + 'prefix' => 'api', |
|
75 | + ], function ($router) { |
|
76 | + require module_path('core', 'Routes/api.php'); |
|
77 | + }); |
|
78 | + } |
|
79 | 79 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | Route::group([ |
55 | 55 | 'middleware' => 'web', |
56 | 56 | 'namespace' => $this->namespace, |
57 | - ], function ($router) { |
|
57 | + ], function($router) { |
|
58 | 58 | require module_path('core', 'Routes/web.php'); |
59 | 59 | }); |
60 | 60 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'middleware' => 'api', |
73 | 73 | 'namespace' => $this->namespace, |
74 | 74 | 'prefix' => 'api', |
75 | - ], function ($router) { |
|
75 | + ], function($router) { |
|
76 | 76 | require module_path('core', 'Routes/api.php'); |
77 | 77 | }); |
78 | 78 | } |
@@ -8,72 +8,72 @@ |
||
8 | 8 | class RouteServiceProvider extends ServiceProvider |
9 | 9 | { |
10 | 10 | /** |
11 | - * This namespace is applied to your controller routes. |
|
12 | - * |
|
13 | - * In addition, it is set as the URL generator's root namespace. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $namespace = 'App\Modules\V1\Reporting\Http\Controllers'; |
|
11 | + * This namespace is applied to your controller routes. |
|
12 | + * |
|
13 | + * In addition, it is set as the URL generator's root namespace. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $namespace = 'App\Modules\V1\Reporting\Http\Controllers'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Define your route model bindings, pattern filters, etc. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function boot() |
|
25 | - { |
|
26 | - // |
|
19 | + /** |
|
20 | + * Define your route model bindings, pattern filters, etc. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function boot() |
|
25 | + { |
|
26 | + // |
|
27 | 27 | |
28 | - parent::boot(); |
|
29 | - } |
|
28 | + parent::boot(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Define the routes for the module. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function map() |
|
37 | - { |
|
38 | - $this->mapWebRoutes(); |
|
31 | + /** |
|
32 | + * Define the routes for the module. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function map() |
|
37 | + { |
|
38 | + $this->mapWebRoutes(); |
|
39 | 39 | |
40 | - $this->mapApiRoutes(); |
|
40 | + $this->mapApiRoutes(); |
|
41 | 41 | |
42 | - // |
|
43 | - } |
|
42 | + // |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Define the "web" routes for the module. |
|
47 | - * |
|
48 | - * These routes all receive session state, CSRF protection, etc. |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - protected function mapWebRoutes() |
|
53 | - { |
|
54 | - Route::group([ |
|
55 | - 'middleware' => 'web', |
|
56 | - 'namespace' => $this->namespace, |
|
57 | - ], function ($router) { |
|
58 | - require module_path('reporting', 'Routes/web.php'); |
|
59 | - }); |
|
60 | - } |
|
45 | + /** |
|
46 | + * Define the "web" routes for the module. |
|
47 | + * |
|
48 | + * These routes all receive session state, CSRF protection, etc. |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + protected function mapWebRoutes() |
|
53 | + { |
|
54 | + Route::group([ |
|
55 | + 'middleware' => 'web', |
|
56 | + 'namespace' => $this->namespace, |
|
57 | + ], function ($router) { |
|
58 | + require module_path('reporting', 'Routes/web.php'); |
|
59 | + }); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Define the "api" routes for the module. |
|
64 | - * |
|
65 | - * These routes are typically stateless. |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function mapApiRoutes() |
|
70 | - { |
|
71 | - Route::group([ |
|
72 | - 'middleware' => 'api', |
|
73 | - 'namespace' => $this->namespace, |
|
74 | - 'prefix' => 'api', |
|
75 | - ], function ($router) { |
|
76 | - require module_path('reporting', 'Routes/api.php'); |
|
77 | - }); |
|
78 | - } |
|
62 | + /** |
|
63 | + * Define the "api" routes for the module. |
|
64 | + * |
|
65 | + * These routes are typically stateless. |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function mapApiRoutes() |
|
70 | + { |
|
71 | + Route::group([ |
|
72 | + 'middleware' => 'api', |
|
73 | + 'namespace' => $this->namespace, |
|
74 | + 'prefix' => 'api', |
|
75 | + ], function ($router) { |
|
76 | + require module_path('reporting', 'Routes/api.php'); |
|
77 | + }); |
|
78 | + } |
|
79 | 79 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | Route::group([ |
55 | 55 | 'middleware' => 'web', |
56 | 56 | 'namespace' => $this->namespace, |
57 | - ], function ($router) { |
|
57 | + ], function($router) { |
|
58 | 58 | require module_path('reporting', 'Routes/web.php'); |
59 | 59 | }); |
60 | 60 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'middleware' => 'api', |
73 | 73 | 'namespace' => $this->namespace, |
74 | 74 | 'prefix' => 'api', |
75 | - ], function ($router) { |
|
75 | + ], function($router) { |
|
76 | 76 | require module_path('reporting', 'Routes/api.php'); |
77 | 77 | }); |
78 | 78 | } |
@@ -8,72 +8,72 @@ |
||
8 | 8 | class RouteServiceProvider extends ServiceProvider |
9 | 9 | { |
10 | 10 | /** |
11 | - * This namespace is applied to your controller routes. |
|
12 | - * |
|
13 | - * In addition, it is set as the URL generator's root namespace. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $namespace = 'App\Modules\V1\Acl\Http\Controllers'; |
|
11 | + * This namespace is applied to your controller routes. |
|
12 | + * |
|
13 | + * In addition, it is set as the URL generator's root namespace. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $namespace = 'App\Modules\V1\Acl\Http\Controllers'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Define your route model bindings, pattern filters, etc. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function boot() |
|
25 | - { |
|
26 | - // |
|
19 | + /** |
|
20 | + * Define your route model bindings, pattern filters, etc. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function boot() |
|
25 | + { |
|
26 | + // |
|
27 | 27 | |
28 | - parent::boot(); |
|
29 | - } |
|
28 | + parent::boot(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Define the routes for the module. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function map() |
|
37 | - { |
|
38 | - $this->mapWebRoutes(); |
|
31 | + /** |
|
32 | + * Define the routes for the module. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function map() |
|
37 | + { |
|
38 | + $this->mapWebRoutes(); |
|
39 | 39 | |
40 | - $this->mapApiRoutes(); |
|
40 | + $this->mapApiRoutes(); |
|
41 | 41 | |
42 | - // |
|
43 | - } |
|
42 | + // |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Define the "web" routes for the module. |
|
47 | - * |
|
48 | - * These routes all receive session state, CSRF protection, etc. |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - protected function mapWebRoutes() |
|
53 | - { |
|
54 | - Route::group([ |
|
55 | - 'middleware' => 'web', |
|
56 | - 'namespace' => $this->namespace, |
|
57 | - ], function ($router) { |
|
58 | - require module_path('acl', 'Routes/web.php'); |
|
59 | - }); |
|
60 | - } |
|
45 | + /** |
|
46 | + * Define the "web" routes for the module. |
|
47 | + * |
|
48 | + * These routes all receive session state, CSRF protection, etc. |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + protected function mapWebRoutes() |
|
53 | + { |
|
54 | + Route::group([ |
|
55 | + 'middleware' => 'web', |
|
56 | + 'namespace' => $this->namespace, |
|
57 | + ], function ($router) { |
|
58 | + require module_path('acl', 'Routes/web.php'); |
|
59 | + }); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Define the "api" routes for the module. |
|
64 | - * |
|
65 | - * These routes are typically stateless. |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function mapApiRoutes() |
|
70 | - { |
|
71 | - Route::group([ |
|
72 | - 'middleware' => 'api', |
|
73 | - 'namespace' => $this->namespace, |
|
74 | - 'prefix' => 'api', |
|
75 | - ], function ($router) { |
|
76 | - require module_path('acl', 'Routes/api.php'); |
|
77 | - }); |
|
78 | - } |
|
62 | + /** |
|
63 | + * Define the "api" routes for the module. |
|
64 | + * |
|
65 | + * These routes are typically stateless. |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function mapApiRoutes() |
|
70 | + { |
|
71 | + Route::group([ |
|
72 | + 'middleware' => 'api', |
|
73 | + 'namespace' => $this->namespace, |
|
74 | + 'prefix' => 'api', |
|
75 | + ], function ($router) { |
|
76 | + require module_path('acl', 'Routes/api.php'); |
|
77 | + }); |
|
78 | + } |
|
79 | 79 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | Route::group([ |
55 | 55 | 'middleware' => 'web', |
56 | 56 | 'namespace' => $this->namespace, |
57 | - ], function ($router) { |
|
57 | + ], function($router) { |
|
58 | 58 | require module_path('acl', 'Routes/web.php'); |
59 | 59 | }); |
60 | 60 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'middleware' => 'api', |
73 | 73 | 'namespace' => $this->namespace, |
74 | 74 | 'prefix' => 'api', |
75 | - ], function ($router) { |
|
75 | + ], function($router) { |
|
76 | 76 | require module_path('acl', 'Routes/api.php'); |
77 | 77 | }); |
78 | 78 | } |
@@ -2,25 +2,25 @@ |
||
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 | - 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
13 | - 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
14 | - 'connectionError' => 'خطأ في الاتصال', |
|
15 | - 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
16 | - 'dbQueryError' => 'خطا في البيانات', |
|
17 | - 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
18 | - 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
19 | - 'userIsBlocked' => 'لقد تم حظرك', |
|
20 | - 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
21 | - 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
22 | - 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
23 | - 'notFound' => 'ال :replace المطلوب غير موجود', |
|
24 | - 'generalError' => 'حدث خطا ما', |
|
5 | + /** |
|
6 | + * List of error messages used in core module. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | + 'tokenExpired' => 'انتهت صلاحية الدخول', |
|
10 | + 'noPermissions' => 'لا توجد صلاحية', |
|
11 | + 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | + 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
13 | + 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
14 | + 'connectionError' => 'خطأ في الاتصال', |
|
15 | + 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
16 | + 'dbQueryError' => 'خطا في البيانات', |
|
17 | + 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
18 | + 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
19 | + 'userIsBlocked' => 'لقد تم حظرك', |
|
20 | + 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
21 | + 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
22 | + 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
23 | + 'notFound' => 'ال :replace المطلوب غير موجود', |
|
24 | + 'generalError' => 'حدث خطا ما', |
|
25 | 25 | |
26 | 26 | ]; |
27 | 27 | \ No newline at end of file |
@@ -2,25 +2,25 @@ |
||
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 | - 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
13 | - 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
14 | - 'connectionError' => 'Connection error', |
|
15 | - 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
16 | - 'dbQueryError' => 'Please check the given inputes', |
|
17 | - 'cannotCreateSetting' => 'Can\'t create setting', |
|
18 | - 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
19 | - 'userIsBlocked' => 'You have been blocked', |
|
20 | - 'invalidResetToken' => 'Reset password token is invalid', |
|
21 | - 'invalidResetPassword' => 'Reset password is invalid', |
|
22 | - 'invalidOldPassword' => 'Old password is invalid', |
|
23 | - 'notFound' => 'The requested :replace not found', |
|
24 | - '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 | + 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
13 | + 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
14 | + 'connectionError' => 'Connection error', |
|
15 | + 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
16 | + 'dbQueryError' => 'Please check the given inputes', |
|
17 | + 'cannotCreateSetting' => 'Can\'t create setting', |
|
18 | + 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
19 | + 'userIsBlocked' => 'You have been blocked', |
|
20 | + 'invalidResetToken' => 'Reset password token is invalid', |
|
21 | + 'invalidResetPassword' => 'Reset password is invalid', |
|
22 | + 'invalidOldPassword' => 'Old password is invalid', |
|
23 | + 'notFound' => 'The requested :replace not found', |
|
24 | + 'generalError' => 'Something went wrong', |
|
25 | 25 | |
26 | 26 | ]; |
27 | 27 | \ No newline at end of file |
@@ -13,16 +13,16 @@ |
||
13 | 13 | public function up() |
14 | 14 | { |
15 | 15 | Schema::create('users', function (Blueprint $table) { |
16 | - $table->increments('id'); |
|
17 | - $table->string('name', 100)->nullable(); |
|
18 | - $table->string('email')->unique(); |
|
19 | - $table->string('password', 60)->nullable(); |
|
20 | - $table->boolean('blocked')->default(0); |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name', 100)->nullable(); |
|
18 | + $table->string('email')->unique(); |
|
19 | + $table->string('password', 60)->nullable(); |
|
20 | + $table->boolean('blocked')->default(0); |
|
21 | 21 | $table->date('last_change_password')->nullable(); |
22 | - $table->softDeletes(); |
|
23 | - $table->rememberToken(); |
|
24 | - $table->timestamps(); |
|
25 | - }); |
|
22 | + $table->softDeletes(); |
|
23 | + $table->rememberToken(); |
|
24 | + $table->timestamps(); |
|
25 | + }); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -12,7 +12,7 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('users', function (Blueprint $table) { |
|
15 | + Schema::create('users', function(Blueprint $table) { |
|
16 | 16 | $table->increments('id'); |
17 | 17 | $table->string('name', 100)->nullable(); |
18 | 18 | $table->string('email')->unique(); |
@@ -170,8 +170,7 @@ |
||
170 | 170 | if ($request->has('id')) |
171 | 171 | { |
172 | 172 | $rule = str_replace('{id}', $request->get('id'), $rule); |
173 | - } |
|
174 | - else |
|
173 | + } else |
|
175 | 174 | { |
176 | 175 | $rule = str_replace(',{id}', '', $rule); |
177 | 176 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * to preform actions like (add, edit ... etc). |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - protected $model = 'users'; |
|
15 | + protected $model = 'users'; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * List of all route actions that the base api controller |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * will skip login check for them. |
27 | 27 | * @var array |
28 | 28 | */ |
29 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
29 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * The validations rules used by the base api controller |
33 | 33 | * to check before add. |
34 | 34 | * @var array |
35 | 35 | */ |
36 | - protected $validationRules = [ |
|
36 | + protected $validationRules = [ |
|
37 | 37 | 'name' => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', |
38 | 38 | 'email' => 'required|email|unique:users,email,{id},id,email,NOT_NULL', |
39 | 39 | 'password' => 'nullable|min:6' |
@@ -7,250 +7,250 @@ |
||
7 | 7 | |
8 | 8 | class UsersController extends BaseApiController |
9 | 9 | { |
10 | - /** |
|
11 | - * The name of the model that is used by the base api controller |
|
12 | - * to preform actions like (add, edit ... etc). |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $model = 'users'; |
|
10 | + /** |
|
11 | + * The name of the model that is used by the base api controller |
|
12 | + * to preform actions like (add, edit ... etc). |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $model = 'users'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * List of all route actions that the base api controller |
|
19 | - * will skip permissions check for them. |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword']; |
|
17 | + /** |
|
18 | + * List of all route actions that the base api controller |
|
19 | + * will skip permissions check for them. |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword']; |
|
23 | 23 | |
24 | - /** |
|
25 | - * List of all route actions that the base api controller |
|
26 | - * will skip login check for them. |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
24 | + /** |
|
25 | + * List of all route actions that the base api controller |
|
26 | + * will skip login check for them. |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
30 | 30 | |
31 | - /** |
|
32 | - * The validations rules used by the base api controller |
|
33 | - * to check before add. |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $validationRules = [ |
|
37 | - 'name' => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', |
|
38 | - 'email' => 'required|email|unique:users,email,{id},id,email,NOT_NULL', |
|
39 | - 'password' => 'nullable|min:6' |
|
40 | - ]; |
|
31 | + /** |
|
32 | + * The validations rules used by the base api controller |
|
33 | + * to check before add. |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $validationRules = [ |
|
37 | + 'name' => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', |
|
38 | + 'email' => 'required|email|unique:users,email,{id},id,email,NOT_NULL', |
|
39 | + 'password' => 'nullable|min:6' |
|
40 | + ]; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Return the logged in user account. |
|
44 | - * |
|
45 | - * @return \Illuminate\Http\Response |
|
46 | - */ |
|
47 | - public function account() |
|
48 | - { |
|
49 | - return \Response::json(\Core::users()->account($this->relations), 200); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Return the logged in user account. |
|
44 | + * |
|
45 | + * @return \Illuminate\Http\Response |
|
46 | + */ |
|
47 | + public function account() |
|
48 | + { |
|
49 | + return \Response::json(\Core::users()->account($this->relations), 200); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Block the user. |
|
54 | - * |
|
55 | - * @param integer $id Id of the user. |
|
56 | - * @return \Illuminate\Http\Response |
|
57 | - */ |
|
58 | - public function block($id) |
|
59 | - { |
|
60 | - return \Response::json(\Core::users()->block($id), 200); |
|
61 | - } |
|
52 | + /** |
|
53 | + * Block the user. |
|
54 | + * |
|
55 | + * @param integer $id Id of the user. |
|
56 | + * @return \Illuminate\Http\Response |
|
57 | + */ |
|
58 | + public function block($id) |
|
59 | + { |
|
60 | + return \Response::json(\Core::users()->block($id), 200); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Unblock the user. |
|
65 | - * |
|
66 | - * @param integer $id Id of the user. |
|
67 | - * @return \Illuminate\Http\Response |
|
68 | - */ |
|
69 | - public function unblock($id) |
|
70 | - { |
|
71 | - return \Response::json(\Core::users()->unblock($id), 200); |
|
72 | - } |
|
63 | + /** |
|
64 | + * Unblock the user. |
|
65 | + * |
|
66 | + * @param integer $id Id of the user. |
|
67 | + * @return \Illuminate\Http\Response |
|
68 | + */ |
|
69 | + public function unblock($id) |
|
70 | + { |
|
71 | + return \Response::json(\Core::users()->unblock($id), 200); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Logout the user. |
|
76 | - * |
|
77 | - * @return \Illuminate\Http\Response |
|
78 | - */ |
|
79 | - public function logout() |
|
80 | - { |
|
81 | - return \Response::json(\Core::users()->logout(), 200); |
|
82 | - } |
|
74 | + /** |
|
75 | + * Logout the user. |
|
76 | + * |
|
77 | + * @return \Illuminate\Http\Response |
|
78 | + */ |
|
79 | + public function logout() |
|
80 | + { |
|
81 | + return \Response::json(\Core::users()->logout(), 200); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Handle a registration request. |
|
86 | - * |
|
87 | - * @param \Illuminate\Http\Request $request |
|
88 | - * @return \Illuminate\Http\Response |
|
89 | - */ |
|
90 | - public function register(Request $request) |
|
91 | - { |
|
92 | - $this->validate($request, [ |
|
93 | - 'name' => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', |
|
94 | - 'email' => 'required|email|unique:users,email,{id},id,email,NOT_NULL', |
|
95 | - 'password' => 'required|min:6' |
|
96 | - ]); |
|
84 | + /** |
|
85 | + * Handle a registration request. |
|
86 | + * |
|
87 | + * @param \Illuminate\Http\Request $request |
|
88 | + * @return \Illuminate\Http\Response |
|
89 | + */ |
|
90 | + public function register(Request $request) |
|
91 | + { |
|
92 | + $this->validate($request, [ |
|
93 | + 'name' => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', |
|
94 | + 'email' => 'required|email|unique:users,email,{id},id,email,NOT_NULL', |
|
95 | + 'password' => 'required|min:6' |
|
96 | + ]); |
|
97 | 97 | |
98 | - return \Response::json(\Core::users()->register($request->only('email', 'password')), 200); |
|
99 | - } |
|
98 | + return \Response::json(\Core::users()->register($request->only('email', 'password')), 200); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Handle a login request of the none admin to the application. |
|
103 | - * |
|
104 | - * @param \Illuminate\Http\Request $request |
|
105 | - * @return \Illuminate\Http\Response |
|
106 | - */ |
|
107 | - public function login(Request $request) |
|
108 | - { |
|
109 | - $this->validate($request, [ |
|
110 | - 'email' => 'required|email', |
|
111 | - 'password' => 'required|min:6', |
|
112 | - 'admin' => 'boolean' |
|
113 | - ]); |
|
101 | + /** |
|
102 | + * Handle a login request of the none admin to the application. |
|
103 | + * |
|
104 | + * @param \Illuminate\Http\Request $request |
|
105 | + * @return \Illuminate\Http\Response |
|
106 | + */ |
|
107 | + public function login(Request $request) |
|
108 | + { |
|
109 | + $this->validate($request, [ |
|
110 | + 'email' => 'required|email', |
|
111 | + 'password' => 'required|min:6', |
|
112 | + 'admin' => 'boolean' |
|
113 | + ]); |
|
114 | 114 | |
115 | - return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200); |
|
116 | - } |
|
115 | + return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200); |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Handle a social login request of the none admin to the application. |
|
120 | - * |
|
121 | - * @param \Illuminate\Http\Request $request |
|
122 | - * @return \Illuminate\Http\Response |
|
123 | - */ |
|
124 | - public function loginSocial(Request $request) |
|
125 | - { |
|
126 | - $this->validate($request, [ |
|
127 | - 'auth_code' => 'required_without:access_token', |
|
128 | - 'access_token' => 'required_without:auth_code', |
|
129 | - 'type' => 'required|in:facebook,google' |
|
130 | - ]); |
|
118 | + /** |
|
119 | + * Handle a social login request of the none admin to the application. |
|
120 | + * |
|
121 | + * @param \Illuminate\Http\Request $request |
|
122 | + * @return \Illuminate\Http\Response |
|
123 | + */ |
|
124 | + public function loginSocial(Request $request) |
|
125 | + { |
|
126 | + $this->validate($request, [ |
|
127 | + 'auth_code' => 'required_without:access_token', |
|
128 | + 'access_token' => 'required_without:auth_code', |
|
129 | + 'type' => 'required|in:facebook,google' |
|
130 | + ]); |
|
131 | 131 | |
132 | - return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
133 | - } |
|
132 | + return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Assign the given groups to the given user. |
|
137 | - * |
|
138 | - * @param \Illuminate\Http\Request $request |
|
139 | - * @return \Illuminate\Http\Response |
|
140 | - */ |
|
141 | - public function assigngroups(Request $request) |
|
142 | - { |
|
143 | - $this->validate($request, [ |
|
144 | - 'group_ids' => 'required|exists:groups,id', |
|
145 | - 'user_id' => 'required|exists:users,id' |
|
146 | - ]); |
|
135 | + /** |
|
136 | + * Assign the given groups to the given user. |
|
137 | + * |
|
138 | + * @param \Illuminate\Http\Request $request |
|
139 | + * @return \Illuminate\Http\Response |
|
140 | + */ |
|
141 | + public function assigngroups(Request $request) |
|
142 | + { |
|
143 | + $this->validate($request, [ |
|
144 | + 'group_ids' => 'required|exists:groups,id', |
|
145 | + 'user_id' => 'required|exists:users,id' |
|
146 | + ]); |
|
147 | 147 | |
148 | - return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
149 | - } |
|
148 | + return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Send a reset link to the given user. |
|
153 | - * |
|
154 | - * @param \Illuminate\Http\Request $request |
|
155 | - * @return \Illuminate\Http\Response |
|
156 | - */ |
|
157 | - public function sendreset(Request $request) |
|
158 | - { |
|
159 | - $this->validate($request, ['email' => 'required|email']); |
|
151 | + /** |
|
152 | + * Send a reset link to the given user. |
|
153 | + * |
|
154 | + * @param \Illuminate\Http\Request $request |
|
155 | + * @return \Illuminate\Http\Response |
|
156 | + */ |
|
157 | + public function sendreset(Request $request) |
|
158 | + { |
|
159 | + $this->validate($request, ['email' => 'required|email']); |
|
160 | 160 | |
161 | - return \Response::json(\Core::users()->sendReset($request->only('email')), 200); |
|
162 | - } |
|
161 | + return \Response::json(\Core::users()->sendReset($request->only('email')), 200); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Reset the given user's password. |
|
166 | - * |
|
167 | - * @param \Illuminate\Http\Request $request |
|
168 | - * @return \Illuminate\Http\Response |
|
169 | - */ |
|
170 | - public function resetpassword(Request $request) |
|
171 | - { |
|
172 | - $this->validate($request, [ |
|
173 | - 'token' => 'required', |
|
174 | - 'email' => 'required|email', |
|
175 | - 'password' => 'required|confirmed|min:6', |
|
176 | - 'password_confirmation' => 'required', |
|
177 | - ]); |
|
164 | + /** |
|
165 | + * Reset the given user's password. |
|
166 | + * |
|
167 | + * @param \Illuminate\Http\Request $request |
|
168 | + * @return \Illuminate\Http\Response |
|
169 | + */ |
|
170 | + public function resetpassword(Request $request) |
|
171 | + { |
|
172 | + $this->validate($request, [ |
|
173 | + 'token' => 'required', |
|
174 | + 'email' => 'required|email', |
|
175 | + 'password' => 'required|confirmed|min:6', |
|
176 | + 'password_confirmation' => 'required', |
|
177 | + ]); |
|
178 | 178 | |
179 | - return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
180 | - } |
|
179 | + return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Change the logged in user password. |
|
184 | - * |
|
185 | - * @param \Illuminate\Http\Request $request |
|
186 | - * @return \Illuminate\Http\Response |
|
187 | - */ |
|
188 | - public function changePassword(Request $request) |
|
189 | - { |
|
190 | - $this->validate($request, [ |
|
191 | - 'old_password' => 'required', |
|
192 | - 'password' => 'required|confirmed|min:6', |
|
193 | - 'password_confirmation' => 'required', |
|
194 | - ]); |
|
182 | + /** |
|
183 | + * Change the logged in user password. |
|
184 | + * |
|
185 | + * @param \Illuminate\Http\Request $request |
|
186 | + * @return \Illuminate\Http\Response |
|
187 | + */ |
|
188 | + public function changePassword(Request $request) |
|
189 | + { |
|
190 | + $this->validate($request, [ |
|
191 | + 'old_password' => 'required', |
|
192 | + 'password' => 'required|confirmed|min:6', |
|
193 | + 'password_confirmation' => 'required', |
|
194 | + ]); |
|
195 | 195 | |
196 | - return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
197 | - } |
|
196 | + return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * Refresh the expired login token. |
|
201 | - * |
|
202 | - * @return \Illuminate\Http\Response |
|
203 | - */ |
|
204 | - public function refreshtoken() |
|
205 | - { |
|
206 | - return \Response::json(\Core::users()->refreshtoken(), 200); |
|
207 | - } |
|
199 | + /** |
|
200 | + * Refresh the expired login token. |
|
201 | + * |
|
202 | + * @return \Illuminate\Http\Response |
|
203 | + */ |
|
204 | + public function refreshtoken() |
|
205 | + { |
|
206 | + return \Response::json(\Core::users()->refreshtoken(), 200); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Paginate all users with inthe given group. |
|
211 | - * |
|
212 | - * @param \Illuminate\Http\Request $request |
|
213 | - * @param string $groupName The name of the requested group. |
|
214 | - * @param integer $perPage Number of rows per page default 15. |
|
215 | - * @param string $sortBy The name of the column to sort by. |
|
216 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
217 | - * @return \Illuminate\Http\Response |
|
218 | - */ |
|
219 | - public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
220 | - { |
|
221 | - return \Response::json(\Core::users()->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
222 | - } |
|
209 | + /** |
|
210 | + * Paginate all users with inthe given group. |
|
211 | + * |
|
212 | + * @param \Illuminate\Http\Request $request |
|
213 | + * @param string $groupName The name of the requested group. |
|
214 | + * @param integer $perPage Number of rows per page default 15. |
|
215 | + * @param string $sortBy The name of the column to sort by. |
|
216 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
217 | + * @return \Illuminate\Http\Response |
|
218 | + */ |
|
219 | + public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
220 | + { |
|
221 | + return \Response::json(\Core::users()->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Save the given data to the logged in user. |
|
226 | - * |
|
227 | - * @param \Illuminate\Http\Request $request |
|
228 | - * @return \Illuminate\Http\Response |
|
229 | - */ |
|
230 | - public function saveProfile(Request $request) |
|
231 | - { |
|
232 | - foreach ($this->validationRules as &$rule) |
|
233 | - { |
|
234 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
235 | - { |
|
236 | - $rule .= ',deleted_at,NULL'; |
|
237 | - } |
|
224 | + /** |
|
225 | + * Save the given data to the logged in user. |
|
226 | + * |
|
227 | + * @param \Illuminate\Http\Request $request |
|
228 | + * @return \Illuminate\Http\Response |
|
229 | + */ |
|
230 | + public function saveProfile(Request $request) |
|
231 | + { |
|
232 | + foreach ($this->validationRules as &$rule) |
|
233 | + { |
|
234 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
235 | + { |
|
236 | + $rule .= ',deleted_at,NULL'; |
|
237 | + } |
|
238 | 238 | |
239 | - if ($request->has('id')) |
|
240 | - { |
|
241 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
242 | - } |
|
243 | - else |
|
244 | - { |
|
245 | - $rule = str_replace(',{id}', '', $rule); |
|
246 | - } |
|
247 | - } |
|
239 | + if ($request->has('id')) |
|
240 | + { |
|
241 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
242 | + } |
|
243 | + else |
|
244 | + { |
|
245 | + $rule = str_replace(',{id}', '', $rule); |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - $this->validate($request, $this->validationRules); |
|
249 | + $this->validate($request, $this->validationRules); |
|
250 | 250 | |
251 | - if ($this->model) |
|
252 | - { |
|
253 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200); |
|
254 | - } |
|
255 | - } |
|
251 | + if ($this->model) |
|
252 | + { |
|
253 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200); |
|
254 | + } |
|
255 | + } |
|
256 | 256 | } |