Skip to content

Commit cce3286

Browse files
authored
Fix/1032 bug (#645)
* fix(password): updated password hint * fix(password): updated password styles
1 parent 617241c commit cce3286

File tree

11 files changed

+60
-75
lines changed

11 files changed

+60
-75
lines changed

src/app/features/auth/pages/reset-password/reset-password.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h2 class="text-center">{{ 'auth.resetPassword.title' | translate }}</h2>
1414
autocomplete="new-password"
1515
></p-password>
1616

17-
<osf-password-input-hint [isError]="isNewPasswordError" />
17+
<osf-password-input-hint [control]="resetPasswordForm.controls['newPassword']" />
1818
</div>
1919

2020
<div class="flex flex-column">

src/app/features/auth/pages/reset-password/reset-password.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,17 @@ export class ResetPasswordComponent {
3030

3131
resetPasswordForm: ResetPasswordFormGroupType = this.fb.group(
3232
{
33-
newPassword: ['', [CustomValidators.requiredTrimmed(), Validators.pattern(this.passwordRegex)]],
33+
newPassword: [
34+
'',
35+
[CustomValidators.requiredTrimmed(), Validators.minLength(8), Validators.pattern(this.passwordRegex)],
36+
],
3437
confirmNewPassword: ['', CustomValidators.requiredTrimmed()],
3538
},
3639
{
3740
validators: CustomValidators.passwordMatchValidator('newPassword', 'confirmNewPassword'),
3841
}
3942
);
4043

41-
get isNewPasswordError() {
42-
return this.resetPasswordForm.get('newPassword')?.errors && this.resetPasswordForm.get('newPassword')?.touched;
43-
}
44-
4544
get isMismatchError(): boolean {
4645
return (
4746
this.resetPasswordForm.get('confirmNewPassword')?.dirty &&

src/app/features/auth/pages/sign-up/sign-up.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ <h2 class="text-center">{{ 'auth.signUp.title' | translate }}</h2>
8989
autocomplete="new-password"
9090
styleClass="w-full"
9191
></p-password>
92-
<osf-password-input-hint [isError]="isPasswordError" />
92+
<osf-password-input-hint [control]="signUpForm.controls['password']" />
9393
</div>
9494

9595
<div class="flex mt-1">

src/app/features/auth/pages/sign-up/sign-up.component.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,11 @@ export class SignUpComponent implements OnInit {
4747
private readonly environment = inject(ENVIRONMENT);
4848

4949
signUpForm = new FormGroup<SignUpForm>({} as SignUpForm);
50-
passwordRegex: RegExp = PASSWORD_REGEX;
5150
inputLimits = InputLimits;
5251
isFormSubmitted = signal(false);
5352

5453
readonly siteKey = this.environment.recaptchaSiteKey;
5554

56-
get isPasswordError() {
57-
return this.signUpForm.controls['password'].errors && this.signUpForm.get('password')?.touched;
58-
}
59-
6055
ngOnInit(): void {
6156
this.initializeForm();
6257
}
@@ -76,7 +71,7 @@ export class SignUpComponent implements OnInit {
7671
}),
7772
password: new FormControl('', {
7873
nonNullable: true,
79-
validators: [CustomValidators.requiredTrimmed(), Validators.pattern(this.passwordRegex)],
74+
validators: [CustomValidators.requiredTrimmed(), Validators.minLength(8), Validators.pattern(PASSWORD_REGEX)],
8075
}),
8176
acceptedTermsOfService: new FormControl(false, {
8277
nonNullable: true,

src/app/features/settings/account-settings/components/change-password/change-password.component.html

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,6 @@ <h2>{{ 'settings.accountSettings.changePassword.title' | translate }}</h2>
4747
"
4848
/>
4949

50-
@if (
51-
FormValidationHelper.hasError(getFormControl(AccountSettingsPasswordFormControls.NewPassword), 'required')
52-
) {
53-
<small class="text-red-500 mt-1">
54-
{{ 'settings.accountSettings.changePassword.validation.newPasswordRequired' | translate }}
55-
</small>
56-
}
57-
58-
@if (
59-
FormValidationHelper.hasError(getFormControl(AccountSettingsPasswordFormControls.NewPassword), 'minlength')
60-
) {
61-
<small class="text-red-500 mt-1">
62-
{{ 'settings.accountSettings.changePassword.validation.newPasswordMinLength' | translate }}
63-
</small>
64-
}
65-
66-
@if (
67-
FormValidationHelper.hasError(getFormControl(AccountSettingsPasswordFormControls.NewPassword), 'pattern')
68-
) {
69-
<small class="text-red-500 mt-1">
70-
{{ 'settings.accountSettings.changePassword.validation.newPasswordPattern' | translate }}
71-
</small>
72-
}
73-
7450
@if (
7551
getFormErrors()['sameAsOldPassword'] &&
7652
FormValidationHelper.isFieldTouched(getFormControl(AccountSettingsPasswordFormControls.NewPassword))
@@ -80,9 +56,7 @@ <h2>{{ 'settings.accountSettings.changePassword.title' | translate }}</h2>
8056
</small>
8157
}
8258

83-
<small class="password-help mt-1">
84-
{{ 'settings.accountSettings.changePassword.form.passwordRequirements' | translate }}
85-
</small>
59+
<osf-password-input-hint [control]="getFormControl(AccountSettingsPasswordFormControls.NewPassword)" />
8660
</div>
8761

8862
<div class="flex flex-column flex-1">
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
.password-help {
2-
color: var(--pr-blue-1);
3-
font-size: 0.75rem;
4-
font-weight: 600;
5-
}

src/app/features/settings/account-settings/components/change-password/change-password.component.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ import {
2020
} from '@angular/forms';
2121

2222
import { AuthService } from '@osf/core/services';
23-
import { CustomValidators, FormValidationHelper } from '@osf/shared/helpers';
23+
import { PasswordInputHintComponent } from '@osf/shared/components';
24+
import { CustomValidators, FormValidationHelper, PASSWORD_REGEX } from '@osf/shared/helpers';
2425
import { LoaderService, ToastService } from '@osf/shared/services';
2526

2627
import { AccountSettingsPasswordForm, AccountSettingsPasswordFormControls } from '../../models';
2728
import { UpdatePassword } from '../../store';
2829

2930
@Component({
3031
selector: 'osf-change-password',
31-
imports: [Card, ReactiveFormsModule, Password, CommonModule, Button, TranslatePipe],
32+
imports: [Card, ReactiveFormsModule, Password, CommonModule, Button, TranslatePipe, PasswordInputHintComponent],
3233
templateUrl: './change-password.component.html',
3334
styleUrl: './change-password.component.scss',
3435
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -47,11 +48,7 @@ export class ChangePasswordComponent implements OnInit {
4748
}),
4849
[AccountSettingsPasswordFormControls.NewPassword]: new FormControl('', {
4950
nonNullable: true,
50-
validators: [
51-
CustomValidators.requiredTrimmed(),
52-
Validators.minLength(8),
53-
Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[\d!@#$%^&*])[A-Za-z\d!@#$%^&*_]{8,}$/),
54-
],
51+
validators: [CustomValidators.requiredTrimmed(), Validators.minLength(8), Validators.pattern(PASSWORD_REGEX)],
5552
}),
5653
[AccountSettingsPasswordFormControls.ConfirmPassword]: new FormControl('', {
5754
nonNullable: true,
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
<small [class]="isError() ? 'text-danger' : ''">
2-
{{ 'auth.common.password.requirements' | translate }}
3-
</small>
1+
@if (validationError) {
2+
<small class="text-danger font-semibold mt-1">
3+
@switch (validationError) {
4+
@case ('required') {
5+
{{ 'auth.common.password.validation.required' | translate }}
6+
}
7+
@case ('minlength') {
8+
{{ 'auth.common.password.validation.minlength' | translate }}
9+
}
10+
@case ('pattern') {
11+
{{ 'auth.common.password.validation.pattern' | translate }}
12+
}
13+
}
14+
</small>
15+
} @else {
16+
<small class="hint-text font-semibold mt-1">
17+
{{ 'auth.common.password.requirements' | translate }}
18+
</small>
19+
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
:host {
2-
color: var(--primary-blue-1);
3-
font-weight: 600;
4-
font-size: 0.85rem;
1+
.text-danger {
2+
color: var(--red-1);
3+
}
54

6-
.text-danger {
7-
color: var(--red-1);
8-
}
5+
.hint-text {
6+
color: var(--pr-blue-1);
97
}
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import { TranslatePipe } from '@ngx-translate/core';
22

3-
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
4-
5-
import { BooleanOrNullOrUndefined } from '@osf/shared/helpers';
3+
import { CommonModule } from '@angular/common';
4+
import { Component, input } from '@angular/core';
5+
import { AbstractControl } from '@angular/forms';
66

77
@Component({
88
selector: 'osf-password-input-hint',
9-
imports: [TranslatePipe],
9+
imports: [TranslatePipe, CommonModule],
1010
templateUrl: './password-input-hint.component.html',
1111
styleUrl: './password-input-hint.component.scss',
12-
changeDetection: ChangeDetectionStrategy.OnPush,
1312
})
1413
export class PasswordInputHintComponent {
15-
isError = input<BooleanOrNullOrUndefined>(false);
14+
control = input<AbstractControl | null>(null);
15+
16+
get validationError(): string | null {
17+
const ctrl = this.control();
18+
if (!ctrl || !ctrl.errors || !ctrl.touched) return null;
19+
20+
if (ctrl.errors['required']) return 'required';
21+
if (ctrl.errors['minlength']) return 'minlength';
22+
if (ctrl.errors['pattern']) return 'pattern';
23+
24+
return null;
25+
}
1626
}

0 commit comments

Comments
 (0)