@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace App\Modules\V1\Acl\Http\Controllers; |
3 | 3 | |
4 | -use Illuminate\Foundation\Http\FormRequest; |
|
5 | 4 | use App\Modules\V1\Core\Http\Controllers\BaseApiController; |
6 | 5 | use App\Modules\V1\Acl\Proxy\LoginProxy; |
7 | 6 | use Illuminate\Http\Request; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * Return the logged in user account. |
58 | 58 | * |
59 | - * @return \Illuminate\Http\Response |
|
59 | + * @return \Illuminate\Http\JsonResponse |
|
60 | 60 | */ |
61 | 61 | public function account() |
62 | 62 | { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * Block the user. |
68 | 68 | * |
69 | 69 | * @param integer $id Id of the user. |
70 | - * @return \Illuminate\Http\Response |
|
70 | + * @return \Illuminate\Http\JsonResponse |
|
71 | 71 | */ |
72 | 72 | public function block($id) |
73 | 73 | { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * Unblock the user. |
79 | 79 | * |
80 | 80 | * @param integer $id Id of the user. |
81 | - * @return \Illuminate\Http\Response |
|
81 | + * @return \Illuminate\Http\JsonResponse |
|
82 | 82 | */ |
83 | 83 | public function unblock($id) |
84 | 84 | { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * Logout the user. |
90 | 90 | * |
91 | - * @return \Illuminate\Http\Response |
|
91 | + * @return \Illuminate\Http\JsonResponse |
|
92 | 92 | */ |
93 | 93 | public function logout() |
94 | 94 | { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * Handle a registration request. |
100 | 100 | * |
101 | 101 | * @param \Illuminate\Http\Request $request |
102 | - * @return \Illuminate\Http\Response |
|
102 | + * @return \Illuminate\Http\JsonResponse |
|
103 | 103 | */ |
104 | 104 | public function register(Request $request) |
105 | 105 | { |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * Handle a login request to the application. |
117 | 117 | * |
118 | 118 | * @param \Illuminate\Http\Request $request |
119 | - * @return \Illuminate\Http\Response |
|
119 | + * @return \Illuminate\Http\JsonResponse |
|
120 | 120 | */ |
121 | 121 | public function login(Request $request) |
122 | 122 | { |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * Handle a social login request of the none admin to the application. |
134 | 134 | * |
135 | 135 | * @param \Illuminate\Http\Request $request |
136 | - * @return \Illuminate\Http\Response |
|
136 | + * @return \Illuminate\Http\JsonResponse |
|
137 | 137 | */ |
138 | 138 | public function loginSocial(Request $request) |
139 | 139 | { |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * Assign the given groups to the given user. |
151 | 151 | * |
152 | 152 | * @param \Illuminate\Http\Request $request |
153 | - * @return \Illuminate\Http\Response |
|
153 | + * @return \Illuminate\Http\JsonResponse |
|
154 | 154 | */ |
155 | 155 | public function assigngroups(Request $request) |
156 | 156 | { |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * Send a reset link to the given user. |
167 | 167 | * |
168 | 168 | * @param \Illuminate\Http\Request $request |
169 | - * @return \Illuminate\Http\Response |
|
169 | + * @return \Illuminate\Http\JsonResponse |
|
170 | 170 | */ |
171 | 171 | public function sendreset(Request $request) |
172 | 172 | { |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * Reset the given user's password. |
180 | 180 | * |
181 | 181 | * @param \Illuminate\Http\Request $request |
182 | - * @return \Illuminate\Http\Response |
|
182 | + * @return \Illuminate\Http\JsonResponse |
|
183 | 183 | */ |
184 | 184 | public function resetpassword(Request $request) |
185 | 185 | { |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * Change the logged in user password. |
198 | 198 | * |
199 | 199 | * @param \Illuminate\Http\Request $request |
200 | - * @return \Illuminate\Http\Response |
|
200 | + * @return \Illuminate\Http\JsonResponse |
|
201 | 201 | */ |
202 | 202 | public function changePassword(Request $request) |
203 | 203 | { |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * Refresh the expired login token. |
215 | 215 | * |
216 | 216 | * @param \Illuminate\Http\Request $request |
217 | - * @return \Illuminate\Http\Response |
|
217 | + * @return \Illuminate\Http\JsonResponse |
|
218 | 218 | */ |
219 | 219 | public function refreshtoken(Request $request) |
220 | 220 | { |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | * @param string $groupName The name of the requested group. |
233 | 233 | * @param integer $perPage Number of rows per page default 15. |
234 | 234 | * @param string $sortBy The name of the column to sort by. |
235 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
236 | - * @return \Illuminate\Http\Response |
|
235 | + * @param integer $desc Sort ascending or descinding (1: desc, 0: asc). |
|
236 | + * @return \Illuminate\Http\JsonResponse |
|
237 | 237 | */ |
238 | 238 | public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
239 | 239 | { |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * Save the given data to the logged in user. |
245 | 245 | * |
246 | 246 | * @param \Illuminate\Http\Request $request |
247 | - * @return \Illuminate\Http\Response |
|
247 | + * @return \Illuminate\Http\JsonResponse|null |
|
248 | 248 | */ |
249 | 249 | public function saveProfile(Request $request) |
250 | 250 | { |
@@ -8,268 +8,268 @@ |
||
8 | 8 | |
9 | 9 | class UsersController extends BaseApiController |
10 | 10 | { |
11 | - /** |
|
12 | - * The name of the model that is used by the base api controller |
|
13 | - * to preform actions like (add, edit ... etc). |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $model = 'users'; |
|
17 | - |
|
18 | - /** |
|
19 | - * List of all route actions that the base api controller |
|
20 | - * will skip permissions check for them. |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword']; |
|
24 | - |
|
25 | - /** |
|
26 | - * List of all route actions that the base api controller |
|
27 | - * will skip login check for them. |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
31 | - |
|
32 | - /** |
|
33 | - * The validations rules used by the base api controller |
|
34 | - * to check before add. |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected $validationRules = [ |
|
38 | - 'name' => 'nullable|string', |
|
39 | - 'email' => 'required|email|unique:users,email,{id}', |
|
40 | - 'password' => 'nullable|min:6' |
|
41 | - ]; |
|
42 | - |
|
43 | - /** |
|
44 | - * The loginProxy implementation. |
|
45 | - * |
|
46 | - * @var \App\Modules\V1\Acl\Proxy\LoginProxy |
|
47 | - */ |
|
48 | - protected $loginProxy; |
|
49 | - |
|
50 | - public function __construct(LoginProxy $loginProxy) |
|
51 | - { |
|
52 | - $this->loginProxy = $loginProxy; |
|
53 | - parent::__construct(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Return the logged in user account. |
|
58 | - * |
|
59 | - * @return \Illuminate\Http\Response |
|
60 | - */ |
|
61 | - public function account() |
|
62 | - { |
|
63 | - return \Response::json($this->repo->account($this->relations), 200); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Block the user. |
|
68 | - * |
|
69 | - * @param integer $id Id of the user. |
|
70 | - * @return \Illuminate\Http\Response |
|
71 | - */ |
|
72 | - public function block($id) |
|
73 | - { |
|
74 | - return \Response::json($this->repo->block($id), 200); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Unblock the user. |
|
79 | - * |
|
80 | - * @param integer $id Id of the user. |
|
81 | - * @return \Illuminate\Http\Response |
|
82 | - */ |
|
83 | - public function unblock($id) |
|
84 | - { |
|
85 | - return \Response::json($this->repo->unblock($id), 200); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Logout the user. |
|
90 | - * |
|
91 | - * @return \Illuminate\Http\Response |
|
92 | - */ |
|
93 | - public function logout() |
|
94 | - { |
|
95 | - return \Response::json($this->loginProxy->logout(), 200); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Handle a registration request. |
|
100 | - * |
|
101 | - * @param \Illuminate\Http\Request $request |
|
102 | - * @return \Illuminate\Http\Response |
|
103 | - */ |
|
104 | - public function register(Request $request) |
|
105 | - { |
|
106 | - $this->validate($request, [ |
|
107 | - 'name' => 'nullable|string', |
|
108 | - 'email' => 'required|email|unique:users,email,{id}', |
|
109 | - 'password' => 'required|min:6' |
|
110 | - ]); |
|
111 | - |
|
112 | - return \Response::json($this->repo->register($request->only('email', 'password')), 200); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Handle a login request to the application. |
|
117 | - * |
|
118 | - * @param \Illuminate\Http\Request $request |
|
119 | - * @return \Illuminate\Http\Response |
|
120 | - */ |
|
121 | - public function login(Request $request) |
|
122 | - { |
|
123 | - $this->validate($request, [ |
|
124 | - 'email' => 'required|email', |
|
125 | - 'password' => 'required|min:6', |
|
126 | - 'admin' => 'boolean' |
|
127 | - ]); |
|
128 | - |
|
129 | - return \Response::json($this->loginProxy->login($request->only('email', 'password'), $request->get('admin')), 200); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Handle a social login request of the none admin to the application. |
|
134 | - * |
|
135 | - * @param \Illuminate\Http\Request $request |
|
136 | - * @return \Illuminate\Http\Response |
|
137 | - */ |
|
138 | - public function loginSocial(Request $request) |
|
139 | - { |
|
140 | - $this->validate($request, [ |
|
141 | - 'auth_code' => 'required_without:access_token', |
|
142 | - 'access_token' => 'required_without:auth_code', |
|
143 | - 'type' => 'required|in:facebook,google' |
|
144 | - ]); |
|
145 | - |
|
146 | - return \Response::json($this->repo->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Assign the given groups to the given user. |
|
151 | - * |
|
152 | - * @param \Illuminate\Http\Request $request |
|
153 | - * @return \Illuminate\Http\Response |
|
154 | - */ |
|
155 | - public function assigngroups(Request $request) |
|
156 | - { |
|
157 | - $this->validate($request, [ |
|
158 | - 'group_ids' => 'required|exists:groups,id', |
|
159 | - 'user_id' => 'required|exists:users,id' |
|
160 | - ]); |
|
161 | - |
|
162 | - return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Send a reset link to the given user. |
|
167 | - * |
|
168 | - * @param \Illuminate\Http\Request $request |
|
169 | - * @return \Illuminate\Http\Response |
|
170 | - */ |
|
171 | - public function sendreset(Request $request) |
|
172 | - { |
|
173 | - $this->validate($request, ['email' => 'required|email']); |
|
174 | - |
|
175 | - return \Response::json($this->repo->sendReset($request->only('email')), 200); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Reset the given user's password. |
|
180 | - * |
|
181 | - * @param \Illuminate\Http\Request $request |
|
182 | - * @return \Illuminate\Http\Response |
|
183 | - */ |
|
184 | - public function resetpassword(Request $request) |
|
185 | - { |
|
186 | - $this->validate($request, [ |
|
187 | - 'token' => 'required', |
|
188 | - 'email' => 'required|email', |
|
189 | - 'password' => 'required|confirmed|min:6', |
|
190 | - 'password_confirmation' => 'required', |
|
191 | - ]); |
|
192 | - |
|
193 | - return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Change the logged in user password. |
|
198 | - * |
|
199 | - * @param \Illuminate\Http\Request $request |
|
200 | - * @return \Illuminate\Http\Response |
|
201 | - */ |
|
202 | - public function changePassword(Request $request) |
|
203 | - { |
|
204 | - $this->validate($request, [ |
|
205 | - 'old_password' => 'required', |
|
206 | - 'password' => 'required|confirmed|min:6', |
|
207 | - 'password_confirmation' => 'required', |
|
208 | - ]); |
|
209 | - |
|
210 | - return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Refresh the expired login token. |
|
215 | - * |
|
216 | - * @param \Illuminate\Http\Request $request |
|
217 | - * @return \Illuminate\Http\Response |
|
218 | - */ |
|
219 | - public function refreshtoken(Request $request) |
|
220 | - { |
|
221 | - $this->validate($request, [ |
|
222 | - 'refreshtoken' => 'required', |
|
223 | - ]); |
|
224 | - |
|
225 | - return \Response::json($this->loginProxy->refreshtoken($request->only('refreshtoken')), 200); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Paginate all users with inthe given group. |
|
230 | - * |
|
231 | - * @param \Illuminate\Http\Request $request |
|
232 | - * @param string $groupName The name of the requested group. |
|
233 | - * @param integer $perPage Number of rows per page default 15. |
|
234 | - * @param string $sortBy The name of the column to sort by. |
|
235 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
236 | - * @return \Illuminate\Http\Response |
|
237 | - */ |
|
238 | - public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
239 | - { |
|
240 | - return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Save the given data to the logged in user. |
|
245 | - * |
|
246 | - * @param \Illuminate\Http\Request $request |
|
247 | - * @return \Illuminate\Http\Response |
|
248 | - */ |
|
249 | - public function saveProfile(Request $request) |
|
250 | - { |
|
251 | - foreach ($this->validationRules as &$rule) |
|
252 | - { |
|
253 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
254 | - { |
|
255 | - $rule .= ',deleted_at,NULL'; |
|
256 | - } |
|
257 | - |
|
258 | - if ($request->has('id')) |
|
259 | - { |
|
260 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
261 | - } |
|
262 | - else |
|
263 | - { |
|
264 | - $rule = str_replace(',{id}', '', $rule); |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - $this->validate($request, $this->validationRules); |
|
269 | - |
|
270 | - if ($this->model) |
|
271 | - { |
|
272 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200); |
|
273 | - } |
|
274 | - } |
|
11 | + /** |
|
12 | + * The name of the model that is used by the base api controller |
|
13 | + * to preform actions like (add, edit ... etc). |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $model = 'users'; |
|
17 | + |
|
18 | + /** |
|
19 | + * List of all route actions that the base api controller |
|
20 | + * will skip permissions check for them. |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword']; |
|
24 | + |
|
25 | + /** |
|
26 | + * List of all route actions that the base api controller |
|
27 | + * will skip login check for them. |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
31 | + |
|
32 | + /** |
|
33 | + * The validations rules used by the base api controller |
|
34 | + * to check before add. |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected $validationRules = [ |
|
38 | + 'name' => 'nullable|string', |
|
39 | + 'email' => 'required|email|unique:users,email,{id}', |
|
40 | + 'password' => 'nullable|min:6' |
|
41 | + ]; |
|
42 | + |
|
43 | + /** |
|
44 | + * The loginProxy implementation. |
|
45 | + * |
|
46 | + * @var \App\Modules\V1\Acl\Proxy\LoginProxy |
|
47 | + */ |
|
48 | + protected $loginProxy; |
|
49 | + |
|
50 | + public function __construct(LoginProxy $loginProxy) |
|
51 | + { |
|
52 | + $this->loginProxy = $loginProxy; |
|
53 | + parent::__construct(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Return the logged in user account. |
|
58 | + * |
|
59 | + * @return \Illuminate\Http\Response |
|
60 | + */ |
|
61 | + public function account() |
|
62 | + { |
|
63 | + return \Response::json($this->repo->account($this->relations), 200); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Block the user. |
|
68 | + * |
|
69 | + * @param integer $id Id of the user. |
|
70 | + * @return \Illuminate\Http\Response |
|
71 | + */ |
|
72 | + public function block($id) |
|
73 | + { |
|
74 | + return \Response::json($this->repo->block($id), 200); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Unblock the user. |
|
79 | + * |
|
80 | + * @param integer $id Id of the user. |
|
81 | + * @return \Illuminate\Http\Response |
|
82 | + */ |
|
83 | + public function unblock($id) |
|
84 | + { |
|
85 | + return \Response::json($this->repo->unblock($id), 200); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Logout the user. |
|
90 | + * |
|
91 | + * @return \Illuminate\Http\Response |
|
92 | + */ |
|
93 | + public function logout() |
|
94 | + { |
|
95 | + return \Response::json($this->loginProxy->logout(), 200); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Handle a registration request. |
|
100 | + * |
|
101 | + * @param \Illuminate\Http\Request $request |
|
102 | + * @return \Illuminate\Http\Response |
|
103 | + */ |
|
104 | + public function register(Request $request) |
|
105 | + { |
|
106 | + $this->validate($request, [ |
|
107 | + 'name' => 'nullable|string', |
|
108 | + 'email' => 'required|email|unique:users,email,{id}', |
|
109 | + 'password' => 'required|min:6' |
|
110 | + ]); |
|
111 | + |
|
112 | + return \Response::json($this->repo->register($request->only('email', 'password')), 200); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Handle a login request to the application. |
|
117 | + * |
|
118 | + * @param \Illuminate\Http\Request $request |
|
119 | + * @return \Illuminate\Http\Response |
|
120 | + */ |
|
121 | + public function login(Request $request) |
|
122 | + { |
|
123 | + $this->validate($request, [ |
|
124 | + 'email' => 'required|email', |
|
125 | + 'password' => 'required|min:6', |
|
126 | + 'admin' => 'boolean' |
|
127 | + ]); |
|
128 | + |
|
129 | + return \Response::json($this->loginProxy->login($request->only('email', 'password'), $request->get('admin')), 200); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Handle a social login request of the none admin to the application. |
|
134 | + * |
|
135 | + * @param \Illuminate\Http\Request $request |
|
136 | + * @return \Illuminate\Http\Response |
|
137 | + */ |
|
138 | + public function loginSocial(Request $request) |
|
139 | + { |
|
140 | + $this->validate($request, [ |
|
141 | + 'auth_code' => 'required_without:access_token', |
|
142 | + 'access_token' => 'required_without:auth_code', |
|
143 | + 'type' => 'required|in:facebook,google' |
|
144 | + ]); |
|
145 | + |
|
146 | + return \Response::json($this->repo->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Assign the given groups to the given user. |
|
151 | + * |
|
152 | + * @param \Illuminate\Http\Request $request |
|
153 | + * @return \Illuminate\Http\Response |
|
154 | + */ |
|
155 | + public function assigngroups(Request $request) |
|
156 | + { |
|
157 | + $this->validate($request, [ |
|
158 | + 'group_ids' => 'required|exists:groups,id', |
|
159 | + 'user_id' => 'required|exists:users,id' |
|
160 | + ]); |
|
161 | + |
|
162 | + return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Send a reset link to the given user. |
|
167 | + * |
|
168 | + * @param \Illuminate\Http\Request $request |
|
169 | + * @return \Illuminate\Http\Response |
|
170 | + */ |
|
171 | + public function sendreset(Request $request) |
|
172 | + { |
|
173 | + $this->validate($request, ['email' => 'required|email']); |
|
174 | + |
|
175 | + return \Response::json($this->repo->sendReset($request->only('email')), 200); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Reset the given user's password. |
|
180 | + * |
|
181 | + * @param \Illuminate\Http\Request $request |
|
182 | + * @return \Illuminate\Http\Response |
|
183 | + */ |
|
184 | + public function resetpassword(Request $request) |
|
185 | + { |
|
186 | + $this->validate($request, [ |
|
187 | + 'token' => 'required', |
|
188 | + 'email' => 'required|email', |
|
189 | + 'password' => 'required|confirmed|min:6', |
|
190 | + 'password_confirmation' => 'required', |
|
191 | + ]); |
|
192 | + |
|
193 | + return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Change the logged in user password. |
|
198 | + * |
|
199 | + * @param \Illuminate\Http\Request $request |
|
200 | + * @return \Illuminate\Http\Response |
|
201 | + */ |
|
202 | + public function changePassword(Request $request) |
|
203 | + { |
|
204 | + $this->validate($request, [ |
|
205 | + 'old_password' => 'required', |
|
206 | + 'password' => 'required|confirmed|min:6', |
|
207 | + 'password_confirmation' => 'required', |
|
208 | + ]); |
|
209 | + |
|
210 | + return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Refresh the expired login token. |
|
215 | + * |
|
216 | + * @param \Illuminate\Http\Request $request |
|
217 | + * @return \Illuminate\Http\Response |
|
218 | + */ |
|
219 | + public function refreshtoken(Request $request) |
|
220 | + { |
|
221 | + $this->validate($request, [ |
|
222 | + 'refreshtoken' => 'required', |
|
223 | + ]); |
|
224 | + |
|
225 | + return \Response::json($this->loginProxy->refreshtoken($request->only('refreshtoken')), 200); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Paginate all users with inthe given group. |
|
230 | + * |
|
231 | + * @param \Illuminate\Http\Request $request |
|
232 | + * @param string $groupName The name of the requested group. |
|
233 | + * @param integer $perPage Number of rows per page default 15. |
|
234 | + * @param string $sortBy The name of the column to sort by. |
|
235 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
236 | + * @return \Illuminate\Http\Response |
|
237 | + */ |
|
238 | + public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
239 | + { |
|
240 | + return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Save the given data to the logged in user. |
|
245 | + * |
|
246 | + * @param \Illuminate\Http\Request $request |
|
247 | + * @return \Illuminate\Http\Response |
|
248 | + */ |
|
249 | + public function saveProfile(Request $request) |
|
250 | + { |
|
251 | + foreach ($this->validationRules as &$rule) |
|
252 | + { |
|
253 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
254 | + { |
|
255 | + $rule .= ',deleted_at,NULL'; |
|
256 | + } |
|
257 | + |
|
258 | + if ($request->has('id')) |
|
259 | + { |
|
260 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
261 | + } |
|
262 | + else |
|
263 | + { |
|
264 | + $rule = str_replace(',{id}', '', $rule); |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + $this->validate($request, $this->validationRules); |
|
269 | + |
|
270 | + if ($this->model) |
|
271 | + { |
|
272 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200); |
|
273 | + } |
|
274 | + } |
|
275 | 275 | } |
@@ -7,89 +7,89 @@ |
||
7 | 7 | |
8 | 8 | class AclUser extends User { |
9 | 9 | |
10 | - use SoftDeletes, HasApiTokens; |
|
11 | - protected $table = 'users'; |
|
12 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
13 | - protected $hidden = ['password', 'remember_token','deleted_at', 'two_factor_code']; |
|
14 | - protected $guarded = ['id']; |
|
15 | - protected $fillable = ['name', 'email', 'password']; |
|
16 | - public $searchable = ['name', 'email']; |
|
10 | + use SoftDeletes, HasApiTokens; |
|
11 | + protected $table = 'users'; |
|
12 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
13 | + protected $hidden = ['password', 'remember_token','deleted_at', 'two_factor_code']; |
|
14 | + protected $guarded = ['id']; |
|
15 | + protected $fillable = ['name', 'email', 'password']; |
|
16 | + public $searchable = ['name', 'email']; |
|
17 | 17 | |
18 | - public function getCreatedAtAttribute($value) |
|
19 | - { |
|
20 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21 | - } |
|
18 | + public function getCreatedAtAttribute($value) |
|
19 | + { |
|
20 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21 | + } |
|
22 | 22 | |
23 | - public function getUpdatedAtAttribute($value) |
|
24 | - { |
|
25 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
26 | - } |
|
23 | + public function getUpdatedAtAttribute($value) |
|
24 | + { |
|
25 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
26 | + } |
|
27 | 27 | |
28 | - public function getDeletedAtAttribute($value) |
|
29 | - { |
|
30 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
31 | - } |
|
28 | + public function getDeletedAtAttribute($value) |
|
29 | + { |
|
30 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Encrypt the password attribute before |
|
35 | - * saving it in the storage. |
|
36 | - * |
|
37 | - * @param string $value |
|
38 | - */ |
|
39 | - public function setPasswordAttribute($value) |
|
40 | - { |
|
41 | - $this->attributes['password'] = bcrypt($value); |
|
42 | - } |
|
33 | + /** |
|
34 | + * Encrypt the password attribute before |
|
35 | + * saving it in the storage. |
|
36 | + * |
|
37 | + * @param string $value |
|
38 | + */ |
|
39 | + public function setPasswordAttribute($value) |
|
40 | + { |
|
41 | + $this->attributes['password'] = bcrypt($value); |
|
42 | + } |
|
43 | 43 | |
44 | - public function groups() |
|
45 | - { |
|
46 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
47 | - } |
|
44 | + public function groups() |
|
45 | + { |
|
46 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Return fcm device tokens related to the user. |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - public function routeNotificationForFCM() |
|
54 | - { |
|
55 | - $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
56 | - $tokens = []; |
|
49 | + /** |
|
50 | + * Return fcm device tokens related to the user. |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + public function routeNotificationForFCM() |
|
54 | + { |
|
55 | + $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
56 | + $tokens = []; |
|
57 | 57 | |
58 | - foreach ($devices as $device) |
|
59 | - { |
|
60 | - $accessToken = decrypt($device->access_token); |
|
58 | + foreach ($devices as $device) |
|
59 | + { |
|
60 | + $accessToken = decrypt($device->access_token); |
|
61 | 61 | |
62 | - try |
|
63 | - { |
|
64 | - if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
65 | - { |
|
66 | - continue; |
|
67 | - } |
|
62 | + try |
|
63 | + { |
|
64 | + if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
65 | + { |
|
66 | + continue; |
|
67 | + } |
|
68 | 68 | |
69 | - $tokens[] = $device->device_token; |
|
70 | - } |
|
71 | - catch (\Exception $e) |
|
72 | - { |
|
73 | - $device->forceDelete(); |
|
74 | - } |
|
75 | - } |
|
69 | + $tokens[] = $device->device_token; |
|
70 | + } |
|
71 | + catch (\Exception $e) |
|
72 | + { |
|
73 | + $device->forceDelete(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - return $tokens; |
|
78 | - } |
|
77 | + return $tokens; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * The channels the user receives notification broadcasts on. |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function receivesBroadcastNotificationsOn() |
|
86 | - { |
|
87 | - return 'users.' . $this->id; |
|
88 | - } |
|
80 | + /** |
|
81 | + * The channels the user receives notification broadcasts on. |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function receivesBroadcastNotificationsOn() |
|
86 | + { |
|
87 | + return 'users.' . $this->id; |
|
88 | + } |
|
89 | 89 | |
90 | - public static function boot() |
|
91 | - { |
|
92 | - parent::boot(); |
|
93 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
94 | - } |
|
90 | + public static function boot() |
|
91 | + { |
|
92 | + parent::boot(); |
|
93 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
94 | + } |
|
95 | 95 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | use SoftDeletes, HasApiTokens; |
11 | 11 | protected $table = 'users'; |
12 | 12 | protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
13 | - protected $hidden = ['password', 'remember_token','deleted_at', 'two_factor_code']; |
|
13 | + protected $hidden = ['password', 'remember_token', 'deleted_at', 'two_factor_code']; |
|
14 | 14 | protected $guarded = ['id']; |
15 | 15 | protected $fillable = ['name', 'email', 'password']; |
16 | 16 | public $searchable = ['name', 'email']; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | public function groups() |
45 | 45 | { |
46 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
46 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function receivesBroadcastNotificationsOn() |
86 | 86 | { |
87 | - return 'users.' . $this->id; |
|
87 | + return 'users.'.$this->id; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | public static function boot() |
@@ -14,27 +14,27 @@ |
||
14 | 14 | return 'App\Modules\V1\Acl\OauthClient'; |
15 | 15 | } |
16 | 16 | |
17 | - /** |
|
18 | - * Revoke the given client. |
|
19 | - * |
|
20 | - * @param integer $clientId |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function revoke($clientId) |
|
24 | - { |
|
25 | - $client = $this->find($clientId); |
|
26 | - $client->tokens()->update(['revoked' => true]); |
|
27 | - $client->forceFill(['revoked' => true])->save(); |
|
28 | - } |
|
17 | + /** |
|
18 | + * Revoke the given client. |
|
19 | + * |
|
20 | + * @param integer $clientId |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function revoke($clientId) |
|
24 | + { |
|
25 | + $client = $this->find($clientId); |
|
26 | + $client->tokens()->update(['revoked' => true]); |
|
27 | + $client->forceFill(['revoked' => true])->save(); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Regenerate seceret for the given client. |
|
32 | - * |
|
33 | - * @param integer $clientId |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function regenerateSecret($clientId) |
|
37 | - { |
|
30 | + /** |
|
31 | + * Regenerate seceret for the given client. |
|
32 | + * |
|
33 | + * @param integer $clientId |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function regenerateSecret($clientId) |
|
37 | + { |
|
38 | 38 | $this->update($clientId, ['secret' => str_random(40)]); |
39 | - } |
|
39 | + } |
|
40 | 40 | } |
@@ -5,355 +5,355 @@ |
||
5 | 5 | |
6 | 6 | class UserRepository extends AbstractRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Return the model full namespace. |
|
10 | - * |
|
11 | - * @return string |
|
12 | - */ |
|
13 | - protected function getModel() |
|
14 | - { |
|
15 | - return 'App\Modules\V1\Acl\AclUser'; |
|
16 | - } |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * Return the logged in user account. |
|
21 | - * |
|
22 | - * @param array $relations |
|
23 | - * @return boolean |
|
24 | - */ |
|
25 | - public function account($relations = []) |
|
26 | - { |
|
27 | - $permissions = []; |
|
28 | - $user = \Core::users()->find(\Auth::id(), $relations); |
|
29 | - foreach ($user->groups()->get() as $group) |
|
30 | - { |
|
31 | - $group->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 boolean $user |
|
47 | - * @return boolean |
|
48 | - */ |
|
49 | - public function can($nameOfPermission, $model, $user = false) |
|
50 | - { |
|
51 | - $user = $user ?: $this->find(\Auth::id(), ['groups.permissions']); |
|
52 | - $permissions = []; |
|
53 | - |
|
54 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
55 | - $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
56 | - }); |
|
8 | + /** |
|
9 | + * Return the model full namespace. |
|
10 | + * |
|
11 | + * @return string |
|
12 | + */ |
|
13 | + protected function getModel() |
|
14 | + { |
|
15 | + return 'App\Modules\V1\Acl\AclUser'; |
|
16 | + } |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * Return the logged in user account. |
|
21 | + * |
|
22 | + * @param array $relations |
|
23 | + * @return boolean |
|
24 | + */ |
|
25 | + public function account($relations = []) |
|
26 | + { |
|
27 | + $permissions = []; |
|
28 | + $user = \Core::users()->find(\Auth::id(), $relations); |
|
29 | + foreach ($user->groups()->get() as $group) |
|
30 | + { |
|
31 | + $group->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 boolean $user |
|
47 | + * @return boolean |
|
48 | + */ |
|
49 | + public function can($nameOfPermission, $model, $user = false) |
|
50 | + { |
|
51 | + $user = $user ?: $this->find(\Auth::id(), ['groups.permissions']); |
|
52 | + $permissions = []; |
|
53 | + |
|
54 | + $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
55 | + $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
56 | + }); |
|
57 | 57 | |
58 | - return in_array($nameOfPermission, $permissions); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Check if the logged in user has the given group. |
|
63 | - * |
|
64 | - * @param string $groupName |
|
65 | - * @param integer $userId |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function hasGroup($groupName, $userId = false) |
|
69 | - { |
|
70 | - $userId = $userId ?: \Auth::id(); |
|
71 | - $groups = $this->find($userId)->groups; |
|
72 | - return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Assign the given group ids to the given user. |
|
77 | - * |
|
78 | - * @param integer $user_id |
|
79 | - * @param array $group_ids |
|
80 | - * @return object |
|
81 | - */ |
|
82 | - public function assignGroups($user_id, $group_ids) |
|
83 | - { |
|
84 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
85 | - $user = $this->find($user_id); |
|
86 | - $user->groups()->detach(); |
|
87 | - $user->groups()->attach($group_ids); |
|
88 | - }); |
|
89 | - |
|
90 | - return $this->find($user_id); |
|
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 | - { |
|
104 | - \ErrorHandler::loginFailed(); |
|
105 | - } |
|
106 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
107 | - { |
|
108 | - \ErrorHandler::loginFailed(); |
|
109 | - } |
|
110 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
111 | - { |
|
112 | - \ErrorHandler::loginFailed(); |
|
113 | - } |
|
114 | - else if ($user->blocked) |
|
115 | - { |
|
116 | - \ErrorHandler::userIsBlocked(); |
|
117 | - } |
|
118 | - |
|
119 | - return $user; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Handle a social login request of the none admin to the application. |
|
124 | - * |
|
125 | - * @param array $credentials |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public function loginSocial($credentials) |
|
129 | - { |
|
130 | - $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
131 | - $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
132 | - |
|
133 | - if ( ! $user->email) |
|
134 | - { |
|
135 | - \ErrorHandler::noSocialEmail(); |
|
136 | - } |
|
137 | - |
|
138 | - if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
139 | - { |
|
140 | - $data = ['email' => $user->email, 'password' => '']; |
|
141 | - return $this->register($data); |
|
142 | - } |
|
143 | - else |
|
144 | - { |
|
145 | - if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
146 | - { |
|
147 | - \ErrorHandler::userAlreadyRegistered(); |
|
148 | - } |
|
149 | - |
|
150 | - $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
151 | - return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0); |
|
152 | - } |
|
153 | - } |
|
58 | + return in_array($nameOfPermission, $permissions); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Check if the logged in user has the given group. |
|
63 | + * |
|
64 | + * @param string $groupName |
|
65 | + * @param integer $userId |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function hasGroup($groupName, $userId = false) |
|
69 | + { |
|
70 | + $userId = $userId ?: \Auth::id(); |
|
71 | + $groups = $this->find($userId)->groups; |
|
72 | + return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Assign the given group ids to the given user. |
|
77 | + * |
|
78 | + * @param integer $user_id |
|
79 | + * @param array $group_ids |
|
80 | + * @return object |
|
81 | + */ |
|
82 | + public function assignGroups($user_id, $group_ids) |
|
83 | + { |
|
84 | + \DB::transaction(function () use ($user_id, $group_ids) { |
|
85 | + $user = $this->find($user_id); |
|
86 | + $user->groups()->detach(); |
|
87 | + $user->groups()->attach($group_ids); |
|
88 | + }); |
|
89 | + |
|
90 | + return $this->find($user_id); |
|
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 | + { |
|
104 | + \ErrorHandler::loginFailed(); |
|
105 | + } |
|
106 | + else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
107 | + { |
|
108 | + \ErrorHandler::loginFailed(); |
|
109 | + } |
|
110 | + else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
111 | + { |
|
112 | + \ErrorHandler::loginFailed(); |
|
113 | + } |
|
114 | + else if ($user->blocked) |
|
115 | + { |
|
116 | + \ErrorHandler::userIsBlocked(); |
|
117 | + } |
|
118 | + |
|
119 | + return $user; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Handle a social login request of the none admin to the application. |
|
124 | + * |
|
125 | + * @param array $credentials |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public function loginSocial($credentials) |
|
129 | + { |
|
130 | + $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
131 | + $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
132 | + |
|
133 | + if ( ! $user->email) |
|
134 | + { |
|
135 | + \ErrorHandler::noSocialEmail(); |
|
136 | + } |
|
137 | + |
|
138 | + if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
139 | + { |
|
140 | + $data = ['email' => $user->email, 'password' => '']; |
|
141 | + return $this->register($data); |
|
142 | + } |
|
143 | + else |
|
144 | + { |
|
145 | + if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
146 | + { |
|
147 | + \ErrorHandler::userAlreadyRegistered(); |
|
148 | + } |
|
149 | + |
|
150 | + $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
151 | + return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0); |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * Handle a registration request. |
|
157 | - * |
|
158 | - * @param array $credentials |
|
159 | - * @return array |
|
160 | - */ |
|
161 | - public function register($credentials) |
|
162 | - { |
|
163 | - $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
164 | - $this->model->create($credentials); |
|
165 | - |
|
166 | - return $loginProxy->login($credentials, 0); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Block the user. |
|
171 | - * |
|
172 | - * @param integer $user_id |
|
173 | - * @return object |
|
174 | - */ |
|
175 | - public function block($user_id) |
|
176 | - { |
|
177 | - if ( ! $user = $this->find($user_id)) |
|
178 | - { |
|
179 | - \ErrorHandler::notFound('user'); |
|
180 | - } |
|
181 | - if ( ! $this->hasGroup('Admin')) |
|
182 | - { |
|
183 | - \ErrorHandler::noPermissions(); |
|
184 | - } |
|
185 | - else if (\Auth::id() == $user_id) |
|
186 | - { |
|
187 | - \ErrorHandler::noPermissions(); |
|
188 | - } |
|
189 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
190 | - { |
|
191 | - \ErrorHandler::noPermissions(); |
|
192 | - } |
|
193 | - |
|
194 | - $user->blocked = 1; |
|
195 | - $user->save(); |
|
155 | + /** |
|
156 | + * Handle a registration request. |
|
157 | + * |
|
158 | + * @param array $credentials |
|
159 | + * @return array |
|
160 | + */ |
|
161 | + public function register($credentials) |
|
162 | + { |
|
163 | + $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
164 | + $this->model->create($credentials); |
|
165 | + |
|
166 | + return $loginProxy->login($credentials, 0); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Block the user. |
|
171 | + * |
|
172 | + * @param integer $user_id |
|
173 | + * @return object |
|
174 | + */ |
|
175 | + public function block($user_id) |
|
176 | + { |
|
177 | + if ( ! $user = $this->find($user_id)) |
|
178 | + { |
|
179 | + \ErrorHandler::notFound('user'); |
|
180 | + } |
|
181 | + if ( ! $this->hasGroup('Admin')) |
|
182 | + { |
|
183 | + \ErrorHandler::noPermissions(); |
|
184 | + } |
|
185 | + else if (\Auth::id() == $user_id) |
|
186 | + { |
|
187 | + \ErrorHandler::noPermissions(); |
|
188 | + } |
|
189 | + else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
190 | + { |
|
191 | + \ErrorHandler::noPermissions(); |
|
192 | + } |
|
193 | + |
|
194 | + $user->blocked = 1; |
|
195 | + $user->save(); |
|
196 | 196 | |
197 | - return $user; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Unblock the user. |
|
202 | - * |
|
203 | - * @param integer $user_id |
|
204 | - * @return object |
|
205 | - */ |
|
206 | - public function unblock($user_id) |
|
207 | - { |
|
208 | - if ( ! $this->hasGroup('Admin')) |
|
209 | - { |
|
210 | - \ErrorHandler::noPermissions(); |
|
211 | - } |
|
212 | - |
|
213 | - $user = $this->find($user_id); |
|
214 | - $user->blocked = 0; |
|
215 | - $user->save(); |
|
216 | - |
|
217 | - return $user; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Send a reset link to the given user. |
|
222 | - * |
|
223 | - * @param string $email |
|
224 | - * @return void |
|
225 | - */ |
|
226 | - public function sendReset($email) |
|
227 | - { |
|
228 | - if ( ! $user = $this->model->where('email', $email)->first()) |
|
229 | - { |
|
230 | - \ErrorHandler::notFound('email'); |
|
231 | - } |
|
232 | - |
|
233 | - $url = $this->config['resetLink']; |
|
234 | - $token = \Password::getRepository()->create($user); |
|
197 | + return $user; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Unblock the user. |
|
202 | + * |
|
203 | + * @param integer $user_id |
|
204 | + * @return object |
|
205 | + */ |
|
206 | + public function unblock($user_id) |
|
207 | + { |
|
208 | + if ( ! $this->hasGroup('Admin')) |
|
209 | + { |
|
210 | + \ErrorHandler::noPermissions(); |
|
211 | + } |
|
212 | + |
|
213 | + $user = $this->find($user_id); |
|
214 | + $user->blocked = 0; |
|
215 | + $user->save(); |
|
216 | + |
|
217 | + return $user; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Send a reset link to the given user. |
|
222 | + * |
|
223 | + * @param string $email |
|
224 | + * @return void |
|
225 | + */ |
|
226 | + public function sendReset($email) |
|
227 | + { |
|
228 | + if ( ! $user = $this->model->where('email', $email)->first()) |
|
229 | + { |
|
230 | + \ErrorHandler::notFound('email'); |
|
231 | + } |
|
232 | + |
|
233 | + $url = $this->config['resetLink']; |
|
234 | + $token = \Password::getRepository()->create($user); |
|
235 | 235 | |
236 | - \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
237 | - $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
|
238 | - }); |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Reset the given user's password. |
|
243 | - * |
|
244 | - * @param array $credentials |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - public function resetPassword($credentials) |
|
248 | - { |
|
249 | - $response = \Password::reset($credentials, function ($user, $password) { |
|
250 | - $user->password = $password; |
|
251 | - $user->save(); |
|
252 | - }); |
|
253 | - |
|
254 | - switch ($response) { |
|
255 | - case \Password::PASSWORD_RESET: |
|
256 | - return 'success'; |
|
236 | + \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
237 | + $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
|
238 | + }); |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Reset the given user's password. |
|
243 | + * |
|
244 | + * @param array $credentials |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + public function resetPassword($credentials) |
|
248 | + { |
|
249 | + $response = \Password::reset($credentials, function ($user, $password) { |
|
250 | + $user->password = $password; |
|
251 | + $user->save(); |
|
252 | + }); |
|
253 | + |
|
254 | + switch ($response) { |
|
255 | + case \Password::PASSWORD_RESET: |
|
256 | + return 'success'; |
|
257 | 257 | |
258 | - case \Password::INVALID_TOKEN: |
|
259 | - \ErrorHandler::invalidResetToken('token'); |
|
260 | - |
|
261 | - case \Password::INVALID_PASSWORD: |
|
262 | - \ErrorHandler::invalidResetPassword('email'); |
|
263 | - |
|
264 | - case \Password::INVALID_USER: |
|
265 | - \ErrorHandler::notFound('user'); |
|
266 | - |
|
267 | - default: |
|
268 | - \ErrorHandler::generalError(); |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Change the logged in user password. |
|
274 | - * |
|
275 | - * @param array $credentials |
|
276 | - * @return void |
|
277 | - */ |
|
278 | - public function changePassword($credentials) |
|
279 | - { |
|
280 | - $user = \Auth::user(); |
|
281 | - if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
282 | - { |
|
283 | - \ErrorHandler::invalidOldPassword(); |
|
284 | - } |
|
285 | - |
|
286 | - $user->password = $credentials['password']; |
|
287 | - $user->save(); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Paginate all users in the given group based on the given conditions. |
|
292 | - * |
|
293 | - * @param string $groupName |
|
294 | - * @param array $relations |
|
295 | - * @param integer $perPage |
|
296 | - * @param string $sortBy |
|
297 | - * @param boolean $desc |
|
298 | - * @return \Illuminate\Http\Response |
|
299 | - */ |
|
300 | - public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
301 | - { |
|
302 | - unset($conditions['page']); |
|
303 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
304 | - $sort = $desc ? 'desc' : 'asc'; |
|
305 | - $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
306 | - |
|
307 | - $model->whereHas('groups', function($q) use ($groupName){ |
|
308 | - $q->where('name', $groupName); |
|
309 | - }); |
|
258 | + case \Password::INVALID_TOKEN: |
|
259 | + \ErrorHandler::invalidResetToken('token'); |
|
260 | + |
|
261 | + case \Password::INVALID_PASSWORD: |
|
262 | + \ErrorHandler::invalidResetPassword('email'); |
|
263 | + |
|
264 | + case \Password::INVALID_USER: |
|
265 | + \ErrorHandler::notFound('user'); |
|
266 | + |
|
267 | + default: |
|
268 | + \ErrorHandler::generalError(); |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Change the logged in user password. |
|
274 | + * |
|
275 | + * @param array $credentials |
|
276 | + * @return void |
|
277 | + */ |
|
278 | + public function changePassword($credentials) |
|
279 | + { |
|
280 | + $user = \Auth::user(); |
|
281 | + if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
282 | + { |
|
283 | + \ErrorHandler::invalidOldPassword(); |
|
284 | + } |
|
285 | + |
|
286 | + $user->password = $credentials['password']; |
|
287 | + $user->save(); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Paginate all users in the given group based on the given conditions. |
|
292 | + * |
|
293 | + * @param string $groupName |
|
294 | + * @param array $relations |
|
295 | + * @param integer $perPage |
|
296 | + * @param string $sortBy |
|
297 | + * @param boolean $desc |
|
298 | + * @return \Illuminate\Http\Response |
|
299 | + */ |
|
300 | + public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
301 | + { |
|
302 | + unset($conditions['page']); |
|
303 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
304 | + $sort = $desc ? 'desc' : 'asc'; |
|
305 | + $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
306 | + |
|
307 | + $model->whereHas('groups', function($q) use ($groupName){ |
|
308 | + $q->where('name', $groupName); |
|
309 | + }); |
|
310 | 310 | |
311 | 311 | |
312 | - if (count($conditions['conditionValues'])) |
|
313 | - { |
|
314 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
315 | - } |
|
316 | - |
|
317 | - if ($perPage) |
|
318 | - { |
|
319 | - return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
320 | - } |
|
321 | - |
|
322 | - return $model->orderBy($sortBy, $sort)->get(); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Save the given data to the logged in user. |
|
327 | - * |
|
328 | - * @param array $credentials |
|
329 | - * @return object |
|
330 | - */ |
|
331 | - public function saveProfile($credentials) |
|
332 | - { |
|
333 | - $user = \Auth::user(); |
|
334 | - $user->save($credentials); |
|
335 | - |
|
336 | - return $user; |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Ensure access token hasn't expired or revoked. |
|
341 | - * |
|
342 | - * @param string $accessToken |
|
343 | - * @return boolean |
|
344 | - */ |
|
345 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
346 | - { |
|
347 | - |
|
348 | - $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface'); |
|
349 | - $data = new ValidationData(); |
|
350 | - $data->setCurrentTime(time()); |
|
351 | - |
|
352 | - if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) |
|
353 | - { |
|
354 | - return true; |
|
355 | - } |
|
356 | - |
|
357 | - return false; |
|
358 | - } |
|
312 | + if (count($conditions['conditionValues'])) |
|
313 | + { |
|
314 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
315 | + } |
|
316 | + |
|
317 | + if ($perPage) |
|
318 | + { |
|
319 | + return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
320 | + } |
|
321 | + |
|
322 | + return $model->orderBy($sortBy, $sort)->get(); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Save the given data to the logged in user. |
|
327 | + * |
|
328 | + * @param array $credentials |
|
329 | + * @return object |
|
330 | + */ |
|
331 | + public function saveProfile($credentials) |
|
332 | + { |
|
333 | + $user = \Auth::user(); |
|
334 | + $user->save($credentials); |
|
335 | + |
|
336 | + return $user; |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Ensure access token hasn't expired or revoked. |
|
341 | + * |
|
342 | + * @param string $accessToken |
|
343 | + * @return boolean |
|
344 | + */ |
|
345 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
346 | + { |
|
347 | + |
|
348 | + $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface'); |
|
349 | + $data = new ValidationData(); |
|
350 | + $data->setCurrentTime(time()); |
|
351 | + |
|
352 | + if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) |
|
353 | + { |
|
354 | + return true; |
|
355 | + } |
|
356 | + |
|
357 | + return false; |
|
358 | + } |
|
359 | 359 | } |
@@ -13,30 +13,30 @@ |
||
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->string('two_factor_code', 4)->nullable(); |
|
23 | - $table->softDeletes(); |
|
24 | - $table->rememberToken(); |
|
25 | - $table->timestamps(); |
|
26 | - }); |
|
22 | + $table->string('two_factor_code', 4)->nullable(); |
|
23 | + $table->softDeletes(); |
|
24 | + $table->rememberToken(); |
|
25 | + $table->timestamps(); |
|
26 | + }); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Create Default users. |
30 | 30 | */ |
31 | 31 | \DB::table('users')->insertGetId( |
32 | - [ |
|
32 | + [ |
|
33 | 33 | 'name' => 'Admin', |
34 | 34 | 'email' => '[email protected]', |
35 | 35 | 'password' => bcrypt('123456'), |
36 | 36 | 'created_at' => \DB::raw('NOW()'), |
37 | 37 | 'updated_at' => \DB::raw('NOW()') |
38 | 38 | ] |
39 | - ); |
|
39 | + ); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -13,21 +13,21 @@ discard block |
||
13 | 13 | public function up() |
14 | 14 | { |
15 | 15 | Schema::create('groups', function (Blueprint $table) { |
16 | - $table->increments('id'); |
|
17 | - $table->string('name',100)->unique(); |
|
18 | - $table->softDeletes(); |
|
19 | - $table->timestamps(); |
|
20 | - }); |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name',100)->unique(); |
|
18 | + $table->softDeletes(); |
|
19 | + $table->timestamps(); |
|
20 | + }); |
|
21 | 21 | |
22 | - Schema::create('users_groups', function (Blueprint $table) { |
|
23 | - $table->increments('id'); |
|
24 | - $table->integer('user_id'); |
|
25 | - $table->integer('group_id'); |
|
26 | - $table->softDeletes(); |
|
27 | - $table->timestamps(); |
|
22 | + Schema::create('users_groups', function (Blueprint $table) { |
|
23 | + $table->increments('id'); |
|
24 | + $table->integer('user_id'); |
|
25 | + $table->integer('group_id'); |
|
26 | + $table->softDeletes(); |
|
27 | + $table->timestamps(); |
|
28 | 28 | |
29 | - $table->index(['user_id']); |
|
30 | - }); |
|
29 | + $table->index(['user_id']); |
|
30 | + }); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Create Default groups. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'created_at' => \DB::raw('NOW()'), |
55 | 55 | 'updated_at' => \DB::raw('NOW()') |
56 | 56 | ] |
57 | - ); |
|
57 | + ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -6,94 +6,94 @@ |
||
6 | 6 | |
7 | 7 | class GroupsTableSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - /** |
|
17 | - * Insert the permissions related to groups table. |
|
18 | - */ |
|
19 | - \DB::table('permissions')->insert( |
|
20 | - [ |
|
21 | - /** |
|
22 | - * Groups model permissions. |
|
23 | - */ |
|
24 | - [ |
|
25 | - 'name' => 'save', |
|
26 | - 'model' => 'groups', |
|
27 | - 'created_at' => \DB::raw('NOW()'), |
|
28 | - 'updated_at' => \DB::raw('NOW()') |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'delete', |
|
32 | - 'model' => 'groups', |
|
33 | - 'created_at' => \DB::raw('NOW()'), |
|
34 | - 'updated_at' => \DB::raw('NOW()') |
|
35 | - ], |
|
36 | - [ |
|
37 | - 'name' => 'find', |
|
38 | - 'model' => 'groups', |
|
39 | - 'created_at' => \DB::raw('NOW()'), |
|
40 | - 'updated_at' => \DB::raw('NOW()') |
|
41 | - ], |
|
42 | - [ |
|
43 | - 'name' => 'search', |
|
44 | - 'model' => 'groups', |
|
45 | - 'created_at' => \DB::raw('NOW()'), |
|
46 | - 'updated_at' => \DB::raw('NOW()') |
|
47 | - ], |
|
48 | - [ |
|
49 | - 'name' => 'list', |
|
50 | - 'model' => 'groups', |
|
51 | - 'created_at' => \DB::raw('NOW()'), |
|
52 | - 'updated_at' => \DB::raw('NOW()') |
|
53 | - ], |
|
54 | - [ |
|
55 | - 'name' => 'findby', |
|
56 | - 'model' => 'groups', |
|
57 | - 'created_at' => \DB::raw('NOW()'), |
|
58 | - 'updated_at' => \DB::raw('NOW()') |
|
59 | - ], |
|
60 | - [ |
|
61 | - 'name' => 'first', |
|
62 | - 'model' => 'groups', |
|
63 | - 'created_at' => \DB::raw('NOW()'), |
|
64 | - 'updated_at' => \DB::raw('NOW()') |
|
65 | - ], |
|
66 | - [ |
|
67 | - 'name' => 'paginate', |
|
68 | - 'model' => 'groups', |
|
69 | - 'created_at' => \DB::raw('NOW()'), |
|
70 | - 'updated_at' => \DB::raw('NOW()') |
|
71 | - ], |
|
72 | - [ |
|
73 | - 'name' => 'paginateby', |
|
74 | - 'model' => 'groups', |
|
75 | - 'created_at' => \DB::raw('NOW()'), |
|
76 | - 'updated_at' => \DB::raw('NOW()') |
|
77 | - ], |
|
78 | - [ |
|
79 | - 'name' => 'assignpermissions', |
|
80 | - 'model' => 'groups', |
|
81 | - 'created_at' => \DB::raw('NOW()'), |
|
82 | - 'updated_at' => \DB::raw('NOW()') |
|
83 | - ], |
|
84 | - [ |
|
85 | - 'name' => 'deleted', |
|
86 | - 'model' => 'groups', |
|
87 | - 'created_at' => \DB::raw('NOW()'), |
|
88 | - 'updated_at' => \DB::raw('NOW()') |
|
89 | - ], |
|
90 | - [ |
|
91 | - 'name' => 'restore', |
|
92 | - 'model' => 'groups', |
|
93 | - 'created_at' => \DB::raw('NOW()'), |
|
94 | - 'updated_at' => \DB::raw('NOW()') |
|
95 | - ] |
|
96 | - ] |
|
97 | - ); |
|
98 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + /** |
|
17 | + * Insert the permissions related to groups table. |
|
18 | + */ |
|
19 | + \DB::table('permissions')->insert( |
|
20 | + [ |
|
21 | + /** |
|
22 | + * Groups model permissions. |
|
23 | + */ |
|
24 | + [ |
|
25 | + 'name' => 'save', |
|
26 | + 'model' => 'groups', |
|
27 | + 'created_at' => \DB::raw('NOW()'), |
|
28 | + 'updated_at' => \DB::raw('NOW()') |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'delete', |
|
32 | + 'model' => 'groups', |
|
33 | + 'created_at' => \DB::raw('NOW()'), |
|
34 | + 'updated_at' => \DB::raw('NOW()') |
|
35 | + ], |
|
36 | + [ |
|
37 | + 'name' => 'find', |
|
38 | + 'model' => 'groups', |
|
39 | + 'created_at' => \DB::raw('NOW()'), |
|
40 | + 'updated_at' => \DB::raw('NOW()') |
|
41 | + ], |
|
42 | + [ |
|
43 | + 'name' => 'search', |
|
44 | + 'model' => 'groups', |
|
45 | + 'created_at' => \DB::raw('NOW()'), |
|
46 | + 'updated_at' => \DB::raw('NOW()') |
|
47 | + ], |
|
48 | + [ |
|
49 | + 'name' => 'list', |
|
50 | + 'model' => 'groups', |
|
51 | + 'created_at' => \DB::raw('NOW()'), |
|
52 | + 'updated_at' => \DB::raw('NOW()') |
|
53 | + ], |
|
54 | + [ |
|
55 | + 'name' => 'findby', |
|
56 | + 'model' => 'groups', |
|
57 | + 'created_at' => \DB::raw('NOW()'), |
|
58 | + 'updated_at' => \DB::raw('NOW()') |
|
59 | + ], |
|
60 | + [ |
|
61 | + 'name' => 'first', |
|
62 | + 'model' => 'groups', |
|
63 | + 'created_at' => \DB::raw('NOW()'), |
|
64 | + 'updated_at' => \DB::raw('NOW()') |
|
65 | + ], |
|
66 | + [ |
|
67 | + 'name' => 'paginate', |
|
68 | + 'model' => 'groups', |
|
69 | + 'created_at' => \DB::raw('NOW()'), |
|
70 | + 'updated_at' => \DB::raw('NOW()') |
|
71 | + ], |
|
72 | + [ |
|
73 | + 'name' => 'paginateby', |
|
74 | + 'model' => 'groups', |
|
75 | + 'created_at' => \DB::raw('NOW()'), |
|
76 | + 'updated_at' => \DB::raw('NOW()') |
|
77 | + ], |
|
78 | + [ |
|
79 | + 'name' => 'assignpermissions', |
|
80 | + 'model' => 'groups', |
|
81 | + 'created_at' => \DB::raw('NOW()'), |
|
82 | + 'updated_at' => \DB::raw('NOW()') |
|
83 | + ], |
|
84 | + [ |
|
85 | + 'name' => 'deleted', |
|
86 | + 'model' => 'groups', |
|
87 | + 'created_at' => \DB::raw('NOW()'), |
|
88 | + 'updated_at' => \DB::raw('NOW()') |
|
89 | + ], |
|
90 | + [ |
|
91 | + 'name' => 'restore', |
|
92 | + 'model' => 'groups', |
|
93 | + 'created_at' => \DB::raw('NOW()'), |
|
94 | + 'updated_at' => \DB::raw('NOW()') |
|
95 | + ] |
|
96 | + ] |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | } |
@@ -6,112 +6,112 @@ |
||
6 | 6 | |
7 | 7 | class UsersTableSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - /** |
|
17 | - * Insert the permissions related to users table. |
|
18 | - */ |
|
19 | - \DB::table('permissions')->insert( |
|
20 | - [ |
|
21 | - /** |
|
22 | - * Users model permissions. |
|
23 | - */ |
|
24 | - [ |
|
25 | - 'name' => 'save', |
|
26 | - 'model' => 'users', |
|
27 | - 'created_at' => \DB::raw('NOW()'), |
|
28 | - 'updated_at' => \DB::raw('NOW()') |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'delete', |
|
32 | - 'model' => 'users', |
|
33 | - 'created_at' => \DB::raw('NOW()'), |
|
34 | - 'updated_at' => \DB::raw('NOW()') |
|
35 | - ], |
|
36 | - [ |
|
37 | - 'name' => 'find', |
|
38 | - 'model' => 'users', |
|
39 | - 'created_at' => \DB::raw('NOW()'), |
|
40 | - 'updated_at' => \DB::raw('NOW()') |
|
41 | - ], |
|
42 | - [ |
|
43 | - 'name' => 'list', |
|
44 | - 'model' => 'users', |
|
45 | - 'created_at' => \DB::raw('NOW()'), |
|
46 | - 'updated_at' => \DB::raw('NOW()') |
|
47 | - ], |
|
48 | - [ |
|
49 | - 'name' => 'search', |
|
50 | - 'model' => 'users', |
|
51 | - 'created_at' => \DB::raw('NOW()'), |
|
52 | - 'updated_at' => \DB::raw('NOW()') |
|
53 | - ], |
|
54 | - [ |
|
55 | - 'name' => 'findby', |
|
56 | - 'model' => 'users', |
|
57 | - 'created_at' => \DB::raw('NOW()'), |
|
58 | - 'updated_at' => \DB::raw('NOW()') |
|
59 | - ], |
|
60 | - [ |
|
61 | - 'name' => 'first', |
|
62 | - 'model' => 'users', |
|
63 | - 'created_at' => \DB::raw('NOW()'), |
|
64 | - 'updated_at' => \DB::raw('NOW()') |
|
65 | - ], |
|
66 | - [ |
|
67 | - 'name' => 'paginate', |
|
68 | - 'model' => 'users', |
|
69 | - 'created_at' => \DB::raw('NOW()'), |
|
70 | - 'updated_at' => \DB::raw('NOW()') |
|
71 | - ], |
|
72 | - [ |
|
73 | - 'name' => 'paginateby', |
|
74 | - 'model' => 'users', |
|
75 | - 'created_at' => \DB::raw('NOW()'), |
|
76 | - 'updated_at' => \DB::raw('NOW()') |
|
77 | - ], |
|
78 | - [ |
|
79 | - 'name' => 'assigngroups', |
|
80 | - 'model' => 'users', |
|
81 | - 'created_at' => \DB::raw('NOW()'), |
|
82 | - 'updated_at' => \DB::raw('NOW()') |
|
83 | - ], |
|
84 | - [ |
|
85 | - 'name' => 'block', |
|
86 | - 'model' => 'users', |
|
87 | - 'created_at' => \DB::raw('NOW()'), |
|
88 | - 'updated_at' => \DB::raw('NOW()') |
|
89 | - ], |
|
90 | - [ |
|
91 | - 'name' => 'unblock', |
|
92 | - 'model' => 'users', |
|
93 | - 'created_at' => \DB::raw('NOW()'), |
|
94 | - 'updated_at' => \DB::raw('NOW()') |
|
95 | - ], |
|
96 | - [ |
|
97 | - 'name' => 'group', |
|
98 | - 'model' => 'users', |
|
99 | - 'created_at' => \DB::raw('NOW()'), |
|
100 | - 'updated_at' => \DB::raw('NOW()') |
|
101 | - ], |
|
102 | - [ |
|
103 | - 'name' => 'deleted', |
|
104 | - 'model' => 'users', |
|
105 | - 'created_at' => \DB::raw('NOW()'), |
|
106 | - 'updated_at' => \DB::raw('NOW()') |
|
107 | - ], |
|
108 | - [ |
|
109 | - 'name' => 'restore', |
|
110 | - 'model' => 'users', |
|
111 | - 'created_at' => \DB::raw('NOW()'), |
|
112 | - 'updated_at' => \DB::raw('NOW()') |
|
113 | - ] |
|
114 | - ] |
|
115 | - ); |
|
116 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + /** |
|
17 | + * Insert the permissions related to users table. |
|
18 | + */ |
|
19 | + \DB::table('permissions')->insert( |
|
20 | + [ |
|
21 | + /** |
|
22 | + * Users model permissions. |
|
23 | + */ |
|
24 | + [ |
|
25 | + 'name' => 'save', |
|
26 | + 'model' => 'users', |
|
27 | + 'created_at' => \DB::raw('NOW()'), |
|
28 | + 'updated_at' => \DB::raw('NOW()') |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'delete', |
|
32 | + 'model' => 'users', |
|
33 | + 'created_at' => \DB::raw('NOW()'), |
|
34 | + 'updated_at' => \DB::raw('NOW()') |
|
35 | + ], |
|
36 | + [ |
|
37 | + 'name' => 'find', |
|
38 | + 'model' => 'users', |
|
39 | + 'created_at' => \DB::raw('NOW()'), |
|
40 | + 'updated_at' => \DB::raw('NOW()') |
|
41 | + ], |
|
42 | + [ |
|
43 | + 'name' => 'list', |
|
44 | + 'model' => 'users', |
|
45 | + 'created_at' => \DB::raw('NOW()'), |
|
46 | + 'updated_at' => \DB::raw('NOW()') |
|
47 | + ], |
|
48 | + [ |
|
49 | + 'name' => 'search', |
|
50 | + 'model' => 'users', |
|
51 | + 'created_at' => \DB::raw('NOW()'), |
|
52 | + 'updated_at' => \DB::raw('NOW()') |
|
53 | + ], |
|
54 | + [ |
|
55 | + 'name' => 'findby', |
|
56 | + 'model' => 'users', |
|
57 | + 'created_at' => \DB::raw('NOW()'), |
|
58 | + 'updated_at' => \DB::raw('NOW()') |
|
59 | + ], |
|
60 | + [ |
|
61 | + 'name' => 'first', |
|
62 | + 'model' => 'users', |
|
63 | + 'created_at' => \DB::raw('NOW()'), |
|
64 | + 'updated_at' => \DB::raw('NOW()') |
|
65 | + ], |
|
66 | + [ |
|
67 | + 'name' => 'paginate', |
|
68 | + 'model' => 'users', |
|
69 | + 'created_at' => \DB::raw('NOW()'), |
|
70 | + 'updated_at' => \DB::raw('NOW()') |
|
71 | + ], |
|
72 | + [ |
|
73 | + 'name' => 'paginateby', |
|
74 | + 'model' => 'users', |
|
75 | + 'created_at' => \DB::raw('NOW()'), |
|
76 | + 'updated_at' => \DB::raw('NOW()') |
|
77 | + ], |
|
78 | + [ |
|
79 | + 'name' => 'assigngroups', |
|
80 | + 'model' => 'users', |
|
81 | + 'created_at' => \DB::raw('NOW()'), |
|
82 | + 'updated_at' => \DB::raw('NOW()') |
|
83 | + ], |
|
84 | + [ |
|
85 | + 'name' => 'block', |
|
86 | + 'model' => 'users', |
|
87 | + 'created_at' => \DB::raw('NOW()'), |
|
88 | + 'updated_at' => \DB::raw('NOW()') |
|
89 | + ], |
|
90 | + [ |
|
91 | + 'name' => 'unblock', |
|
92 | + 'model' => 'users', |
|
93 | + 'created_at' => \DB::raw('NOW()'), |
|
94 | + 'updated_at' => \DB::raw('NOW()') |
|
95 | + ], |
|
96 | + [ |
|
97 | + 'name' => 'group', |
|
98 | + 'model' => 'users', |
|
99 | + 'created_at' => \DB::raw('NOW()'), |
|
100 | + 'updated_at' => \DB::raw('NOW()') |
|
101 | + ], |
|
102 | + [ |
|
103 | + 'name' => 'deleted', |
|
104 | + 'model' => 'users', |
|
105 | + 'created_at' => \DB::raw('NOW()'), |
|
106 | + 'updated_at' => \DB::raw('NOW()') |
|
107 | + ], |
|
108 | + [ |
|
109 | + 'name' => 'restore', |
|
110 | + 'model' => 'users', |
|
111 | + 'created_at' => \DB::raw('NOW()'), |
|
112 | + 'updated_at' => \DB::raw('NOW()') |
|
113 | + ] |
|
114 | + ] |
|
115 | + ); |
|
116 | + } |
|
117 | 117 | } |
@@ -6,20 +6,20 @@ discard block |
||
6 | 6 | |
7 | 7 | class AssignRelationsSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id; |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id; |
|
17 | 17 | |
18 | - /** |
|
18 | + /** |
|
19 | 19 | * Assign the permissions to the admin group. |
20 | 20 | */ |
21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups', 'oauthClients'])->each(function ($permission) use ($adminGroupId) { |
|
22 | - \DB::table('groups_permissions')->insert( |
|
21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups', 'oauthClients'])->each(function ($permission) use ($adminGroupId) { |
|
22 | + \DB::table('groups_permissions')->insert( |
|
23 | 23 | [ |
24 | 24 | 'permission_id' => $permission->id, |
25 | 25 | 'group_id' => $adminGroupId, |
@@ -27,6 +27,6 @@ discard block |
||
27 | 27 | 'updated_at' => \DB::raw('NOW()') |
28 | 28 | ] |
29 | 29 | ); |
30 | - }); |
|
31 | - } |
|
30 | + }); |
|
31 | + } |
|
32 | 32 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | /** |
19 | 19 | * Assign the permissions to the admin group. |
20 | 20 | */ |
21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups', 'oauthClients'])->each(function ($permission) use ($adminGroupId) { |
|
21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups', 'oauthClients'])->each(function($permission) use ($adminGroupId) { |
|
22 | 22 | \DB::table('groups_permissions')->insert( |
23 | 23 | [ |
24 | 24 | 'permission_id' => $permission->id, |