From d9286124e255415501900440618f4ecee9476378 Mon Sep 17 00:00:00 2001 From: amirch1 Date: Mon, 2 May 2022 15:47:08 +0300 Subject: [PATCH] fix(login): display authenticator field for 2FA reset password form SUP-31938 --- .../password-expired-form.component.html | 21 +++++++---- .../password-expired-form.component.scss | 8 ++++- .../password-expired-form.component.ts | 35 +++++++++++++++---- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/kmc-app/components/login/password-expired-form/password-expired-form.component.html b/src/kmc-app/components/login/password-expired-form/password-expired-form.component.html index ccda4d3562..0cec7a61aa 100644 --- a/src/kmc-app/components/login/password-expired-form/password-expired-form.component.html +++ b/src/kmc-app/components/login/password-expired-form/password-expired-form.component.html @@ -1,14 +1,14 @@
-

{{ 'app.login.passwordExpired.title' | translate}}

+

{{ 'app.login.passwordExpired.title' | translate}}

@@ -18,7 +18,7 @@

{{ 'app.login.passwordExpired.title' | translate}}

type="password" autocomplete="off" [placeholder]="'app.login.passwordExpired.placeholder.new' | translate" [formControl]="_newPasswordField" - [class.has-error]="_showError(_newPasswordField) || _passwordsDontMatch || _newPasswordIsOld || _passwordStructureInvalid" + [ngClass]="{smallMargin: showAuthenticationCode, 'has-error': _showError(_newPasswordField) || _passwordsDontMatch || _newPasswordIsOld || _passwordStructureInvalid}" [kTooltip]="_getClientValidationMessage(_newPasswordField) || _passwordStructureInvalidMessage | translate" placement="right"> @@ -28,23 +28,30 @@

{{ 'app.login.passwordExpired.title' | translate}}

type="password" autocomplete="off" [placeholder]="'app.login.passwordExpired.placeholder.confirm' | translate" [formControl]="_repeatPasswordField" - [class.has-error]="_showError(_repeatPasswordField) || _passwordsDontMatch" + [ngClass]="{smallMargin: showAuthenticationCode, 'has-error': _showError(_repeatPasswordField) || _passwordsDontMatch}" [kTooltip]="_getClientValidationMessage(_repeatPasswordField) | translate" placement="right"> +
+ +
+

-

-

+

{{'app.login.error.loginBlocked.loginDenied' | translate}} {{_supportAddress}} {{'app.login.error.loginBlocked.toUnblockYourAccount' | translate}}

-

+

{{'app.login.error.retriesExceeded.yourAccountHasBeenLocked' | translate}} {{_supportAddress}} {{'app.login.error.retriesExceeded.toUnblockYourAccount' | translate}} diff --git a/src/kmc-app/components/login/password-expired-form/password-expired-form.component.scss b/src/kmc-app/components/login/password-expired-form/password-expired-form.component.scss index 81b221a47a..25697a0377 100644 --- a/src/kmc-app/components/login/password-expired-form/password-expired-form.component.scss +++ b/src/kmc-app/components/login/password-expired-form/password-expired-form.component.scss @@ -13,6 +13,10 @@ font-weight: bold; line-height: 29px; text-align: center; + &.smallFont { + font-size: 18px; + line-height: 24px; + } } .kErrorMessage { @@ -37,7 +41,9 @@ color: $kGrayscale3; font-size: 16px; border-radius: 4px; - + &.smallMargin { + margin-bottom: 32px; + } &:placeholder-shown { background-color: $kGrayscale6; } diff --git a/src/kmc-app/components/login/password-expired-form/password-expired-form.component.ts b/src/kmc-app/components/login/password-expired-form/password-expired-form.component.ts index bf650e7fc0..f06b8be6d5 100644 --- a/src/kmc-app/components/login/password-expired-form/password-expired-form.component.ts +++ b/src/kmc-app/components/login/password-expired-form/password-expired-form.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { EqualFieldsValidator } from 'app-shared/kmc-shell/validators/equalFields.validator'; import { BrowserService } from 'app-shared/kmc-shell/providers'; @@ -11,19 +11,33 @@ import { serverConfig } from 'config/server'; }) export class PasswordExpiredFormComponent { @Input() errorMessage: string; - @Input() errorCode: string; + @Input() + set errorCode(value: string) { + this._errorCode = value; + if (value === 'MISSING_OTP') { + this.showAuthenticationCode = true; + setTimeout(() => { + this.authField.nativeElement.focus(); + },100) + } + }; @Input() inProgress = false; @Input() passwordRestored = false; - @Output() onResetPassword = new EventEmitter<{ password: string, newPassword: string }>(); + @Output() onResetPassword = new EventEmitter<{ password: string, newPassword: string, otp?: string }>(); + @ViewChild('auth', { static: true }) authField; public _formSent = false; public _resetPasswordForm: FormGroup; public _passwords: FormGroup; public _oldPasswordField: AbstractControl; public _newPasswordField: AbstractControl; + public _authenticationField: AbstractControl; public _repeatPasswordField: AbstractControl; public _supportAddress: string; + public showAuthenticationCode = false; + + public _errorCode: string; public get _sendBtnText(): string { return this.inProgress ? 'app.login.wait' : 'app.login.send'; @@ -38,11 +52,11 @@ export class PasswordExpiredFormComponent { } public get _oldPasswordWrong(): boolean { - return 'WRONG_OLD_PASSWORD' === this.errorCode; + return 'WRONG_OLD_PASSWORD' === this._errorCode; } public get _passwordStructureInvalid(): boolean { - return 'PASSWORD_STRUCTURE_INVALID' === this.errorCode; + return 'PASSWORD_STRUCTURE_INVALID' === this._errorCode; } public get _passwordStructureInvalidMessage(): string { @@ -68,19 +82,25 @@ export class PasswordExpiredFormComponent { validator: Validators.compose([ NotEqualFieldsValidator.validate(), EqualFieldsValidator.validate('newPassword', 'repeatPassword') ]) - }) + }), + authentication: [''], }); this._oldPasswordField = this._resetPasswordForm.controls['oldPassword']; this._passwords = this._resetPasswordForm.controls['passwords']; this._newPasswordField = this._passwords.controls['newPassword']; this._repeatPasswordField = this._passwords.controls['repeatPassword']; + this._authenticationField = this._resetPasswordForm.controls['authentication']; } public _showError(control: AbstractControl): boolean { return control.invalid && (control.dirty || this._formSent); } + public _showSuccess(control: AbstractControl): boolean { + return control.valid && control.dirty; + } + public _getClientValidationMessage(control: AbstractControl): string { const invalid = this._showError(control); let message = ''; @@ -105,7 +125,8 @@ export class PasswordExpiredFormComponent { this._formSent = false; this.onResetPassword.emit({ password: this._oldPasswordField.value, - newPassword: this._newPasswordField.value + newPassword: this._newPasswordField.value, + otp: this._authenticationField.value || '' }); } }