Skip to content

Commit

Permalink
Fixed reset password (#680)
Browse files Browse the repository at this point in the history
Fixed reset password
  • Loading branch information
ygrik authored Jun 4, 2020
1 parent d5285c1 commit 4173ec1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ValidationReport } from "../../../../../contracts/validationReport";
})
export class ConfirmPassword {
private userId: string;
private token: string;
public readonly password: ko.Observable<string>;
public readonly passwordConfirmation: ko.Observable<string>;
public readonly isResetConfirmed: ko.Observable<boolean>;
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 17 additions & 2 deletions src/services/usersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const userId = parameters.get("userid");
const ticket = parameters.get("ticket");
Expand All @@ -67,8 +81,9 @@ export class UsersService {
await this.mapiClient.put<void>(requestUrl, [{ name: "Authorization", value: token }], {});
}

public async updatePassword(userId: string, newPassword: string): Promise<void> {
await this.mapiClient.patch(userId, undefined, { password: newPassword });
public async updatePassword(userId: string, newPassword: string, token: string): Promise<void> {
const heasers = [{ name: "Authorization", value: token }];
await this.mapiClient.patch(userId, heasers, { password: newPassword });
}

/**
Expand Down

0 comments on commit 4173ec1

Please sign in to comment.