diff --git a/src/app/register/register-student-form/register-student-form.component.html b/src/app/register/register-student-form/register-student-form.component.html
index b0efca7b5e5..15415ac3044 100644
--- a/src/app/register/register-student-form/register-student-form.component.html
+++ b/src/app/register/register-student-form/register-student-form.component.html
@@ -93,7 +93,7 @@
Create Student Account
>
-
+
Security Question
@@ -130,7 +130,7 @@ Create Student Account
-
+
Create Student Account
Privacy Policy and
Terms of Service apply.
-
+
Recaptcha failed. Please reload the page and try again!
diff --git a/src/app/register/register-student-form/register-student-form.component.spec.ts b/src/app/register/register-student-form/register-student-form.component.spec.ts
index 841c09d7c8c..f4ac3c01720 100644
--- a/src/app/register/register-student-form/register-student-form.component.spec.ts
+++ b/src/app/register/register-student-form/register-student-form.component.spec.ts
@@ -168,7 +168,7 @@ async function createAccount() {
PASSWORD
)
);
- component.studentUser.isRecaptchaInvalid = true;
+ component.user.isRecaptchaInvalid = true;
spyOn(recaptchaV3Service, 'execute').and.returnValue(of(''));
const errorMessage = 'recaptchaResponseInvalid';
const response: any = helpers.createAccountErrorResponse(errorMessage);
diff --git a/src/app/register/register-student-form/register-student-form.component.ts b/src/app/register/register-student-form/register-student-form.component.ts
index 2a26d0b5cbb..24f82ef2145 100644
--- a/src/app/register/register-student-form/register-student-form.component.ts
+++ b/src/app/register/register-student-form/register-student-form.component.ts
@@ -44,23 +44,21 @@ export class RegisterStudentFormComponent extends RegisterUserFormComponent impl
{ code: '11', label: $localize`11 (Nov)` },
{ code: '12', label: $localize`12 (Dec)` }
];
- passwordsFormGroup: FormGroup = this.fb.group({});
- processing: boolean = false;
securityQuestions: object;
- studentUser: Student = new Student();
+ user: Student = new Student();
constructor(
private changeDetectorRef: ChangeDetectorRef,
private configService: ConfigService,
- private fb: FormBuilder,
+ protected fb: FormBuilder,
private recaptchaV3Service: ReCaptchaV3Service,
private router: Router,
private route: ActivatedRoute,
- private snackBar: MatSnackBar,
+ protected snackBar: MatSnackBar,
private studentService: StudentService,
private utilService: UtilService
) {
- super();
+ super(fb, snackBar);
this.studentService.retrieveSecurityQuestions().subscribe((response) => {
this.securityQuestions = response;
});
@@ -68,7 +66,7 @@ export class RegisterStudentFormComponent extends RegisterUserFormComponent impl
ngOnInit() {
this.route.params.subscribe((params) => {
- this.studentUser.googleUserId = params['gID'];
+ this.user.googleUserId = params['gID'];
if (!this.isUsingGoogleId()) {
this.createStudentAccountFormGroup.addControl('passwords', this.passwordsFormGroup);
this.createStudentAccountFormGroup.addControl(
@@ -102,14 +100,14 @@ export class RegisterStudentFormComponent extends RegisterUserFormComponent impl
}
isUsingGoogleId() {
- return this.studentUser.googleUserId != null;
+ return this.user.googleUserId != null;
}
async createAccount() {
if (this.createStudentAccountFormGroup.valid) {
this.processing = true;
await this.populateStudentUser();
- this.studentService.registerStudentAccount(this.studentUser).subscribe(
+ this.studentService.registerStudentAccount(this.user).subscribe(
(response: any) => {
this.createAccountSuccess(response);
},
@@ -128,46 +126,22 @@ export class RegisterStudentFormComponent extends RegisterUserFormComponent impl
this.processing = false;
}
- createAccountError(error: any): void {
- const formError: any = {};
- switch (error.messageCode) {
- case 'invalidPasswordLength':
- formError.minlength = true;
- this.passwordsFormGroup
- .get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
- .setErrors(formError);
- break;
- case 'invalidPasswordPattern':
- formError.pattern = true;
- this.passwordsFormGroup
- .get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
- .setErrors(formError);
- break;
- case 'recaptchaResponseInvalid':
- this.studentUser['isRecaptchaInvalid'] = true;
- break;
- default:
- this.snackBar.open(this.translateCreateAccountErrorMessageCode(error.messageCode));
- }
- this.processing = false;
- }
-
async populateStudentUser() {
for (let key of Object.keys(this.createStudentAccountFormGroup.controls)) {
if (key == 'birthMonth' || key == 'birthDay') {
- this.studentUser[key] = parseInt(this.createStudentAccountFormGroup.get(key).value);
+ this.user[key] = parseInt(this.createStudentAccountFormGroup.get(key).value);
} else {
- this.studentUser[key] = this.createStudentAccountFormGroup.get(key).value;
+ this.user[key] = this.createStudentAccountFormGroup.get(key).value;
}
}
if (this.isRecaptchaEnabled) {
const token = await this.recaptchaV3Service.execute('importantAction').toPromise();
- this.studentUser['token'] = token;
+ this.user['token'] = token;
}
if (!this.isUsingGoogleId()) {
- this.studentUser['password'] = this.getPassword();
- delete this.studentUser['passwords'];
- delete this.studentUser['googleUserId'];
+ this.user['password'] = this.getPassword();
+ delete this.user['passwords'];
+ delete this.user['googleUserId'];
}
}
diff --git a/src/app/register/register-teacher-form/register-teacher-form.component.html b/src/app/register/register-teacher-form/register-teacher-form.component.html
index 4c30d8ee5d5..467a5d2a797 100644
--- a/src/app/register/register-teacher-form/register-teacher-form.component.html
+++ b/src/app/register/register-teacher-form/register-teacher-form.component.html
@@ -115,7 +115,7 @@ Create Teacher Account
School Level
@@ -141,7 +141,7 @@ Create Teacher Account
/>
-
+
Create Teacher Account
Privacy Policy and
Terms of Service apply.
-
+
Recaptcha failed. Please reload the page and try again!
diff --git a/src/app/register/register-teacher-form/register-teacher-form.component.spec.ts b/src/app/register/register-teacher-form/register-teacher-form.component.spec.ts
index 10327066997..0a90d517488 100644
--- a/src/app/register/register-teacher-form/register-teacher-form.component.spec.ts
+++ b/src/app/register/register-teacher-form/register-teacher-form.component.spec.ts
@@ -167,7 +167,7 @@ async function createAccount() {
true
)
);
- component.teacherUser.isRecaptchaInvalid = true;
+ component.user.isRecaptchaInvalid = true;
spyOn(recaptchaV3Service, 'execute').and.returnValue(of(''));
const errorMessage = 'recaptchaResponseInvalid';
const response: any = helpers.createAccountErrorResponse(errorMessage);
diff --git a/src/app/register/register-teacher-form/register-teacher-form.component.ts b/src/app/register/register-teacher-form/register-teacher-form.component.ts
index 67716c928c7..d096e990c02 100644
--- a/src/app/register/register-teacher-form/register-teacher-form.component.ts
+++ b/src/app/register/register-teacher-form/register-teacher-form.component.ts
@@ -38,25 +38,25 @@ export class RegisterTeacherFormComponent extends RegisterUserFormComponent impl
passwordsFormGroup = this.fb.group({});
processing: boolean = false;
schoolLevels: SchoolLevel[] = schoolLevels;
- teacherUser: Teacher = new Teacher();
+ user: Teacher = new Teacher();
constructor(
private changeDetectorRef: ChangeDetectorRef,
private configService: ConfigService,
- private fb: FormBuilder,
+ protected fb: FormBuilder,
private recaptchaV3Service: ReCaptchaV3Service,
private router: Router,
private route: ActivatedRoute,
- private snackBar: MatSnackBar,
+ protected snackBar: MatSnackBar,
private teacherService: TeacherService,
private utilService: UtilService
) {
- super();
+ super(fb, snackBar);
}
ngOnInit(): void {
this.route.params.subscribe((params) => {
- this.teacherUser.googleUserId = params['gID'];
+ this.user.googleUserId = params['gID'];
if (!this.isUsingGoogleId()) {
this.createTeacherAccountFormGroup.addControl('passwords', this.passwordsFormGroup);
}
@@ -74,7 +74,7 @@ export class RegisterTeacherFormComponent extends RegisterUserFormComponent impl
}
private isUsingGoogleId(): boolean {
- return this.teacherUser.googleUserId != null;
+ return this.user.googleUserId != null;
}
private setControlFieldValue(name: string, value: string): void {
@@ -86,7 +86,7 @@ export class RegisterTeacherFormComponent extends RegisterUserFormComponent impl
if (this.createTeacherAccountFormGroup.valid) {
this.processing = true;
await this.populateTeacherUser();
- this.teacherService.registerTeacherAccount(this.teacherUser).subscribe(
+ this.teacherService.registerTeacherAccount(this.user).subscribe(
(response: any) => {
this.createAccountSuccess(response);
},
@@ -105,42 +105,18 @@ export class RegisterTeacherFormComponent extends RegisterUserFormComponent impl
this.processing = false;
}
- private createAccountError(error: any): void {
- const formError: any = {};
- switch (error.messageCode) {
- case 'invalidPasswordLength':
- formError.minlength = true;
- this.passwordsFormGroup
- .get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
- .setErrors(formError);
- break;
- case 'invalidPasswordPattern':
- formError.pattern = true;
- this.passwordsFormGroup
- .get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
- .setErrors(formError);
- break;
- case 'recaptchaResponseInvalid':
- this.teacherUser['isRecaptchaInvalid'] = true;
- break;
- default:
- this.snackBar.open(this.translateCreateAccountErrorMessageCode(error.messageCode));
- }
- this.processing = false;
- }
-
private async populateTeacherUser() {
for (let key of Object.keys(this.createTeacherAccountFormGroup.controls)) {
- this.teacherUser[key] = this.createTeacherAccountFormGroup.get(key).value;
+ this.user[key] = this.createTeacherAccountFormGroup.get(key).value;
}
if (this.isRecaptchaEnabled) {
const token = await this.recaptchaV3Service.execute('importantAction').toPromise();
- this.teacherUser['token'] = token;
+ this.user['token'] = token;
}
if (!this.isUsingGoogleId()) {
- this.teacherUser['password'] = this.getPassword();
- delete this.teacherUser['passwords'];
- delete this.teacherUser['googleUserId'];
+ this.user['password'] = this.getPassword();
+ delete this.user['passwords'];
+ delete this.user['googleUserId'];
}
}
diff --git a/src/app/register/register-user-form/register-user-form.component.ts b/src/app/register/register-user-form/register-user-form.component.ts
index 4e046ddc0cf..41645944e8b 100644
--- a/src/app/register/register-user-form/register-user-form.component.ts
+++ b/src/app/register/register-user-form/register-user-form.component.ts
@@ -1,10 +1,44 @@
+import { MatSnackBar } from '@angular/material/snack-bar';
+import { User } from '../../domain/user';
+import { NewPasswordAndConfirmComponent } from '../../password/new-password-and-confirm/new-password-and-confirm.component';
+import { FormBuilder, FormGroup } from '@angular/forms';
+
export class RegisterUserFormComponent {
- NAME_REGEX = '^[a-zA-Z]+([ -]?[a-zA-Z]+)*$';
+ protected NAME_REGEX = '^[a-zA-Z]+([ -]?[a-zA-Z]+)*$';
+
+ protected confirmPasswordLabel: string = $localize`Confirm Password`;
+ protected passwordLabel: string = $localize`Password`;
+ protected passwordsFormGroup: FormGroup = this.fb.group({});
+ protected processing: boolean = false;
+ user: User;
+
+ constructor(protected fb: FormBuilder, protected snackBar: MatSnackBar) {}
- confirmPasswordLabel: string = $localize`Confirm Password`;
- passwordLabel: string = $localize`Password`;
+ protected createAccountError(error: any): void {
+ const formError: any = {};
+ switch (error.messageCode) {
+ case 'invalidPasswordLength':
+ formError.minlength = true;
+ this.passwordsFormGroup
+ .get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
+ .setErrors(formError);
+ break;
+ case 'invalidPasswordPattern':
+ formError.pattern = true;
+ this.passwordsFormGroup
+ .get(NewPasswordAndConfirmComponent.NEW_PASSWORD_FORM_CONTROL_NAME)
+ .setErrors(formError);
+ break;
+ case 'recaptchaResponseInvalid':
+ this.user['isRecaptchaInvalid'] = true;
+ break;
+ default:
+ this.snackBar.open(this.translateCreateAccountErrorMessageCode(error.messageCode));
+ }
+ this.processing = false;
+ }
- translateCreateAccountErrorMessageCode(messageCode: string) {
+ private translateCreateAccountErrorMessageCode(messageCode: string): string {
switch (messageCode) {
case 'invalidFirstAndLastName':
return $localize`Error: First Name and Last Name must only contain characters A-Z, a-z, spaces, or dashes and can not start or end with a space or dash`;
diff --git a/src/messages.xlf b/src/messages.xlf
index 17eb5d5ccf1..aa83700b406 100644
--- a/src/messages.xlf
+++ b/src/messages.xlf
@@ -7244,35 +7244,35 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Confirm Password
src/app/register/register-user-form/register-user-form.component.ts
- 4
+ 9
src/app/register/register-user-form/register-user-form.component.ts
- 5
+ 10
src/app/register/register-user-form/register-user-form.component.ts
- 10
+ 44
src/app/register/register-user-form/register-user-form.component.ts
- 12
+ 46
src/app/register/register-user-form/register-user-form.component.ts
- 14
+ 48