Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Password): Allow special characters in password #1402

Merged
merged 15 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"@stomp/rx-stomp": "^1.1.4",
"@stomp/stompjs": "^5.4.4",
"@tinymce/tinymce-angular": "^4.2.4",
"@zxcvbn-ts/core": "^2.2.1",
"@zxcvbn-ts/language-en": "^2.1.0",
"angular-password-strength-meter": "^6.0.0",
"canvg": "^2.0.0",
"compute-covariance": "^1.0.1",
"core-js": "^3.22.0",
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export function initialize(
MatDialogModule,
RecaptchaV3Module,
RouterModule.forRoot([], {
scrollPositionRestoration: 'enabled',
anchorScrolling: 'enabled'
})
scrollPositionRestoration: 'enabled',
anchorScrolling: 'enabled'
})
],
providers: [
ConfigService,
Expand Down
27 changes: 27 additions & 0 deletions src/app/common/password-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FormGroup } from '@angular/forms';
import { NewPasswordAndConfirmComponent } from '../password/new-password-and-confirm/new-password-and-confirm.component';
import { PasswordErrors } from '../domain/password/password-errors';

export function changePasswordError(
error: any,
hirokiterashima marked this conversation as resolved.
Show resolved Hide resolved
incorrectPasswordFormGroup: FormGroup,
invalidPasswordFormGroup: FormGroup,
previousPasswordFieldName: string
): void {
switch (error.messageCode) {
case 'incorrectPassword':
incorrectPasswordFormGroup
.get(previousPasswordFieldName)
.setErrors({ incorrectPassword: true });
break;
case 'invalidPassword':
injectPasswordErrors(invalidPasswordFormGroup, error);
break;
}
}

export function injectPasswordErrors(formGroup: FormGroup, passwordErrors: PasswordErrors): void {
formGroup
.get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
.setErrors(passwordErrors);
}
19 changes: 19 additions & 0 deletions src/app/domain/password/password-errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export class PasswordErrors {
messageCode: string = 'invalidPassword';
missingLetter: boolean;
missingNumber: boolean;
missingSymbol: boolean;
tooShort: boolean;

constructor(
missingLetter: boolean,
missingNumber: boolean,
missingSymbol: boolean,
tooShort: boolean
) {
this.missingLetter = missingLetter;
this.missingNumber = missingNumber;
this.missingSymbol = missingSymbol;
this.tooShort = tooShort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class MockStudentService {
}
}

const PASSWORD = 'Abcd1234';
const PASSWORD = 'abcd1234!';

describe('ForgotStudentPasswordChangeComponent', () => {
let component: ForgotStudentPasswordChangeComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { StudentService } from '../../../student/student.service';
import { finalize } from 'rxjs/operators';
import { NewPasswordAndConfirmComponent } from '../../../password/new-password-and-confirm/new-password-and-confirm.component';
import { injectPasswordErrors } from '../../../common/password-helper';

@Component({
selector: 'forgot-student-password-change',
Expand Down Expand Up @@ -63,19 +64,9 @@ export class ForgotStudentPasswordChangeComponent implements OnInit {
}

private changePasswordError(error: any): void {
hirokiterashima marked this conversation as resolved.
Show resolved Hide resolved
const formError: any = {};
switch (error.messageCode) {
case 'invalidPasswordLength':
formError.minlength = true;
this.changePasswordFormGroup
.get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
.setErrors(formError);
break;
case 'invalidPasswordPattern':
formError.pattern = true;
this.changePasswordFormGroup
.get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
.setErrors(formError);
case 'invalidPassword':
injectPasswordErrors(this.changePasswordFormGroup, error);
break;
default:
this.setErrorOccurredMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe('ForgotTeacherPasswordChangeComponent', () => {
MatCardModule,
MatDividerModule,
PasswordModule,
RouterTestingModule,
ReactiveFormsModule
ReactiveFormsModule,
RouterTestingModule
],
providers: [{ provide: TeacherService, useClass: MockTeacherService }],
schemas: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AbstractControl, FormBuilder, FormGroup } from '@angular/forms';
import { TeacherService } from '../../../teacher/teacher.service';
import { finalize } from 'rxjs/operators';
import { NewPasswordAndConfirmComponent } from '../../../password/new-password-and-confirm/new-password-and-confirm.component';
import { injectPasswordErrors } from '../../../common/password-helper';

@Component({
selector: 'app-forgot-teacher-password-change',
Expand Down Expand Up @@ -68,7 +69,6 @@ export class ForgotTeacherPasswordChangeComponent implements OnInit {
}

private changePasswordError(error: any): void {
hirokiterashima marked this conversation as resolved.
Show resolved Hide resolved
const formError: any = {};
switch (error.messageCode) {
case 'tooManyVerificationCodeAttempts':
this.setTooManyVerificationCodeAttemptsMessage();
Expand All @@ -85,23 +85,13 @@ export class ForgotTeacherPasswordChangeComponent implements OnInit {
case 'verificationCodeIncorrect':
this.setVerificationCodeIncorrectMessage();
break;
case 'invalidPasswordLength':
formError.minlength = true;
this.changePasswordFormGroup
.get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
.setErrors(formError);
break;
case 'invalidPasswordPattern':
formError.pattern = true;
this.changePasswordFormGroup
.get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
.setErrors(formError);
case 'invalidPassword':
injectPasswordErrors(this.changePasswordFormGroup, error);
break;
case 'passwordDoesNotMatch':
formError.passwordDoesNotMatch = true;
this.changePasswordFormGroup
.get(NewPasswordAndConfirmComponent.CONFIRM_NEW_PASSWORD_FORM_CONTROL_NAME)
.setErrors(formError);
.setErrors({ passwordDoesNotMatch: true });
break;
default:
this.setErrorOccurredMessage();
Expand Down
Loading