From 9bc20bb1b0fff43e63a1220b380beaa9e28c4a0d Mon Sep 17 00:00:00 2001 From: Igor O Date: Thu, 4 Jun 2020 12:54:16 -0700 Subject: [PATCH] Fixed reset password (#680) Fixed reset password --- .../ko/runtime/confirm-password.ts | 7 ++++--- src/services/usersService.ts | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/users/confirm-password/ko/runtime/confirm-password.ts b/src/components/users/confirm-password/ko/runtime/confirm-password.ts index 5adc3339b..f7096953a 100644 --- a/src/components/users/confirm-password/ko/runtime/confirm-password.ts +++ b/src/components/users/confirm-password/ko/runtime/confirm-password.ts @@ -16,6 +16,7 @@ import { ValidationReport } from "../../../../../contracts/validationReport"; }) export class ConfirmPassword { private userId: string; + private token: string; public readonly password: ko.Observable; public readonly passwordConfirmation: ko.Observable; public readonly isResetConfirmed: ko.Observable; @@ -66,8 +67,8 @@ export class ConfirmPassword { } try { - await this.usersService.activateUser(queryParams); - this.userId = await this.usersService.getCurrentUserId(); + this.token = this.usersService.getTokenFromTiketParams(queryParams); + this.userId = this.usersService.getUserIdFromParams(queryParams); if (!this.userId) { throw new Error("User not found."); @@ -103,7 +104,7 @@ export class ConfirmPassword { } try { - await this.usersService.updatePassword(this.userId, this.password()); + await this.usersService.updatePassword(this.userId, this.password(), this.token); this.isResetConfirmed(true); setTimeout(() => { this.usersService.navigateToHome(); diff --git a/src/services/usersService.ts b/src/services/usersService.ts index ca42b418d..d85456b66 100644 --- a/src/services/usersService.ts +++ b/src/services/usersService.ts @@ -56,6 +56,20 @@ export class UsersService { } } + public getTokenFromTiketParams(parameters: URLSearchParams): string { + const ticket = parameters.get("ticket"); + const ticketId = parameters.get("ticketid"); + const token = `Ticket id="${ticketId}",ticket="${ticket}"`; + + return token; + } + + public getUserIdFromParams(parameters: URLSearchParams): string { + const userId = parameters.get("userid"); + + return userId ? `/users/${userId}` : undefined; + } + public async activateUser(parameters: URLSearchParams): Promise { const userId = parameters.get("userid"); const ticket = parameters.get("ticket"); @@ -67,8 +81,9 @@ export class UsersService { await this.mapiClient.put(requestUrl, [{ name: "Authorization", value: token }], {}); } - public async updatePassword(userId: string, newPassword: string): Promise { - await this.mapiClient.patch(userId, undefined, { password: newPassword }); + public async updatePassword(userId: string, newPassword: string, token: string): Promise { + const heasers = [{ name: "Authorization", value: token }]; + await this.mapiClient.patch(userId, heasers, { password: newPassword }); } /**