Skip to content

Commit 3a9078b

Browse files
authored
Disable reset password for signed in users (#2308)
* Disable reset password for signed in users * code review fix
1 parent fe8d7da commit 3a9078b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/components/users/confirm-password/ko/runtime/confirm-password.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</div>
2121

2222
<div class="form-group">
23-
<button type="submit" id="signup" class="button button-primary">
23+
<button type="submit" id="signup" class="button button-primary" data-bind="attr: { disabled: isResetPasswordDisabled() }">
2424
Reset
2525
</button>
2626
</div>

src/components/users/confirm-password/ko/runtime/confirm-password.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export class ConfirmPassword {
2121
public readonly password: ko.Observable<string>;
2222
public readonly passwordConfirmation: ko.Observable<string>;
2323
public readonly isResetConfirmed: ko.Observable<boolean>;
24-
public readonly working: ko.Observable<boolean>;
24+
public readonly isResetPasswordDisabled: ko.Observable<boolean>;
2525

2626
constructor(
2727
private readonly usersService: UsersService,
2828
private readonly eventManager: EventManager) {
2929
this.password = ko.observable();
3030
this.passwordConfirmation = ko.observable();
3131
this.isResetConfirmed = ko.observable(false);
32-
this.working = ko.observable(false);
32+
this.isResetPasswordDisabled = ko.observable(true);
3333

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

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

@@ -69,12 +70,19 @@ export class ConfirmPassword {
6970
} catch (error) {
7071
dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Activate user error: " + error.message]);
7172
}
73+
74+
this.isResetPasswordDisabled(false);
7275
}
7376

7477
/**
7578
* Sends user resetPswd request to Management API.
7679
*/
7780
public async resetPswd(): Promise<void> {
81+
if (this.token == undefined || this.userId == undefined) {
82+
dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Required params not found"]);
83+
return;
84+
}
85+
7886
const result = validation.group({
7987
password: this.password,
8088
passwordConfirmation: this.passwordConfirmation

0 commit comments

Comments
 (0)