From 3d9df20d455e576f70b6f1d25b8262d63fc103d1 Mon Sep 17 00:00:00 2001 From: AndriiD Date: Sat, 7 Jan 2023 18:00:49 +0200 Subject: [PATCH 1/3] resetPassword in AuthController now returns nothing instead of token pair, just updates password. Button 'reset password' in reset password form now redirects to login page --- .../thingsboard/server/controller/AuthController.java | 3 +-- ui-ngx/src/app/core/auth/auth.service.ts | 10 ++++------ .../login/pages/login/reset-password.component.ts | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) 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 0cb3a3fc92..1d1410b05a 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AuthController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AuthController.java @@ -278,7 +278,7 @@ public class AuthController extends BaseController { @RequestMapping(value = "/noauth/resetPassword", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) @ResponseBody - public JwtPair resetPassword( + public void resetPassword( @ApiParam(value = "Reset password request.") @RequestBody ResetPasswordRequest resetPasswordRequest, HttpServletRequest request) throws ThingsboardException { @@ -305,7 +305,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/ui-ngx/src/app/core/auth/auth.service.ts b/ui-ngx/src/app/core/auth/auth.service.ts index a62623260f..3eb596381d 100644 --- a/ui-ngx/src/app/core/auth/auth.service.ts +++ b/ui-ngx/src/app/core/auth/auth.service.ts @@ -156,12 +156,10 @@ 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) { + this.http.post('/api/noauth/resetPassword', {resetToken, password}, defaultHttpOptions()).subscribe( + () => { this.router.navigateByUrl('login'); }, () => {} + ); } 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 ab0928ec66..73d7da65d4 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 @@ -71,7 +71,7 @@ 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); } } } From bd8129082655e93908adff8a2ad292776cd10694 Mon Sep 17 00:00:00 2001 From: AndriiD Date: Mon, 16 Jan 2023 14:03:17 +0200 Subject: [PATCH 2/3] fix test --- .../server/controller/BaseUserControllerTest.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/controller/BaseUserControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/BaseUserControllerTest.java index 6429574e38..90d74a9117 100644 --- a/application/src/test/java/org/thingsboard/server/controller/BaseUserControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/BaseUserControllerTest.java @@ -235,16 +235,8 @@ public abstract class BaseUserControllerTest extends AbstractControllerTest { .put("resetToken", TestMailService.currentResetPasswordToken) .put("password", "testPassword2"); - JsonNode tokenInfo = readResponse( - doPost("/api/noauth/resetPassword", resetPasswordRequest) - .andExpect(status().isOk()), JsonNode.class); - validateAndSetJwtToken(tokenInfo, email); - - doGet("/api/auth/user") - .andExpect(status().isOk()) - .andExpect(jsonPath("$.authority", is(Authority.TENANT_ADMIN.name()))) - .andExpect(jsonPath("$.email", is(email))); + doPost("/api/noauth/resetPassword", resetPasswordRequest); resetTokens(); login(email, "testPassword2"); From 533f08464818f403728f54fcd3f2bbd2387a94bc Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Tue, 18 Apr 2023 16:41:29 +0300 Subject: [PATCH 3/3] UI: Fixed reset password service --- ui-ngx/src/app/core/auth/auth.service.ts | 6 ++---- .../modules/login/pages/login/reset-password.component.ts | 7 +++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ui-ngx/src/app/core/auth/auth.service.ts b/ui-ngx/src/app/core/auth/auth.service.ts index 3eb596381d..7b5a997804 100644 --- a/ui-ngx/src/app/core/auth/auth.service.ts +++ b/ui-ngx/src/app/core/auth/auth.service.ts @@ -156,10 +156,8 @@ export class AuthService { )); } - public resetPassword(resetToken: string, password: string) { - this.http.post('/api/noauth/resetPassword', {resetToken, password}, defaultHttpOptions()).subscribe( - () => { this.router.navigateByUrl('login'); }, () => {} - ); + 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 73d7da65d4..2857241c27 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 { FormBuilder } 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: FormBuilder) { @@ -71,7 +72,9 @@ export class ResetPasswordComponent extends PageComponent implements OnInit, OnD } else { this.authService.resetPassword( this.resetToken, - this.resetPassword.get('newPassword').value); + this.resetPassword.get('newPassword').value).subscribe( + () => this.router.navigateByUrl('login') + ); } } }