@@ -1676,7 +1676,10 @@ public ApiResponse update2faVerification(
16761676 if (credVerification .getEnabled () == null || !credVerification .getEnabled ()) {
16771677 throw new APIRuntimeException (SC_BAD_REQUEST , "2FA is not enabled for user" );
16781678 }
1679- if (!credVerification .getVerified ().equals (credential .getVerified ())) {
1679+ // update only if it's true. We need to prevent changing verification status from true to false
1680+ // Otherwise 2fa will be skipped during the login flow.
1681+ // The only way to set verification to false is disabling the 2fa for that user.
1682+ if (credential .getVerified ()) {
16801683 userDao .update2fa (credVerification .getId (), true , credential .getVerified ());
16811684 }
16821685 return ApiResponseFactory .createResponse ("User verification updated" );
@@ -1706,8 +1709,8 @@ public ApiResponse createOtp(
17061709 throw new APIRuntimeException (SC_BAD_REQUEST , "2FA is not enabled for user" );
17071710 }
17081711 String otp = Utils .generateRandomString (ALPHABET_DIGITS_EN , 6 );
1709- userDao .update2faOtp (user2faInDb .getId (), otp );
1710- send2faCodeEmailEvent (user2faInDb , otp );
1712+ userDao .update2faOtp (user2faInDb .getId (), otp , diceAuth . getOtpDuration () );
1713+ send2faCodeEmailEvent (user2faInDb , otp , diceAuth . getOtpDuration () );
17111714 return ApiResponseFactory .createResponse ("SUCCESS" );
17121715 }
17131716
@@ -2193,7 +2196,7 @@ private void send2faInvitationEmailEvent(User2fa user, String inviteLink) {
21932196 this .eventBusServiceClient .reFireEvent (msg );
21942197 }
21952198
2196- private void send2faCodeEmailEvent (User2fa user , String code ) {
2199+ private void send2faCodeEmailEvent (User2fa user , String code , Integer duration ) {
21972200
21982201 EventMessage msg = EventMessage .getDefault ();
21992202 msg .setTopic ("external.action.email" );
@@ -2202,6 +2205,7 @@ private void send2faCodeEmailEvent(User2fa user, String code) {
22022205 Map <String ,Object > data = new LinkedHashMap <String ,Object >();
22032206 data .put ("handle" , user .getHandle ());
22042207 data .put ("code" , code );
2208+ data .put ("duration" , duration );
22052209
22062210 payload .put ("data" , data );
22072211
0 commit comments