Skip to content

Commit

Permalink
Disable reset password for signed in users (#2308)
Browse files Browse the repository at this point in the history
* Disable reset password for signed in users

* code review fix
  • Loading branch information
malincrist authored Jan 30, 2024
1 parent 8b3c6f9 commit 9f4d773
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>

<div class="form-group">
<button type="submit" id="signup" class="button button-primary">
<button type="submit" id="signup" class="button button-primary" data-bind="attr: { disabled: isResetPasswordDisabled() }">
Reset
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export class ConfirmPassword {
public readonly password: ko.Observable<string>;
public readonly passwordConfirmation: ko.Observable<string>;
public readonly isResetConfirmed: ko.Observable<boolean>;
public readonly working: ko.Observable<boolean>;
public readonly isResetPasswordDisabled: ko.Observable<boolean>;

constructor(
private readonly usersService: UsersService,
private readonly eventManager: EventManager) {
this.password = ko.observable();
this.passwordConfirmation = ko.observable();
this.isResetConfirmed = ko.observable(false);
this.working = ko.observable(false);
this.isResetPasswordDisabled = ko.observable(true);

validation.init({
insertMessages: false,
Expand All @@ -49,6 +49,7 @@ export class ConfirmPassword {
this.userId = await this.usersService.getCurrentUserId();

if (this.userId) {
dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Cannot reset password for a signed in user."]);
return;
}

Expand All @@ -69,12 +70,19 @@ export class ConfirmPassword {
} catch (error) {
dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Activate user error: " + error.message]);
}

this.isResetPasswordDisabled(false);
}

/**
* Sends user resetPswd request to Management API.
*/
public async resetPswd(): Promise<void> {
if (this.token == undefined || this.userId == undefined) {
dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Required params not found"]);
return;
}

const result = validation.group({
password: this.password,
passwordConfirmation: this.passwordConfirmation
Expand Down

0 comments on commit 9f4d773

Please sign in to comment.