2020use App \ModelSerializers \SerializerRegistry ;
2121use Auth \Exceptions \AuthenticationException ;
2222use Auth \Exceptions \UnverifiedEmailMemberException ;
23+ use App \Services \Auth \IUserService as AuthUserService ;
2324use Exception ;
25+ use Illuminate \Http \Request as LaravelRequest ;
2426use Illuminate \Support \Facades \Request ;
2527use Illuminate \Support \Facades \Log ;
2628use Illuminate \Support \Facades \Redirect ;
@@ -85,6 +87,10 @@ final class UserController extends OpenIdController
8587 * @var IUserService
8688 */
8789 private $ user_service ;
90+ /**
91+ * @var AuthUserService
92+ */
93+ private $ auth_user_service ;
8894 /**
8995 * @var IUserActionService
9096 */
@@ -131,6 +137,7 @@ final class UserController extends OpenIdController
131137 * @param ITrustedSitesService $trusted_sites_service
132138 * @param DiscoveryController $discovery
133139 * @param IUserService $user_service
140+ * @param AuthUserService $auth_user_service
134141 * @param IUserActionService $user_action_service
135142 * @param IClientRepository $client_repository
136143 * @param IApiScopeRepository $scope_repository
@@ -149,6 +156,7 @@ public function __construct
149156 ITrustedSitesService $ trusted_sites_service ,
150157 DiscoveryController $ discovery ,
151158 IUserService $ user_service ,
159+ AuthUserService $ auth_user_service ,
152160 IUserActionService $ user_action_service ,
153161 IClientRepository $ client_repository ,
154162 IApiScopeRepository $ scope_repository ,
@@ -159,15 +167,14 @@ public function __construct
159167 LoginHintProcessStrategy $ login_hint_process_strategy
160168 )
161169 {
162-
163-
164170 $ this ->openid_memento_service = $ openid_memento_service ;
165171 $ this ->oauth2_memento_service = $ oauth2_memento_service ;
166172 $ this ->auth_service = $ auth_service ;
167173 $ this ->server_configuration_service = $ server_configuration_service ;
168174 $ this ->trusted_sites_service = $ trusted_sites_service ;
169175 $ this ->discovery = $ discovery ;
170176 $ this ->user_service = $ user_service ;
177+ $ this ->auth_user_service = $ auth_user_service ;
171178 $ this ->user_action_service = $ user_action_service ;
172179 $ this ->client_repository = $ client_repository ;
173180 $ this ->scope_repository = $ scope_repository ;
@@ -257,14 +264,16 @@ public function getAccount()
257264
258265 $ user = $ this ->auth_service ->getUserByUsername ($ email );
259266
260- if (is_null ($ user ) || ! $ user -> canLogin () )
267+ if (is_null ($ user ))
261268 throw new EntityNotFoundException ();
262269
263270 return $ this ->ok (
264271 [
272+ 'is_active ' => $ user ->isActive (),
273+ 'is_verified ' => $ user ->isEmailVerified (),
265274 'pic ' => $ user ->getPic (),
266275 'full_name ' => $ user ->getFullName (),
267- 'has_password_set ' => $ user ->hasPasswordSet ()
276+ 'has_password_set ' => $ user ->hasPasswordSet (),
268277 ]
269278 );
270279 } catch (ValidationException $ ex ) {
@@ -354,9 +363,41 @@ public function emitOTP()
354363 }
355364 }
356365
366+ /**
367+ * @return \Illuminate\Http\JsonResponse|mixed
368+ */
369+ public function resendVerificationEmail (LaravelRequest $ request )
370+ {
371+ try {
372+ $ payload = $ request ->all ();
373+ $ validator = Validator::make ($ payload , [
374+ 'email ' => 'required|string|email|max:255 '
375+ ]);
376+
377+ if (!$ validator ->passes ()) {
378+ return $ this ->error412 ($ validator ->getMessageBag ()->getMessages ());
379+ }
380+ $ this ->auth_user_service ->resendVerificationEmail ($ payload );
381+ return $ this ->ok ();
382+ }
383+ catch (ValidationException $ ex ) {
384+ Log::warning ($ ex );
385+ return $ this ->error412 ($ ex ->getMessages ());
386+ }
387+ catch (EntityNotFoundException $ ex ) {
388+ Log::warning ($ ex );
389+ return $ this ->error404 ();
390+ }
391+ catch (Exception $ ex ) {
392+ Log::error ($ ex );
393+ return $ this ->error500 ($ ex );
394+ }
395+ }
396+
357397 public function postLogin ()
358398 {
359399 $ max_login_attempts_2_show_captcha = $ this ->server_configuration_service ->getConfigValue ("MaxFailed.LoginAttempts.2ShowCaptcha " );
400+ $ max_login_failed_attempts = intval ($ this ->server_configuration_service ->getConfigValue ("MaxFailed.Login.Attempts " ));
360401 $ login_attempts = 0 ;
361402 $ username = '' ;
362403 $ user = null ;
@@ -443,13 +484,15 @@ public function postLogin()
443484 (
444485 [
445486 'max_login_attempts_2_show_captcha ' => $ max_login_attempts_2_show_captcha ,
487+ 'max_login_failed_attempts ' => $ max_login_failed_attempts ,
446488 'login_attempts ' => $ login_attempts ,
447489 'error_message ' => $ ex ->getMessage (),
448490 'user_fullname ' => !is_null ($ user ) ? $ user ->getFullName () : "" ,
449491 'user_pic ' => !is_null ($ user ) ? $ user ->getPic (): "" ,
450492 'user_verified ' => true ,
451493 'username ' => $ username ,
452- 'flow ' => $ flow
494+ 'flow ' => $ flow ,
495+ 'user_is_active ' => !is_null ($ user ) ? ($ user ->isActive () ? 1 : 0 ) : 0
453496 ]
454497 );
455498 }
@@ -459,6 +502,7 @@ public function postLogin()
459502 // validator errors
460503 $ response_data = [
461504 'max_login_attempts_2_show_captcha ' => $ max_login_attempts_2_show_captcha ,
505+ 'max_login_failed_attempts ' => $ max_login_failed_attempts ,
462506 'login_attempts ' => $ login_attempts ,
463507 'validator ' => $ validator ,
464508 ];
@@ -470,7 +514,8 @@ public function postLogin()
470514 if (!is_null ($ user )){
471515 $ response_data ['user_fullname ' ] = $ user ->getFullName ();
472516 $ response_data ['user_pic ' ] = $ user ->getPic ();
473- $ response_data ['user_verified ' ] = true ;
517+ $ response_data ['user_verified ' ] = 1 ;
518+ $ response_data ['user_is_active ' ] = $ user ->isActive () ? 1 : 0 ;
474519 }
475520
476521 return $ this ->login_strategy ->errorLogin
@@ -485,9 +530,10 @@ public function postLogin()
485530
486531 $ response_data = [
487532 'max_login_attempts_2_show_captcha ' => $ max_login_attempts_2_show_captcha ,
533+ 'max_login_failed_attempts ' => $ max_login_failed_attempts ,
488534 'login_attempts ' => $ login_attempts ,
489535 'username ' => $ username ,
490- 'error_message ' => $ ex1 ->getMessage ()
536+ 'error_message ' => $ ex1 ->getMessage (),
491537 ];
492538
493539 if (is_null ($ user ) && isset ($ data ['username ' ])) {
@@ -497,7 +543,8 @@ public function postLogin()
497543 if (!is_null ($ user )){
498544 $ response_data ['user_fullname ' ] = $ user ->getFullName ();
499545 $ response_data ['user_pic ' ] = $ user ->getPic ();
500- $ response_data ['user_verified ' ] = true ;
546+ $ response_data ['user_verified ' ] = 1 ;
547+ $ response_data ['user_is_active ' ] = $ user ->isActive () ? 1 : 0 ;
501548 }
502549
503550 return $ this ->login_strategy ->errorLogin
0 commit comments