diff --git a/application/src/main/java/org/thingsboard/server/controller/AuthController.java b/application/src/main/java/org/thingsboard/server/controller/AuthController.java index 66e5cf6f90..0e21444431 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AuthController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AuthController.java @@ -228,10 +228,9 @@ public class AuthController extends BaseController { @ApiOperation(value = "Reset password (resetPassword)", notes = "Checks the password reset token and updates the password. " + - "If token is valid, returns the object that contains [JWT](https://jwt.io/) access and refresh tokens. " + "If token is not valid, returns '400 Bad Request'.") @PostMapping(value = "/noauth/resetPassword") - public JwtPair resetPassword(@Parameter(description = "Reset password request.") + public void resetPassword(@Parameter(description = "Reset password request.") @RequestBody ResetPasswordRequest resetPasswordRequest, HttpServletRequest request) throws ThingsboardException { String resetToken = resetPasswordRequest.getResetToken(); @@ -263,8 +262,6 @@ public class AuthController extends BaseController { } eventPublisher.publishEvent(new UserCredentialsInvalidationEvent(securityUser.getId())); - - return tokenFactory.createTokenPair(securityUser); } else { throw new ThingsboardException("Invalid reset token!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); } diff --git a/application/src/test/java/org/thingsboard/server/controller/UserControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/UserControllerTest.java index 7d40e56a57..d7aa6f5770 100644 --- a/application/src/test/java/org/thingsboard/server/controller/UserControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/UserControllerTest.java @@ -233,16 +233,9 @@ public class UserControllerTest extends AbstractControllerTest { .put("password", "testPassword2"); Mockito.doNothing().when(mailService).sendPasswordWasResetEmail(anyString(), anyString()); - JsonNode tokenInfo = readResponse( - doPost("/api/noauth/resetPassword", resetPasswordRequest) - .andExpect(status().isOk()), JsonNode.class); + doPost("/api/noauth/resetPassword", resetPasswordRequest) + .andExpect(status().isOk()); Mockito.verify(mailService).sendPasswordWasResetEmail(anyString(), anyString()); - validateAndSetJwtToken(tokenInfo, email); - - doGet("/api/auth/user") - .andExpect(status().isOk()) - .andExpect(jsonPath("$.authority", is(Authority.TENANT_ADMIN.name()))) - .andExpect(jsonPath("$.email", is(email))); resetTokens(); diff --git a/ui-ngx/src/app/core/auth/auth.service.ts b/ui-ngx/src/app/core/auth/auth.service.ts index ba0161ed02..f8ffd5e8b6 100644 --- a/ui-ngx/src/app/core/auth/auth.service.ts +++ b/ui-ngx/src/app/core/auth/auth.service.ts @@ -152,12 +152,8 @@ export class AuthService { )); } - public resetPassword(resetToken: string, password: string): Observable { - return this.http.post('/api/noauth/resetPassword', {resetToken, password}, defaultHttpOptions()).pipe( - tap((loginResponse: LoginResponse) => { - this.setUserFromJwtToken(loginResponse.token, loginResponse.refreshToken, true); - } - )); + public resetPassword(resetToken: string, password: string): Observable { + return this.http.post('/api/noauth/resetPassword', {resetToken, password}, defaultHttpOptions()); } public changePassword(currentPassword: string, newPassword: string, config?: RequestConfig) { diff --git a/ui-ngx/src/app/modules/login/pages/login/reset-password.component.ts b/ui-ngx/src/app/modules/login/pages/login/reset-password.component.ts index c751fc5e62..202722cf15 100644 --- a/ui-ngx/src/app/modules/login/pages/login/reset-password.component.ts +++ b/ui-ngx/src/app/modules/login/pages/login/reset-password.component.ts @@ -22,7 +22,7 @@ import { PageComponent } from '@shared/components/page.component'; import { UntypedFormBuilder } from '@angular/forms'; import { ActionNotificationShow } from '@core/notification/notification.actions'; import { TranslateService } from '@ngx-translate/core'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { Subscription } from 'rxjs'; @Component({ @@ -44,6 +44,7 @@ export class ResetPasswordComponent extends PageComponent implements OnInit, OnD constructor(protected store: Store, private route: ActivatedRoute, + private router: Router, private authService: AuthService, private translate: TranslateService, public fb: UntypedFormBuilder) { @@ -71,7 +72,9 @@ export class ResetPasswordComponent extends PageComponent implements OnInit, OnD } else { this.authService.resetPassword( this.resetToken, - this.resetPassword.get('newPassword').value).subscribe(); + this.resetPassword.get('newPassword').value).subscribe( + () => this.router.navigateByUrl('login') + ); } } }