@@ -6,82 +6,82 @@ |
||
6 | 6 | |
7 | 7 | class Kernel extends HttpKernel |
8 | 8 | { |
9 | - /** |
|
10 | - * The application's global HTTP middleware stack. |
|
11 | - * |
|
12 | - * These middleware are run during every request to your application. |
|
13 | - * |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $middleware = [ |
|
17 | - \Fruitcake\Cors\HandleCors::class, |
|
18 | - \App\Http\Middleware\TrustProxies::class, |
|
19 | - \App\Http\Middleware\CheckForMaintenanceMode::class, |
|
20 | - \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, |
|
21 | - \App\Http\Middleware\TrimStrings::class, |
|
22 | - \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, |
|
23 | - ]; |
|
9 | + /** |
|
10 | + * The application's global HTTP middleware stack. |
|
11 | + * |
|
12 | + * These middleware are run during every request to your application. |
|
13 | + * |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $middleware = [ |
|
17 | + \Fruitcake\Cors\HandleCors::class, |
|
18 | + \App\Http\Middleware\TrustProxies::class, |
|
19 | + \App\Http\Middleware\CheckForMaintenanceMode::class, |
|
20 | + \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, |
|
21 | + \App\Http\Middleware\TrimStrings::class, |
|
22 | + \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, |
|
23 | + ]; |
|
24 | 24 | |
25 | - /** |
|
26 | - * The application's route middleware groups. |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $middlewareGroups = [ |
|
31 | - 'web' => [ |
|
32 | - \App\Http\Middleware\EncryptCookies::class, |
|
33 | - \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, |
|
34 | - \Illuminate\Session\Middleware\StartSession::class, |
|
35 | - // \Illuminate\Session\Middleware\AuthenticateSession::class, |
|
36 | - \Illuminate\View\Middleware\ShareErrorsFromSession::class, |
|
37 | - \App\Http\Middleware\VerifyCsrfToken::class, |
|
38 | - \Illuminate\Routing\Middleware\SubstituteBindings::class, |
|
39 | - ], |
|
25 | + /** |
|
26 | + * The application's route middleware groups. |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $middlewareGroups = [ |
|
31 | + 'web' => [ |
|
32 | + \App\Http\Middleware\EncryptCookies::class, |
|
33 | + \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, |
|
34 | + \Illuminate\Session\Middleware\StartSession::class, |
|
35 | + // \Illuminate\Session\Middleware\AuthenticateSession::class, |
|
36 | + \Illuminate\View\Middleware\ShareErrorsFromSession::class, |
|
37 | + \App\Http\Middleware\VerifyCsrfToken::class, |
|
38 | + \Illuminate\Routing\Middleware\SubstituteBindings::class, |
|
39 | + ], |
|
40 | 40 | |
41 | - 'api' => [ |
|
42 | - 'throttle:60,1', |
|
43 | - \Illuminate\Routing\Middleware\SubstituteBindings::class, |
|
44 | - \App\Modules\Core\Http\Middleware\SetSessions::class, |
|
45 | - \App\Modules\Core\Http\Middleware\CheckPermissions::class, |
|
46 | - \App\Modules\Core\Http\Middleware\UpdateLocaleAndTimezone::class, |
|
47 | - \App\Modules\Core\Http\Middleware\SetRelations::class, |
|
48 | - ], |
|
49 | - ]; |
|
41 | + 'api' => [ |
|
42 | + 'throttle:60,1', |
|
43 | + \Illuminate\Routing\Middleware\SubstituteBindings::class, |
|
44 | + \App\Modules\Core\Http\Middleware\SetSessions::class, |
|
45 | + \App\Modules\Core\Http\Middleware\CheckPermissions::class, |
|
46 | + \App\Modules\Core\Http\Middleware\UpdateLocaleAndTimezone::class, |
|
47 | + \App\Modules\Core\Http\Middleware\SetRelations::class, |
|
48 | + ], |
|
49 | + ]; |
|
50 | 50 | |
51 | - /** |
|
52 | - * The application's route middleware. |
|
53 | - * |
|
54 | - * These middleware may be assigned to groups or used individually. |
|
55 | - * |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - protected $routeMiddleware = [ |
|
59 | - 'auth' => \App\Http\Middleware\Authenticate::class, |
|
60 | - 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, |
|
61 | - 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, |
|
62 | - 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, |
|
63 | - 'can' => \Illuminate\Auth\Middleware\Authorize::class, |
|
64 | - 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, |
|
65 | - 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, |
|
66 | - 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, |
|
67 | - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, |
|
68 | - 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, |
|
69 | - ]; |
|
51 | + /** |
|
52 | + * The application's route middleware. |
|
53 | + * |
|
54 | + * These middleware may be assigned to groups or used individually. |
|
55 | + * |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + protected $routeMiddleware = [ |
|
59 | + 'auth' => \App\Http\Middleware\Authenticate::class, |
|
60 | + 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, |
|
61 | + 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, |
|
62 | + 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, |
|
63 | + 'can' => \Illuminate\Auth\Middleware\Authorize::class, |
|
64 | + 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, |
|
65 | + 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, |
|
66 | + 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, |
|
67 | + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, |
|
68 | + 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, |
|
69 | + ]; |
|
70 | 70 | |
71 | - /** |
|
72 | - * The priority-sorted list of middleware. |
|
73 | - * |
|
74 | - * This forces non-global middleware to always be in the given order. |
|
75 | - * |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - protected $middlewarePriority = [ |
|
79 | - \Illuminate\Session\Middleware\StartSession::class, |
|
80 | - \Illuminate\View\Middleware\ShareErrorsFromSession::class, |
|
81 | - \App\Http\Middleware\Authenticate::class, |
|
82 | - \Illuminate\Routing\Middleware\ThrottleRequests::class, |
|
83 | - \Illuminate\Session\Middleware\AuthenticateSession::class, |
|
84 | - \Illuminate\Routing\Middleware\SubstituteBindings::class, |
|
85 | - \Illuminate\Auth\Middleware\Authorize::class, |
|
86 | - ]; |
|
71 | + /** |
|
72 | + * The priority-sorted list of middleware. |
|
73 | + * |
|
74 | + * This forces non-global middleware to always be in the given order. |
|
75 | + * |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + protected $middlewarePriority = [ |
|
79 | + \Illuminate\Session\Middleware\StartSession::class, |
|
80 | + \Illuminate\View\Middleware\ShareErrorsFromSession::class, |
|
81 | + \App\Http\Middleware\Authenticate::class, |
|
82 | + \Illuminate\Routing\Middleware\ThrottleRequests::class, |
|
83 | + \Illuminate\Session\Middleware\AuthenticateSession::class, |
|
84 | + \Illuminate\Routing\Middleware\SubstituteBindings::class, |
|
85 | + \Illuminate\Auth\Middleware\Authorize::class, |
|
86 | + ]; |
|
87 | 87 | } |
@@ -12,360 +12,360 @@ |
||
12 | 12 | |
13 | 13 | class UserService extends BaseService |
14 | 14 | { |
15 | - /** |
|
16 | - * @var PermissionService |
|
17 | - */ |
|
18 | - protected $permissionService; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var LoginProxy |
|
22 | - */ |
|
23 | - protected $loginProxy; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var NotificationService |
|
27 | - */ |
|
28 | - protected $notificationService; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var OauthClientService |
|
32 | - */ |
|
33 | - protected $oauthClientService; |
|
34 | - |
|
35 | - /** |
|
36 | - * Init new object. |
|
37 | - * |
|
38 | - * @param UserRepository $repo |
|
39 | - * @param PermissionService $permissionService |
|
40 | - * @param LoginProxy $loginProxy |
|
41 | - * @param NotificationService $notificationService |
|
42 | - * @param OauthClientService $oauthClientService |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - UserRepository $repo, |
|
47 | - PermissionService $permissionService, |
|
48 | - LoginProxy $loginProxy, |
|
49 | - NotificationService $notificationService, |
|
50 | - OauthClientService $oauthClientService |
|
51 | - ) { |
|
52 | - $this->permissionService = $permissionService; |
|
53 | - $this->loginProxy = $loginProxy; |
|
54 | - $this->notificationService = $notificationService; |
|
55 | - $this->oauthClientService = $oauthClientService; |
|
56 | - parent::__construct($repo); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Return the logged in user account. |
|
61 | - * |
|
62 | - * @param array $relations |
|
63 | - * @return boolean |
|
64 | - */ |
|
65 | - public function account($relations = ['roles.permissions']) |
|
66 | - { |
|
67 | - $permissions = []; |
|
68 | - $user = $this->repo->find(\Auth::id(), $relations); |
|
69 | - foreach ($user->roles as $role) { |
|
70 | - $role->permissions->each(function ($permission) use (&$permissions) { |
|
71 | - $permissions[$permission->repo][$permission->id] = $permission->name; |
|
72 | - }); |
|
73 | - } |
|
74 | - $user->permissions = $permissions; |
|
75 | - |
|
76 | - return $user; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Check if the logged in user or the given user |
|
81 | - * has the given permissions on the given model. |
|
82 | - * |
|
83 | - * @param string $permissionName |
|
84 | - * @param string $model |
|
85 | - * @param mixed $userId |
|
86 | - * @return boolean |
|
87 | - */ |
|
88 | - public function can($permissionName, $model, $userId = false) |
|
89 | - { |
|
90 | - $permission = $this->permissionService->first([ |
|
91 | - 'and' => [ |
|
92 | - 'model' => $model, |
|
93 | - 'name' => $permissionName, |
|
94 | - 'roles' => [ |
|
95 | - 'op' => 'has', |
|
96 | - 'val' => [ |
|
97 | - 'users' => [ |
|
98 | - 'op' => 'has', |
|
99 | - 'val' => [ |
|
100 | - 'users.id' => $userId ?: \Auth::id() |
|
101 | - ] |
|
102 | - ] |
|
103 | - ] |
|
104 | - ] |
|
105 | - ] |
|
106 | - ]); |
|
107 | - |
|
108 | - return $permission ? true : false; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Check if the logged in or the given user has the given role. |
|
113 | - * |
|
114 | - * @param string[] $roles |
|
115 | - * @param mixed $user |
|
116 | - * @return boolean |
|
117 | - */ |
|
118 | - public function hasRoles($roles, $user = false) |
|
119 | - { |
|
120 | - return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Assign the given role ids to the given user. |
|
125 | - * |
|
126 | - * @param integer $userId |
|
127 | - * @param array $roleIds |
|
128 | - * @return object |
|
129 | - */ |
|
130 | - public function assignRoles($userId, $roleIds) |
|
131 | - { |
|
132 | - $user = false; |
|
133 | - \DB::transaction(function () use ($userId, $roleIds, &$user) { |
|
134 | - $user = $this->repo->find($userId); |
|
135 | - $this->repo->detachRoles($user); |
|
136 | - $this->repo->attachRoles($user, $roleIds); |
|
137 | - }); |
|
138 | - |
|
139 | - return $user; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Handle the login request to the application. |
|
144 | - * |
|
145 | - * @param string $email |
|
146 | - * @param string $password |
|
147 | - * @return object |
|
148 | - */ |
|
149 | - public function login($email, $password) |
|
150 | - { |
|
151 | - if (! $user = $this->repo->first(['email' => $email])) { |
|
152 | - \Errors::loginFailed(); |
|
153 | - } elseif ($user->blocked) { |
|
154 | - \Errors::userIsBlocked(); |
|
155 | - } elseif (! config('user.disable_confirm_email') && ! $user->confirmed) { |
|
156 | - \Errors::emailNotConfirmed(); |
|
157 | - } |
|
158 | - |
|
159 | - return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)]; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Handle the social login request to the application. |
|
164 | - * |
|
165 | - * @param string $authCode |
|
166 | - * @param string $accessToken |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - public function loginSocial($authCode, $accessToken, $type) |
|
170 | - { |
|
171 | - $accessToken = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
|
172 | - $user = \Socialite::driver($type)->userFromToken($accessToken)->user; |
|
173 | - |
|
174 | - if (! \Arr::has($user, 'email')) { |
|
175 | - \Errors::noSocialEmail(); |
|
176 | - } |
|
177 | - |
|
178 | - if (! $this->repo->first(['email' => $user['email']])) { |
|
179 | - $this->register($user['name'], $user['email'], '', true); |
|
180 | - } |
|
181 | - |
|
182 | - return $this->login($user['email'], config('user.social_pass')); |
|
183 | - } |
|
184 | - /** |
|
185 | - * Handle the registration request. |
|
186 | - * |
|
187 | - * @param array $data |
|
188 | - * @param boolean $skipConfirmEmail |
|
189 | - * @param integer $roleId |
|
190 | - * @return object |
|
191 | - */ |
|
192 | - public function register($data, $skipConfirmEmail = false, $roleId = false) |
|
193 | - { |
|
194 | - $data['confirmed'] = $skipConfirmEmail; |
|
195 | - |
|
196 | - if($roleId){ |
|
197 | - $data ['roles'] = [['id' => $roleId]]; |
|
198 | - } |
|
199 | - |
|
200 | - $user = $this->repo->save($data); |
|
201 | - |
|
202 | - if (! $skipConfirmEmail && ! config('user.disable_confirm_email')) { |
|
203 | - $this->sendConfirmationEmail($user->email); |
|
204 | - } |
|
205 | - |
|
206 | - return $user; |
|
207 | - } |
|
15 | + /** |
|
16 | + * @var PermissionService |
|
17 | + */ |
|
18 | + protected $permissionService; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var LoginProxy |
|
22 | + */ |
|
23 | + protected $loginProxy; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var NotificationService |
|
27 | + */ |
|
28 | + protected $notificationService; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var OauthClientService |
|
32 | + */ |
|
33 | + protected $oauthClientService; |
|
34 | + |
|
35 | + /** |
|
36 | + * Init new object. |
|
37 | + * |
|
38 | + * @param UserRepository $repo |
|
39 | + * @param PermissionService $permissionService |
|
40 | + * @param LoginProxy $loginProxy |
|
41 | + * @param NotificationService $notificationService |
|
42 | + * @param OauthClientService $oauthClientService |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + UserRepository $repo, |
|
47 | + PermissionService $permissionService, |
|
48 | + LoginProxy $loginProxy, |
|
49 | + NotificationService $notificationService, |
|
50 | + OauthClientService $oauthClientService |
|
51 | + ) { |
|
52 | + $this->permissionService = $permissionService; |
|
53 | + $this->loginProxy = $loginProxy; |
|
54 | + $this->notificationService = $notificationService; |
|
55 | + $this->oauthClientService = $oauthClientService; |
|
56 | + parent::__construct($repo); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Return the logged in user account. |
|
61 | + * |
|
62 | + * @param array $relations |
|
63 | + * @return boolean |
|
64 | + */ |
|
65 | + public function account($relations = ['roles.permissions']) |
|
66 | + { |
|
67 | + $permissions = []; |
|
68 | + $user = $this->repo->find(\Auth::id(), $relations); |
|
69 | + foreach ($user->roles as $role) { |
|
70 | + $role->permissions->each(function ($permission) use (&$permissions) { |
|
71 | + $permissions[$permission->repo][$permission->id] = $permission->name; |
|
72 | + }); |
|
73 | + } |
|
74 | + $user->permissions = $permissions; |
|
75 | + |
|
76 | + return $user; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Check if the logged in user or the given user |
|
81 | + * has the given permissions on the given model. |
|
82 | + * |
|
83 | + * @param string $permissionName |
|
84 | + * @param string $model |
|
85 | + * @param mixed $userId |
|
86 | + * @return boolean |
|
87 | + */ |
|
88 | + public function can($permissionName, $model, $userId = false) |
|
89 | + { |
|
90 | + $permission = $this->permissionService->first([ |
|
91 | + 'and' => [ |
|
92 | + 'model' => $model, |
|
93 | + 'name' => $permissionName, |
|
94 | + 'roles' => [ |
|
95 | + 'op' => 'has', |
|
96 | + 'val' => [ |
|
97 | + 'users' => [ |
|
98 | + 'op' => 'has', |
|
99 | + 'val' => [ |
|
100 | + 'users.id' => $userId ?: \Auth::id() |
|
101 | + ] |
|
102 | + ] |
|
103 | + ] |
|
104 | + ] |
|
105 | + ] |
|
106 | + ]); |
|
107 | + |
|
108 | + return $permission ? true : false; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Check if the logged in or the given user has the given role. |
|
113 | + * |
|
114 | + * @param string[] $roles |
|
115 | + * @param mixed $user |
|
116 | + * @return boolean |
|
117 | + */ |
|
118 | + public function hasRoles($roles, $user = false) |
|
119 | + { |
|
120 | + return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Assign the given role ids to the given user. |
|
125 | + * |
|
126 | + * @param integer $userId |
|
127 | + * @param array $roleIds |
|
128 | + * @return object |
|
129 | + */ |
|
130 | + public function assignRoles($userId, $roleIds) |
|
131 | + { |
|
132 | + $user = false; |
|
133 | + \DB::transaction(function () use ($userId, $roleIds, &$user) { |
|
134 | + $user = $this->repo->find($userId); |
|
135 | + $this->repo->detachRoles($user); |
|
136 | + $this->repo->attachRoles($user, $roleIds); |
|
137 | + }); |
|
138 | + |
|
139 | + return $user; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Handle the login request to the application. |
|
144 | + * |
|
145 | + * @param string $email |
|
146 | + * @param string $password |
|
147 | + * @return object |
|
148 | + */ |
|
149 | + public function login($email, $password) |
|
150 | + { |
|
151 | + if (! $user = $this->repo->first(['email' => $email])) { |
|
152 | + \Errors::loginFailed(); |
|
153 | + } elseif ($user->blocked) { |
|
154 | + \Errors::userIsBlocked(); |
|
155 | + } elseif (! config('user.disable_confirm_email') && ! $user->confirmed) { |
|
156 | + \Errors::emailNotConfirmed(); |
|
157 | + } |
|
158 | + |
|
159 | + return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)]; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Handle the social login request to the application. |
|
164 | + * |
|
165 | + * @param string $authCode |
|
166 | + * @param string $accessToken |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + public function loginSocial($authCode, $accessToken, $type) |
|
170 | + { |
|
171 | + $accessToken = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
|
172 | + $user = \Socialite::driver($type)->userFromToken($accessToken)->user; |
|
173 | + |
|
174 | + if (! \Arr::has($user, 'email')) { |
|
175 | + \Errors::noSocialEmail(); |
|
176 | + } |
|
177 | + |
|
178 | + if (! $this->repo->first(['email' => $user['email']])) { |
|
179 | + $this->register($user['name'], $user['email'], '', true); |
|
180 | + } |
|
181 | + |
|
182 | + return $this->login($user['email'], config('user.social_pass')); |
|
183 | + } |
|
184 | + /** |
|
185 | + * Handle the registration request. |
|
186 | + * |
|
187 | + * @param array $data |
|
188 | + * @param boolean $skipConfirmEmail |
|
189 | + * @param integer $roleId |
|
190 | + * @return object |
|
191 | + */ |
|
192 | + public function register($data, $skipConfirmEmail = false, $roleId = false) |
|
193 | + { |
|
194 | + $data['confirmed'] = $skipConfirmEmail; |
|
195 | + |
|
196 | + if($roleId){ |
|
197 | + $data ['roles'] = [['id' => $roleId]]; |
|
198 | + } |
|
199 | + |
|
200 | + $user = $this->repo->save($data); |
|
201 | + |
|
202 | + if (! $skipConfirmEmail && ! config('user.disable_confirm_email')) { |
|
203 | + $this->sendConfirmationEmail($user->email); |
|
204 | + } |
|
205 | + |
|
206 | + return $user; |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Block the user. |
|
211 | - * |
|
212 | - * @param integer $userId |
|
213 | - * @return object |
|
214 | - */ |
|
215 | - public function block($userId) |
|
216 | - { |
|
217 | - if (\Auth::id() == $userId) { |
|
218 | - \Errors::noPermissions(); |
|
219 | - } |
|
209 | + /** |
|
210 | + * Block the user. |
|
211 | + * |
|
212 | + * @param integer $userId |
|
213 | + * @return object |
|
214 | + */ |
|
215 | + public function block($userId) |
|
216 | + { |
|
217 | + if (\Auth::id() == $userId) { |
|
218 | + \Errors::noPermissions(); |
|
219 | + } |
|
220 | 220 | |
221 | - return $this->repo->save(['id' => $userId, 'blocked' => 1]); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Unblock the user. |
|
226 | - * |
|
227 | - * @param integer $userId |
|
228 | - * @return object |
|
229 | - */ |
|
230 | - public function unblock($userId) |
|
231 | - { |
|
232 | - return $this->repo->save(['id' => $userId, 'blocked' => 0]); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Send a reset link to the given user. |
|
237 | - * |
|
238 | - * @param string $email |
|
239 | - * @return void |
|
240 | - */ |
|
241 | - public function sendReset($email) |
|
242 | - { |
|
243 | - if (! $user = $this->repo->first(['email' => $email])) { |
|
244 | - \Errors::notFound('email'); |
|
245 | - } |
|
246 | - |
|
247 | - $token = \Password::createToken($user); |
|
248 | - $this->notificationService->notify($user, 'ResetPassword', $token); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Reset the given user's password. |
|
253 | - * |
|
254 | - * @param string $email |
|
255 | - * @param string $password |
|
256 | - * @param string $passwordConfirmation |
|
257 | - * @param string $token |
|
258 | - * @return string|void |
|
259 | - */ |
|
260 | - public function resetPassword($email, $password, $passwordConfirmation, $token) |
|
261 | - { |
|
262 | - $response = \Password::reset([ |
|
263 | - 'email' => $email, |
|
264 | - 'password' => $password, |
|
265 | - 'password_confirmation' => $passwordConfirmation, |
|
266 | - 'token' => $token |
|
267 | - ], function ($user, $password) { |
|
268 | - $this->repo->save(['id' => $user->id, 'password' => $password]); |
|
269 | - }); |
|
270 | - |
|
271 | - switch ($response) { |
|
272 | - case \Password::PASSWORD_RESET: |
|
273 | - return 'success'; |
|
274 | - break; |
|
275 | - |
|
276 | - case \Password::INVALID_TOKEN: |
|
277 | - \Errors::invalidResetToken(); |
|
278 | - break; |
|
279 | - |
|
280 | - case \Password::INVALID_PASSWORD: |
|
281 | - \Errors::invalidResetPassword(); |
|
282 | - break; |
|
283 | - |
|
284 | - case \Password::INVALID_USER: |
|
285 | - \Errors::notFound('user'); |
|
286 | - break; |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Change the logged in user password. |
|
292 | - * |
|
293 | - * @param string $password |
|
294 | - * @param string $oldPassword |
|
295 | - * @return void |
|
296 | - */ |
|
297 | - public function changePassword($password, $oldPassword) |
|
298 | - { |
|
299 | - $user = \Auth::user(); |
|
300 | - if (! \Hash::check($oldPassword, $user->password)) { |
|
301 | - \Errors::invalidOldPassword(); |
|
302 | - } |
|
303 | - |
|
304 | - $this->repo->save(['id' => $user->id, 'password' => $password]); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Confirm email using the confirmation code. |
|
309 | - * |
|
310 | - * @param string $confirmationCode |
|
311 | - * @return void |
|
312 | - */ |
|
313 | - public function confirmEmail($confirmationCode) |
|
314 | - { |
|
315 | - if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) { |
|
316 | - \Errors::invalidConfirmationCode(); |
|
317 | - } |
|
318 | - |
|
319 | - $this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Send the confirmation mail. |
|
324 | - * |
|
325 | - * @param string $email |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - public function sendConfirmationEmail($email) |
|
329 | - { |
|
330 | - $user = $this->repo->first(['email' => $email]); |
|
331 | - if ($user->confirmed) { |
|
332 | - \Errors::emailAlreadyConfirmed(); |
|
333 | - } |
|
334 | - |
|
335 | - $this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]); |
|
336 | - $this->notificationService->notify($user, 'ConfirmEmail'); |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Save the given data to the logged in user. |
|
341 | - * |
|
342 | - * @param array $data |
|
343 | - * @return void |
|
344 | - */ |
|
345 | - public function saveProfile($data) |
|
346 | - { |
|
347 | - $data['id'] = \Auth::id(); |
|
348 | - return $this->repo->save($data); |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Logs out the user, revoke access token and refresh token. |
|
353 | - * |
|
354 | - * @return void |
|
355 | - */ |
|
356 | - public function logout() |
|
357 | - { |
|
358 | - $this->oauthClientService->revokeAccessToken(\Auth::user()->token()); |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Attempt to refresh the access token using the given refresh token. |
|
363 | - * |
|
364 | - * @param string $refreshToken |
|
365 | - * @return array |
|
366 | - */ |
|
367 | - public function refreshToken($refreshToken) |
|
368 | - { |
|
369 | - return $this->loginProxy->refreshToken($refreshToken); |
|
370 | - } |
|
221 | + return $this->repo->save(['id' => $userId, 'blocked' => 1]); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Unblock the user. |
|
226 | + * |
|
227 | + * @param integer $userId |
|
228 | + * @return object |
|
229 | + */ |
|
230 | + public function unblock($userId) |
|
231 | + { |
|
232 | + return $this->repo->save(['id' => $userId, 'blocked' => 0]); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Send a reset link to the given user. |
|
237 | + * |
|
238 | + * @param string $email |
|
239 | + * @return void |
|
240 | + */ |
|
241 | + public function sendReset($email) |
|
242 | + { |
|
243 | + if (! $user = $this->repo->first(['email' => $email])) { |
|
244 | + \Errors::notFound('email'); |
|
245 | + } |
|
246 | + |
|
247 | + $token = \Password::createToken($user); |
|
248 | + $this->notificationService->notify($user, 'ResetPassword', $token); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Reset the given user's password. |
|
253 | + * |
|
254 | + * @param string $email |
|
255 | + * @param string $password |
|
256 | + * @param string $passwordConfirmation |
|
257 | + * @param string $token |
|
258 | + * @return string|void |
|
259 | + */ |
|
260 | + public function resetPassword($email, $password, $passwordConfirmation, $token) |
|
261 | + { |
|
262 | + $response = \Password::reset([ |
|
263 | + 'email' => $email, |
|
264 | + 'password' => $password, |
|
265 | + 'password_confirmation' => $passwordConfirmation, |
|
266 | + 'token' => $token |
|
267 | + ], function ($user, $password) { |
|
268 | + $this->repo->save(['id' => $user->id, 'password' => $password]); |
|
269 | + }); |
|
270 | + |
|
271 | + switch ($response) { |
|
272 | + case \Password::PASSWORD_RESET: |
|
273 | + return 'success'; |
|
274 | + break; |
|
275 | + |
|
276 | + case \Password::INVALID_TOKEN: |
|
277 | + \Errors::invalidResetToken(); |
|
278 | + break; |
|
279 | + |
|
280 | + case \Password::INVALID_PASSWORD: |
|
281 | + \Errors::invalidResetPassword(); |
|
282 | + break; |
|
283 | + |
|
284 | + case \Password::INVALID_USER: |
|
285 | + \Errors::notFound('user'); |
|
286 | + break; |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Change the logged in user password. |
|
292 | + * |
|
293 | + * @param string $password |
|
294 | + * @param string $oldPassword |
|
295 | + * @return void |
|
296 | + */ |
|
297 | + public function changePassword($password, $oldPassword) |
|
298 | + { |
|
299 | + $user = \Auth::user(); |
|
300 | + if (! \Hash::check($oldPassword, $user->password)) { |
|
301 | + \Errors::invalidOldPassword(); |
|
302 | + } |
|
303 | + |
|
304 | + $this->repo->save(['id' => $user->id, 'password' => $password]); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Confirm email using the confirmation code. |
|
309 | + * |
|
310 | + * @param string $confirmationCode |
|
311 | + * @return void |
|
312 | + */ |
|
313 | + public function confirmEmail($confirmationCode) |
|
314 | + { |
|
315 | + if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) { |
|
316 | + \Errors::invalidConfirmationCode(); |
|
317 | + } |
|
318 | + |
|
319 | + $this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Send the confirmation mail. |
|
324 | + * |
|
325 | + * @param string $email |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + public function sendConfirmationEmail($email) |
|
329 | + { |
|
330 | + $user = $this->repo->first(['email' => $email]); |
|
331 | + if ($user->confirmed) { |
|
332 | + \Errors::emailAlreadyConfirmed(); |
|
333 | + } |
|
334 | + |
|
335 | + $this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]); |
|
336 | + $this->notificationService->notify($user, 'ConfirmEmail'); |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Save the given data to the logged in user. |
|
341 | + * |
|
342 | + * @param array $data |
|
343 | + * @return void |
|
344 | + */ |
|
345 | + public function saveProfile($data) |
|
346 | + { |
|
347 | + $data['id'] = \Auth::id(); |
|
348 | + return $this->repo->save($data); |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Logs out the user, revoke access token and refresh token. |
|
353 | + * |
|
354 | + * @return void |
|
355 | + */ |
|
356 | + public function logout() |
|
357 | + { |
|
358 | + $this->oauthClientService->revokeAccessToken(\Auth::user()->token()); |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Attempt to refresh the access token using the given refresh token. |
|
363 | + * |
|
364 | + * @param string $refreshToken |
|
365 | + * @return array |
|
366 | + */ |
|
367 | + public function refreshToken($refreshToken) |
|
368 | + { |
|
369 | + return $this->loginProxy->refreshToken($refreshToken); |
|
370 | + } |
|
371 | 371 | } |
@@ -20,211 +20,211 @@ |
||
20 | 20 | |
21 | 21 | class UserController extends BaseApiController |
22 | 22 | { |
23 | - /** |
|
24 | - * Path of the sotre form request. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $storeFormRequest = 'App\Modules\Users\Http\Requests\StoreUser'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Path of the model resource. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser'; |
|
36 | - |
|
37 | - /** |
|
38 | - * List of all route actions that the base api controller |
|
39 | - * will skip permissions check for them. |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile']; |
|
43 | - |
|
44 | - /** |
|
45 | - * List of all route actions that the base api controller |
|
46 | - * will skip login check for them. |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation']; |
|
50 | - |
|
51 | - /** |
|
52 | - * Init new object. |
|
53 | - * |
|
54 | - * @param UserService $service |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function __construct(UserService $service) |
|
58 | - { |
|
59 | - parent::__construct($service); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Return the logged in user account. |
|
64 | - * |
|
65 | - * @param Request $request |
|
66 | - * @return \Illuminate\Http\Response |
|
67 | - */ |
|
68 | - public function account(Request $request) |
|
69 | - { |
|
70 | - return new $this->modelResource($this->service->account($request->relations)); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Block the user. |
|
75 | - * |
|
76 | - * @param integer $id Id of the user. |
|
77 | - * @return \Illuminate\Http\Response |
|
78 | - */ |
|
79 | - public function block($id) |
|
80 | - { |
|
81 | - return new $this->modelResource($this->service->block($id)); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Unblock the user. |
|
86 | - * |
|
87 | - * @param integer $id Id of the user. |
|
88 | - * @return \Illuminate\Http\Response |
|
89 | - */ |
|
90 | - public function unblock($id) |
|
91 | - { |
|
92 | - return new $this->modelResource($this->service->unblock($id)); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Logout the user. |
|
97 | - * |
|
98 | - * @return \Illuminate\Http\Response |
|
99 | - */ |
|
100 | - public function logout() |
|
101 | - { |
|
102 | - return new GeneralResource($this->service->logout()); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Handle the registration request. |
|
107 | - * |
|
108 | - * @param Register $request |
|
109 | - * @return \Illuminate\Http\Response |
|
110 | - */ |
|
111 | - public function register(Register $request) |
|
112 | - { |
|
113 | - return new $this->modelResource($this->service->register($request->validated())); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Handle the login request to the application. |
|
118 | - * |
|
119 | - * @param Login $request |
|
120 | - * @return \Illuminate\Http\Response |
|
121 | - */ |
|
122 | - public function login(Login $request) |
|
123 | - { |
|
124 | - $result = $this->service->login($request->get('email'), $request->get('password')); |
|
125 | - |
|
126 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Handle the social login request the application. |
|
131 | - * |
|
132 | - * @param LoginSocial $request |
|
133 | - * @return \Illuminate\Http\Response |
|
134 | - */ |
|
135 | - public function loginSocial(LoginSocial $request) |
|
136 | - { |
|
137 | - $result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
138 | - |
|
139 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Assign the given roles to the given user. |
|
144 | - * |
|
145 | - * @param AssignRoles $request |
|
146 | - * @param integer $id |
|
147 | - * @return \Illuminate\Http\Response |
|
148 | - */ |
|
149 | - public function assignRoles(AssignRoles $request, $id) |
|
150 | - { |
|
151 | - return new $this->modelResource($this->service->assignRoles($id, $request->get('role_ids'))); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Send a reset link to the given user. |
|
156 | - * |
|
157 | - * @param SendReset $request |
|
158 | - * @return \Illuminate\Http\Response |
|
159 | - */ |
|
160 | - public function sendReset(SendReset $request) |
|
161 | - { |
|
162 | - return new GeneralResource($this->service->sendReset($request->get('email'))); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Reset the given user's password. |
|
167 | - * |
|
168 | - * @param ResetPassword $request |
|
169 | - * @return \Illuminate\Http\Response |
|
170 | - */ |
|
171 | - public function resetPassword(ResetPassword $request) |
|
172 | - { |
|
173 | - return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token'))); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Change the logged in user password. |
|
178 | - * |
|
179 | - * @param ChangePassword $request |
|
180 | - * @return \Illuminate\Http\Response |
|
181 | - */ |
|
182 | - public function changePassword(ChangePassword $request) |
|
183 | - { |
|
184 | - return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password'))); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Confirm email using the confirmation code. |
|
189 | - * |
|
190 | - * @param ConfirmEmail $request |
|
191 | - * @return \Illuminate\Http\Response |
|
192 | - */ |
|
193 | - public function confirmEmail(ConfirmEmail $request) |
|
194 | - { |
|
195 | - return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code'))); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Resend the email confirmation mail. |
|
200 | - * |
|
201 | - * @param ResendEmailConfirmation $request |
|
202 | - * @return \Illuminate\Http\Response |
|
203 | - */ |
|
204 | - public function resendEmailConfirmation(ResendEmailConfirmation $request) |
|
205 | - { |
|
206 | - return new GeneralResource($this->service->sendConfirmationEmail($request->get('email'))); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Refresh the expired login token. |
|
211 | - * |
|
212 | - * @param RefreshToken $request |
|
213 | - * @return \Illuminate\Http\Response |
|
214 | - */ |
|
215 | - public function refreshToken(RefreshToken $request) |
|
216 | - { |
|
217 | - return new GeneralResource($this->service->refreshToken($request->get('refresh_token'))); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Save the given data to the logged in user. |
|
222 | - * |
|
223 | - * @param SaveProfile $request |
|
224 | - * @return \Illuminate\Http\Response |
|
225 | - */ |
|
226 | - public function saveProfile(SaveProfile $request) |
|
227 | - { |
|
228 | - return new $this->modelResource($this->service->saveProfile($request->validated())); |
|
229 | - } |
|
23 | + /** |
|
24 | + * Path of the sotre form request. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $storeFormRequest = 'App\Modules\Users\Http\Requests\StoreUser'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Path of the model resource. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser'; |
|
36 | + |
|
37 | + /** |
|
38 | + * List of all route actions that the base api controller |
|
39 | + * will skip permissions check for them. |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile']; |
|
43 | + |
|
44 | + /** |
|
45 | + * List of all route actions that the base api controller |
|
46 | + * will skip login check for them. |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation']; |
|
50 | + |
|
51 | + /** |
|
52 | + * Init new object. |
|
53 | + * |
|
54 | + * @param UserService $service |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function __construct(UserService $service) |
|
58 | + { |
|
59 | + parent::__construct($service); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Return the logged in user account. |
|
64 | + * |
|
65 | + * @param Request $request |
|
66 | + * @return \Illuminate\Http\Response |
|
67 | + */ |
|
68 | + public function account(Request $request) |
|
69 | + { |
|
70 | + return new $this->modelResource($this->service->account($request->relations)); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Block the user. |
|
75 | + * |
|
76 | + * @param integer $id Id of the user. |
|
77 | + * @return \Illuminate\Http\Response |
|
78 | + */ |
|
79 | + public function block($id) |
|
80 | + { |
|
81 | + return new $this->modelResource($this->service->block($id)); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Unblock the user. |
|
86 | + * |
|
87 | + * @param integer $id Id of the user. |
|
88 | + * @return \Illuminate\Http\Response |
|
89 | + */ |
|
90 | + public function unblock($id) |
|
91 | + { |
|
92 | + return new $this->modelResource($this->service->unblock($id)); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Logout the user. |
|
97 | + * |
|
98 | + * @return \Illuminate\Http\Response |
|
99 | + */ |
|
100 | + public function logout() |
|
101 | + { |
|
102 | + return new GeneralResource($this->service->logout()); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Handle the registration request. |
|
107 | + * |
|
108 | + * @param Register $request |
|
109 | + * @return \Illuminate\Http\Response |
|
110 | + */ |
|
111 | + public function register(Register $request) |
|
112 | + { |
|
113 | + return new $this->modelResource($this->service->register($request->validated())); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Handle the login request to the application. |
|
118 | + * |
|
119 | + * @param Login $request |
|
120 | + * @return \Illuminate\Http\Response |
|
121 | + */ |
|
122 | + public function login(Login $request) |
|
123 | + { |
|
124 | + $result = $this->service->login($request->get('email'), $request->get('password')); |
|
125 | + |
|
126 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Handle the social login request the application. |
|
131 | + * |
|
132 | + * @param LoginSocial $request |
|
133 | + * @return \Illuminate\Http\Response |
|
134 | + */ |
|
135 | + public function loginSocial(LoginSocial $request) |
|
136 | + { |
|
137 | + $result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
138 | + |
|
139 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Assign the given roles to the given user. |
|
144 | + * |
|
145 | + * @param AssignRoles $request |
|
146 | + * @param integer $id |
|
147 | + * @return \Illuminate\Http\Response |
|
148 | + */ |
|
149 | + public function assignRoles(AssignRoles $request, $id) |
|
150 | + { |
|
151 | + return new $this->modelResource($this->service->assignRoles($id, $request->get('role_ids'))); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Send a reset link to the given user. |
|
156 | + * |
|
157 | + * @param SendReset $request |
|
158 | + * @return \Illuminate\Http\Response |
|
159 | + */ |
|
160 | + public function sendReset(SendReset $request) |
|
161 | + { |
|
162 | + return new GeneralResource($this->service->sendReset($request->get('email'))); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Reset the given user's password. |
|
167 | + * |
|
168 | + * @param ResetPassword $request |
|
169 | + * @return \Illuminate\Http\Response |
|
170 | + */ |
|
171 | + public function resetPassword(ResetPassword $request) |
|
172 | + { |
|
173 | + return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token'))); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Change the logged in user password. |
|
178 | + * |
|
179 | + * @param ChangePassword $request |
|
180 | + * @return \Illuminate\Http\Response |
|
181 | + */ |
|
182 | + public function changePassword(ChangePassword $request) |
|
183 | + { |
|
184 | + return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password'))); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Confirm email using the confirmation code. |
|
189 | + * |
|
190 | + * @param ConfirmEmail $request |
|
191 | + * @return \Illuminate\Http\Response |
|
192 | + */ |
|
193 | + public function confirmEmail(ConfirmEmail $request) |
|
194 | + { |
|
195 | + return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code'))); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Resend the email confirmation mail. |
|
200 | + * |
|
201 | + * @param ResendEmailConfirmation $request |
|
202 | + * @return \Illuminate\Http\Response |
|
203 | + */ |
|
204 | + public function resendEmailConfirmation(ResendEmailConfirmation $request) |
|
205 | + { |
|
206 | + return new GeneralResource($this->service->sendConfirmationEmail($request->get('email'))); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Refresh the expired login token. |
|
211 | + * |
|
212 | + * @param RefreshToken $request |
|
213 | + * @return \Illuminate\Http\Response |
|
214 | + */ |
|
215 | + public function refreshToken(RefreshToken $request) |
|
216 | + { |
|
217 | + return new GeneralResource($this->service->refreshToken($request->get('refresh_token'))); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Save the given data to the logged in user. |
|
222 | + * |
|
223 | + * @param SaveProfile $request |
|
224 | + * @return \Illuminate\Http\Response |
|
225 | + */ |
|
226 | + public function saveProfile(SaveProfile $request) |
|
227 | + { |
|
228 | + return new $this->modelResource($this->service->saveProfile($request->validated())); |
|
229 | + } |
|
230 | 230 | } |
@@ -7,63 +7,63 @@ |
||
7 | 7 | |
8 | 8 | class OauthClientService extends BaseService |
9 | 9 | { |
10 | - /** |
|
11 | - * Init new object. |
|
12 | - * |
|
13 | - * @param OauthClientRepository $repo |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function __construct(OauthClientRepository $repo) |
|
17 | - { |
|
18 | - parent::__construct($repo); |
|
19 | - } |
|
10 | + /** |
|
11 | + * Init new object. |
|
12 | + * |
|
13 | + * @param OauthClientRepository $repo |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function __construct(OauthClientRepository $repo) |
|
17 | + { |
|
18 | + parent::__construct($repo); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Revoke the given client. |
|
23 | - * |
|
24 | - * @param integer $clientId |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public function revoke($clientId) |
|
28 | - { |
|
29 | - \DB::transaction(function () use ($clientId) { |
|
30 | - $client = $this->repo->find($clientId); |
|
31 | - $this->repo->revokeClientTokens($client); |
|
32 | - $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
|
33 | - }); |
|
34 | - } |
|
21 | + /** |
|
22 | + * Revoke the given client. |
|
23 | + * |
|
24 | + * @param integer $clientId |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public function revoke($clientId) |
|
28 | + { |
|
29 | + \DB::transaction(function () use ($clientId) { |
|
30 | + $client = $this->repo->find($clientId); |
|
31 | + $this->repo->revokeClientTokens($client); |
|
32 | + $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
|
33 | + }); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * UnRevoke the given client. |
|
38 | - * |
|
39 | - * @param integer $clientId |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function unRevoke($clientId) |
|
43 | - { |
|
44 | - $this->repo->save(['id'=> $clientId, 'revoked' => false]); |
|
45 | - } |
|
36 | + /** |
|
37 | + * UnRevoke the given client. |
|
38 | + * |
|
39 | + * @param integer $clientId |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function unRevoke($clientId) |
|
43 | + { |
|
44 | + $this->repo->save(['id'=> $clientId, 'revoked' => false]); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Ensure access token hasn't expired or revoked. |
|
49 | - * |
|
50 | - * @param string $accessToken |
|
51 | - * @return boolean |
|
52 | - */ |
|
53 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
54 | - { |
|
55 | - return $this->repo->accessTokenExpiredOrRevoked($accessToken); |
|
56 | - } |
|
47 | + /** |
|
48 | + * Ensure access token hasn't expired or revoked. |
|
49 | + * |
|
50 | + * @param string $accessToken |
|
51 | + * @return boolean |
|
52 | + */ |
|
53 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
54 | + { |
|
55 | + return $this->repo->accessTokenExpiredOrRevoked($accessToken); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Revoke the given access token and all |
|
60 | - * associated refresh tokens. |
|
61 | - * |
|
62 | - * @param oject $accessToken |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function revokeAccessToken($accessToken) |
|
66 | - { |
|
67 | - return $this->repo->revokeAccessToken($accessToken); |
|
68 | - } |
|
58 | + /** |
|
59 | + * Revoke the given access token and all |
|
60 | + * associated refresh tokens. |
|
61 | + * |
|
62 | + * @param oject $accessToken |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function revokeAccessToken($accessToken) |
|
66 | + { |
|
67 | + return $this->repo->revokeAccessToken($accessToken); |
|
68 | + } |
|
69 | 69 | } |