@@ -818,6 +818,9 @@ public ApiResponse login(
818818 User user = userDao .authenticate (handleOrEmail , password );
819819
820820 if (user != null && user .getId () != null ) {
821+ if (!user .getStatus ().equals (MemberStatus .ACTIVE .getValue ()) && !user .getStatus ().equals (MemberStatus .UNVERIFIED .getValue ())) {
822+ throw new APIRuntimeException (SC_UNAUTHORIZED , "Account is deactivated." );
823+ }
821824 List <Role > roles = roleDao .getRolesBySubjectId (Long .parseLong (user .getId ().getId ()));
822825 user .setRoles (roles );
823826 }
@@ -867,7 +870,7 @@ public ApiResponse roles(
867870 // temp - just for testing
868871 user .setRegSource (userDao .generateSSOToken (Long .parseLong (user .getId ().getId ())));
869872
870- if (! user .isActive ( )) {
873+ if (user .getStatus (). equals ( MemberStatus . UNVERIFIED . getValue () )) {
871874 UserOtp activation = userDao .findUserOtpByUserId (Utils .toLongValue (user .getId ()), otpActivationMode );
872875 if (user .getCredential () == null ) {
873876 user .setCredential (new Credential ());
@@ -912,12 +915,12 @@ public ApiResponse changePassword(
912915 throw new APIRuntimeException (SC_BAD_REQUEST , String .format (MSG_TEMPLATE_MANDATORY , "email" ));
913916
914917 User user = userDao .findUserByEmail (email );
915- user .setCredential (new Credential ());
916- user .getCredential ().setPassword (password );
917-
918- if (user ==null ) {
919- throw new APIRuntimeException (SC_UNAUTHORIZED , "Credentials are incorrect." );
918+ if (user == null ) {
919+ throw new APIRuntimeException (SC_NOT_FOUND , MSG_TEMPLATE_USER_NOT_FOUND );
920920 }
921+ if (user .getCredential () == null )
922+ user .setCredential (new Credential ());
923+ user .getCredential ().setPassword (password );
921924
922925 // SSO users can't reset their password.
923926 List <UserProfile > ssoProfiles = userDao .getSSOProfiles (Utils .toLongValue (user .getId ()));
@@ -929,22 +932,8 @@ public ApiResponse changePassword(
929932 throw new APIRuntimeException (SC_BAD_REQUEST , error );
930933 }
931934
932- User dbUser = null ;
933- if (dbUser ==null && user .getEmail ()!=null ) {
934- logger .debug (String .format ("Auth0: findUserByEmail(%s)" , user .getEmail ()));
935- dbUser = this .userDao .findUserByEmail (user .getEmail ());
936- }
937-
938- if (dbUser ==null ) {
939- throw new APIRuntimeException (SC_NOT_FOUND , MSG_TEMPLATE_USER_NOT_FOUND );
940- }
941-
942- if (dbUser .getCredential ()==null )
943- dbUser .setCredential (new Credential ());
944- dbUser .getCredential ().setPassword (user .getCredential ().getPassword ());
945-
946- logger .debug (String .format ("Auth0: updating password for user: %s" , dbUser .getHandle ()));
947- userDao .updatePassword (dbUser );
935+ logger .debug (String .format ("Auth0: updating password for user: %s" , user .getHandle ()));
936+ userDao .updatePassword (user );
948937
949938 return ApiResponseFactory .createResponse ("password updated successfully." );
950939 }
@@ -1062,6 +1051,9 @@ public ApiResponse resendActivationEmail(
10621051 if (userActivation .isActive ()) {
10631052 throw new APIRuntimeException (SC_BAD_REQUEST , MSG_TEMPLATE_USER_ALREADY_ACTIVATED );
10641053 }
1054+ if (!userActivation .getStatus ().equals (MemberStatus .UNVERIFIED .getValue ())) {
1055+ throw new APIRuntimeException (SC_FORBIDDEN , "Account is deactivated" );
1056+ }
10651057 if (userActivation .getId () == null ) {
10661058 throw new APIRuntimeException (SC_NOT_FOUND , "No activation code found" );
10671059 }
@@ -1113,18 +1105,21 @@ public ApiResponse activateUser(
11131105 if (userActivation .isActive ()) {
11141106 return ApiResponseFactory .createResponse (MSG_TEMPLATE_USER_ALREADY_ACTIVATED );
11151107 }
1108+ if (!userActivation .getStatus ().equals (MemberStatus .UNVERIFIED .getValue ())) {
1109+ throw new APIRuntimeException (SC_FORBIDDEN , "Account is deactivated" );
1110+ }
11161111 if (userActivation .getId () == null ) {
11171112 throw new APIRuntimeException (SC_NOT_FOUND , "No activation code found" );
11181113 }
11191114
11201115 if (userActivation .getFailCount () >= 3 ) {
1121- throw new APIRuntimeException (SC_BAD_REQUEST , "Blocked " );
1116+ throw new APIRuntimeException (SC_BAD_REQUEST , "Too many attempts " );
11221117 } else if (userActivation .getExpireAt ().isBeforeNow ()) {
1123- throw new APIRuntimeException (SC_BAD_REQUEST , "Expired " );
1118+ throw new APIRuntimeException (SC_BAD_REQUEST , "Activation code expired " );
11241119 } else if (!userActivation .getOtp ().equals (activationRequest .getOtp ())) {
11251120 userDao .updateUserOtpAttempt (userActivation .getId (), userActivation .getFailCount () + 1 );
11261121 if (userActivation .getFailCount () >= 2 ) {
1127- throw new APIRuntimeException (SC_BAD_REQUEST , "Blocked " );
1122+ throw new APIRuntimeException (SC_BAD_REQUEST , "Too many attempts " );
11281123 }
11291124 throw new APIRuntimeException (SC_BAD_REQUEST , "Wrong Activation Code" );
11301125 }
0 commit comments