diff --git a/signup-service/src/main/java/io/mosip/signup/controllers/SignUpController.java b/signup-service/src/main/java/io/mosip/signup/controllers/SignUpController.java index 276eac10..ee177671 100644 --- a/signup-service/src/main/java/io/mosip/signup/controllers/SignUpController.java +++ b/signup-service/src/main/java/io/mosip/signup/controllers/SignUpController.java @@ -48,11 +48,10 @@ public ResponseWrapper getSignUpDetails() { @PostMapping("/reset-password") public ResponseWrapper resetPassword(@Valid @RequestBody RequestWrapper requestWrapper, @Valid @NotBlank(message = ErrorConstants.INVALID_TRANSACTION) - @RequestHeader(name = "Locale") String locale, @CookieValue(value = SignUpConstants.VERIFIED_TRANSACTION_ID, defaultValue = EMTPY) String transactionId){ ResponseWrapper responseWrapper = new ResponseWrapper<>(); try{ - responseWrapper.setResponse(registrationService.updatePassword(requestWrapper.getRequest(), transactionId, locale)); + responseWrapper.setResponse(registrationService.updatePassword(requestWrapper.getRequest(), transactionId)); }catch (SignUpException signUpException){ auditHelper.sendAuditTransaction(AuditEvent.RESET_PASSWORD, AuditEventType.ERROR, transactionId, signUpException); throw signUpException; diff --git a/signup-service/src/main/java/io/mosip/signup/dto/ResetPasswordRequest.java b/signup-service/src/main/java/io/mosip/signup/dto/ResetPasswordRequest.java index b5c33773..c0976dfe 100644 --- a/signup-service/src/main/java/io/mosip/signup/dto/ResetPasswordRequest.java +++ b/signup-service/src/main/java/io/mosip/signup/dto/ResetPasswordRequest.java @@ -12,4 +12,6 @@ public class ResetPasswordRequest { @Password private String password; + + private String locale; } diff --git a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java index 6a13070b..03812591 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java @@ -264,7 +264,7 @@ public RegisterResponse register(RegisterRequest registerRequest, String transac } public RegistrationStatusResponse updatePassword(ResetPasswordRequest resetPasswordRequest, - String transactionId, String locale) throws SignUpException{ + String transactionId) throws SignUpException{ log.debug("Transaction {} : start reset password", transactionId); RegistrationTransaction transaction = cacheUtilService.getChallengeVerifiedTransaction(transactionId); @@ -324,7 +324,7 @@ public RegistrationStatusResponse updatePassword(ResetPasswordRequest resetPassw transaction.setRegistrationStatus(RegistrationStatus.PENDING); cacheUtilService.setStatusCheckTransaction(transactionId, transaction); - notificationHelper.sendSMSNotificationAsync(resetPasswordRequest.getIdentifier(), locale, + notificationHelper.sendSMSNotificationAsync(resetPasswordRequest.getIdentifier(), resetPasswordRequest.getLocale(), FORGOT_PASSWORD_SMS_NOTIFICATION_TEMPLATE_KEY, null) .thenAccept(notificationResponseRestResponseWrapper -> log.debug(notificationLogging, notificationResponseRestResponseWrapper) diff --git a/signup-service/src/test/java/io/mosip/signup/controllers/SignUpControllerTest.java b/signup-service/src/test/java/io/mosip/signup/controllers/SignUpControllerTest.java index 7dcbdb60..a60ec07d 100644 --- a/signup-service/src/test/java/io/mosip/signup/controllers/SignUpControllerTest.java +++ b/signup-service/src/test/java/io/mosip/signup/controllers/SignUpControllerTest.java @@ -90,7 +90,7 @@ public void restPassword_thenPass() throws Exception { RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); registrationStatusResponse.setStatus(RegistrationStatus.PENDING); - when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse); + when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse); mockMvc.perform(post("/reset-password") .header("locale", "khm") @@ -161,7 +161,7 @@ public void resetPassword_withPasswordInvalidPattern_returnInvalidPassword() thr RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); registrationStatusResponse.setStatus(RegistrationStatus.PENDING); - when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse); + when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse); mockMvc.perform(post("/reset-password") .content(objectMapper.writeValueAsString(resetPasswordWrapper)) @@ -188,7 +188,7 @@ public void resetPassword_withPasswordMoreThenAndLeastThenLength_returnInvalidPa RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); registrationStatusResponse.setStatus(RegistrationStatus.PENDING); - when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse); + when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse); mockMvc.perform(post("/reset-password") .content(objectMapper.writeValueAsString(resetPasswordWrapper)) @@ -224,7 +224,7 @@ public void resetPassword_withIdentifierInvalidPattern_returnInvalidPassword() t RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); registrationStatusResponse.setStatus(RegistrationStatus.PENDING); - when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse); + when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse); mockMvc.perform(post("/reset-password") .content(objectMapper.writeValueAsString(resetPasswordWrapper)) @@ -251,7 +251,7 @@ public void resetPassword_withBlankIdentifier_returnInvalidPassword() throws Exc RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); registrationStatusResponse.setStatus(RegistrationStatus.PENDING); - when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse); + when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse); mockMvc.perform(post("/reset-password") .content(objectMapper.writeValueAsString(resetPasswordWrapper)) @@ -278,7 +278,7 @@ public void resetPassword_withNullIdentifier_returnInvalidPassword() throws Exce RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); registrationStatusResponse.setStatus(RegistrationStatus.PENDING); - when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse); + when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse); mockMvc.perform(post("/reset-password") .content(objectMapper.writeValueAsString(resetPasswordWrapper)) diff --git a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java index bc5d6e23..b324dbdf 100644 --- a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java +++ b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java @@ -1980,6 +1980,7 @@ public void doUpdatePassword_thenSuccess() { ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(); resetPasswordRequest.setPassword("Password@2002"); resetPasswordRequest.setIdentifier("+85512345678"); + resetPasswordRequest.setLocale(locale); RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(), Purpose.RESET_PASSWORD); @@ -2015,7 +2016,7 @@ public void doUpdatePassword_thenSuccess() { .thenReturn(new CompletableFuture<>()); RegistrationStatusResponse registrationStatusResponse = registrationService.updatePassword(resetPasswordRequest, - verifiedTransactionId, locale); + verifiedTransactionId); Assert.assertEquals(RegistrationStatus.PENDING, registrationStatusResponse.getStatus()); } @@ -2026,9 +2027,10 @@ public void doUpdatePassword_withInvalidTransaction_thenSuccess() { ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(); resetPasswordRequest.setPassword("Password@2002"); resetPasswordRequest.setIdentifier("+85512345678"); + resetPasswordRequest.setLocale(locale); try { - registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale); + registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId); Assert.fail(); } catch (SignUpException signUpException) { Assert.assertEquals("invalid_transaction", signUpException.getErrorCode()); @@ -2042,13 +2044,14 @@ public void doUpdatePassword_withIdentifierMismatch_throwIdentifierMismatch() { ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(); resetPasswordRequest.setPassword("Password@2002"); resetPasswordRequest.setIdentifier("+85512345678"); + resetPasswordRequest.setLocale(locale); RegistrationTransaction transaction = new RegistrationTransaction("****", Purpose.RESET_PASSWORD); transaction.setUin("mockUin"); when(cacheUtilService.getChallengeVerifiedTransaction(verifiedTransactionId)).thenReturn(transaction); try { - registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale); + registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId); Assert.fail(); } catch (SignUpException signUpException) { Assert.assertEquals("identifier_mismatch", signUpException.getErrorCode()); @@ -2062,6 +2065,7 @@ public void doUpdatePassword_whenIdentityEndpointResponseIsNull_throwResetPasswo ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(); resetPasswordRequest.setPassword("Password@2002"); resetPasswordRequest.setIdentifier("+85512345678"); + resetPasswordRequest.setLocale(locale); RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(), Purpose.RESET_PASSWORD); @@ -2088,7 +2092,7 @@ public void doUpdatePassword_whenIdentityEndpointResponseIsNull_throwResetPasswo .thenReturn(new ResponseEntity<>(null, HttpStatus.OK)); try { - registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale); + registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId); Assert.fail(); } catch (SignUpException signUpException) { Assert.assertEquals("reset_pwd_failed", signUpException.getErrorCode()); @@ -2102,6 +2106,7 @@ public void doUpdatePassword_whenIdentityEndpointReturnInvalidResponse_throwRese ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(); resetPasswordRequest.setPassword("Password@2002"); resetPasswordRequest.setIdentifier("+85512345678"); + resetPasswordRequest.setLocale(locale); RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(), Purpose.RESET_PASSWORD); @@ -2131,7 +2136,7 @@ public void doUpdatePassword_whenIdentityEndpointReturnInvalidResponse_throwRese .thenReturn(new ResponseEntity<>(mockIdentityResponseRestResponseWrapper, HttpStatus.OK)); try { - registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale); + registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId); Assert.fail(); } catch (SignUpException signUpException) { Assert.assertEquals("reset_pwd_failed", signUpException.getErrorCode()); @@ -2144,6 +2149,7 @@ public void doUpdatePassword_whenIdentityEndpointReturnsError_throwErrorFromAnot ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(); resetPasswordRequest.setPassword("Password@2002"); resetPasswordRequest.setIdentifier("+85512345678"); + resetPasswordRequest.setLocale(locale); RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(), Purpose.RESET_PASSWORD); @@ -2178,7 +2184,7 @@ public void doUpdatePassword_whenIdentityEndpointReturnsError_throwErrorFromAnot try { - registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale); + registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId); Assert.fail(); } catch (SignUpException signUpException) { Assert.assertEquals("error_from_another_service", signUpException.getErrorCode()); diff --git a/signup-ui/src/pages/ResetPasswordPage/ResetPassword/ResetPassword.tsx b/signup-ui/src/pages/ResetPasswordPage/ResetPassword/ResetPassword.tsx index 21d2c65f..760215a3 100644 --- a/signup-ui/src/pages/ResetPasswordPage/ResetPassword/ResetPassword.tsx +++ b/signup-ui/src/pages/ResetPasswordPage/ResetPassword/ResetPassword.tsx @@ -104,6 +104,7 @@ export const ResetPassword = ({ methods, settings }: ResetPasswordProps) => { settings.response.configs["identifier.prefix"] }${getValues("username")}`, password: getValues("newPassword"), + locale: null }, }; diff --git a/signup-ui/src/pages/SignUpPage/AccountSetup/AccountSetup.tsx b/signup-ui/src/pages/SignUpPage/AccountSetup/AccountSetup.tsx index a2421ec5..27f48335 100644 --- a/signup-ui/src/pages/SignUpPage/AccountSetup/AccountSetup.tsx +++ b/signup-ui/src/pages/SignUpPage/AccountSetup/AccountSetup.tsx @@ -98,6 +98,7 @@ export const AccountSetup = ({ settings, methods }: AccountSetupProps) => { }${getValues("phone")}`, preferredLang: "eng", }, + locale: null }, }; diff --git a/signup-ui/src/pages/shared/mutations.ts b/signup-ui/src/pages/shared/mutations.ts index 6459ce43..ccd32301 100644 --- a/signup-ui/src/pages/shared/mutations.ts +++ b/signup-ui/src/pages/shared/mutations.ts @@ -67,7 +67,7 @@ export const useRegister = () => { mutationKey: keys.registration, mutationFn: (registrationRequestDto: RegistrationRequestDto) =>{ registrationRequestDto.request.locale = locale - register(registrationRequestDto)}, + return register(registrationRequestDto)}, gcTime: Infinity, }); @@ -86,7 +86,7 @@ export const useResetPassword = () => { mutationKey: keys.resetPassword, mutationFn: (resetPasswordRequestDto: ResetPasswordRequestDto) => { resetPasswordRequestDto.request.locale = locale - resetPassword(resetPasswordRequestDto)}, + return resetPassword(resetPasswordRequestDto)}, gcTime: Infinity, }); diff --git a/signup-ui/src/typings/types.ts b/signup-ui/src/typings/types.ts index 4dac3971..eeabaf1c 100644 --- a/signup-ui/src/typings/types.ts +++ b/signup-ui/src/typings/types.ts @@ -203,7 +203,7 @@ export type RegistrationRequestDto = BaseRequestDto & { username: string; password: string; consent: string; - locale: string; + locale: string | null; userInfo: UserInfo; }; }; @@ -235,7 +235,7 @@ export type ResetPasswordRequestDto = BaseRequestDto & { request: { identifier: string; password: string; - locale: string; + locale: string | null; }; };