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