-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from szymonpoltorak/register
Register
- Loading branch information
Showing
28 changed files
with
446 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
{ | ||
"name": "todo-app-frontend", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"ng": "ng", | ||
"start": "ng serve", | ||
"build": "ng build", | ||
"watch": "ng build --watch --configuration development", | ||
"test": "ng test" | ||
}, | ||
"private": true, | ||
"dependencies": { | ||
"@angular/animations": "^16.2.0", | ||
"@angular/cdk": "^16.2.8", | ||
"@angular/common": "^16.2.0", | ||
"@angular/compiler": "^16.2.0", | ||
"@angular/core": "^16.2.0", | ||
"@angular/forms": "^16.2.0", | ||
"@angular/material": "^16.2.8", | ||
"@angular/platform-browser": "^16.2.0", | ||
"@angular/platform-browser-dynamic": "^16.2.0", | ||
"@angular/router": "^16.2.0", | ||
"rxjs": "~7.8.0", | ||
"tslib": "^2.3.0", | ||
"zone.js": "~0.13.0" | ||
}, | ||
"devDependencies": { | ||
"@angular-devkit/build-angular": "^16.2.6", | ||
"@angular/cli": "^16.2.6", | ||
"@angular/compiler-cli": "^16.2.0", | ||
"@types/jasmine": "~4.3.0", | ||
"autoprefixer": "^10.4.16", | ||
"jasmine-core": "~4.6.0", | ||
"karma": "~6.4.0", | ||
"karma-chrome-launcher": "~3.2.0", | ||
"karma-coverage": "~2.2.0", | ||
"karma-jasmine": "~5.1.0", | ||
"karma-jasmine-html-reporter": "~2.1.0", | ||
"scss": "^0.2.4", | ||
"typescript": "~5.1.3" | ||
} | ||
"name": "todo-app-frontend", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"ng": "ng", | ||
"start": "ng serve", | ||
"build": "ng build", | ||
"watch": "ng build --watch --configuration development", | ||
"test": "ng test" | ||
}, | ||
"private": true, | ||
"dependencies": { | ||
"@angular/animations": "^16.2.0", | ||
"@angular/cdk": "^16.2.8", | ||
"@angular/common": "^16.2.0", | ||
"@angular/compiler": "^16.2.0", | ||
"@angular/core": "^16.2.0", | ||
"@angular/forms": "^16.2.0", | ||
"@angular/material": "^16.2.8", | ||
"@angular/platform-browser": "^16.2.0", | ||
"@angular/platform-browser-dynamic": "^16.2.0", | ||
"@angular/router": "^16.2.0", | ||
"rxjs": "~7.8.0", | ||
"tslib": "^2.3.0", | ||
"zone.js": "~0.13.0" | ||
}, | ||
"devDependencies": { | ||
"@angular-devkit/build-angular": "^16.2.6", | ||
"@angular/cli": "^16.2.6", | ||
"@angular/compiler-cli": "^16.2.0", | ||
"@types/jasmine": "~4.3.0", | ||
"autoprefixer": "^10.4.16", | ||
"jasmine-core": "~4.6.0", | ||
"karma": "~6.4.0", | ||
"karma-chrome-launcher": "~3.2.0", | ||
"karma-coverage": "~2.2.0", | ||
"karma-jasmine": "~5.1.0", | ||
"karma-jasmine-html-reporter": "~2.1.0", | ||
"scss": "^0.2.4", | ||
"typescript": "~5.1.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
export enum RouterPaths { | ||
CURRENT_PATH = "", | ||
LOGIN_AUTH_PATH = "login", | ||
REGISTER_AUTH_PATH = "register", | ||
REGISTER_FULL_PATH = "auth/register", | ||
LOGIN_FULL_PATH = "auth/login", | ||
} |
83 changes: 83 additions & 0 deletions
83
todo-app-frontend/src/app/core/validators/form-validator.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms"; | ||
import { FormValidation } from "@enums/FormValidation"; | ||
import { PasswordValidatorService } from "@core/validators/password-validator.service"; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class FormValidatorService { | ||
readonly nameControl: FormControl = new FormControl(FormValidation.NAME_VALUE, | ||
[ | ||
Validators.required, | ||
Validators.maxLength(FormValidation.NAME_MAX_LENGTH), | ||
Validators.minLength(FormValidation.NAME_MIN_LENGTH), | ||
Validators.pattern(FormValidation.NAME_PATTERN) | ||
] | ||
); | ||
|
||
readonly surnameControl: FormControl = new FormControl(FormValidation.NAME_VALUE, | ||
[ | ||
Validators.required, | ||
Validators.maxLength(FormValidation.NAME_MAX_LENGTH), | ||
Validators.minLength(FormValidation.NAME_MIN_LENGTH), | ||
Validators.pattern(FormValidation.NAME_PATTERN) | ||
] | ||
); | ||
|
||
readonly emailControl: FormControl = new FormControl( | ||
FormValidation.EMAIL_VALUE, | ||
[ | ||
Validators.required, | ||
Validators.pattern(FormValidation.EMAIL_PATTERN) | ||
] | ||
); | ||
|
||
readonly passwordControl: FormControl = new FormControl( | ||
FormValidation.PASSWORD_VALUE, | ||
[ | ||
Validators.required, | ||
Validators.pattern(FormValidation.PASSWORD_PATTERN), | ||
] | ||
); | ||
|
||
readonly repeatPasswordControl: FormControl = new FormControl( | ||
FormValidation.PASSWORD_VALUE, | ||
[ | ||
Validators.required, | ||
Validators.pattern(FormValidation.PASSWORD_PATTERN), | ||
] | ||
); | ||
|
||
private readonly passwordName: string = "userPassword"; | ||
private readonly repeatPassword: string = "repeatPassword"; | ||
|
||
constructor(private formBuilder: FormBuilder, | ||
private passwordValidator: PasswordValidatorService) { | ||
} | ||
|
||
buildFormGroup(): FormGroup { | ||
return this.formBuilder.group({ | ||
email: this.emailControl, | ||
password: this.passwordControl | ||
}); | ||
} | ||
|
||
buildRegisterFormGroup(): FormGroup { | ||
return this.formBuilder.group({ | ||
nameInputs: this.formBuilder.group({ | ||
firstName: this.nameControl, | ||
lastName: this.surnameControl | ||
}), | ||
email: this.emailControl, | ||
passwordInputs: this.formBuilder.group({ | ||
userPassword: this.passwordControl, | ||
repeatPassword: this.repeatPasswordControl | ||
}, | ||
{ | ||
validator: this.passwordValidator.passwordMatchValidator(this.passwordName, this.repeatPassword) | ||
} | ||
) | ||
}); | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
todo-app-frontend/src/app/core/validators/login-validator.service.ts
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
todo-app-frontend/src/app/core/validators/password-validator.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { AbstractControl, ValidatorFn } from "@angular/forms"; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class PasswordValidatorService { | ||
constructor() { | ||
} | ||
|
||
passwordMatchValidator(passwordFieldName: string, repeatFieldName: string): ValidatorFn { | ||
return (control: AbstractControl): { [key: string]: any } | null => { | ||
const userPassword: AbstractControl<any, any> | null = control.get(passwordFieldName); | ||
const repeatPassword: AbstractControl<any, any> | null = control.get(repeatFieldName); | ||
|
||
if (!userPassword || !repeatPassword) { | ||
return null; | ||
} | ||
return userPassword.value !== repeatPassword.value ? {'passwordMatch': true} : null; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
todo-app-frontend/src/app/pages/auth/auth-utils/email-field/email-field.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
todo-app-frontend/src/app/pages/auth/auth-utils/name-field/name-field.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<mat-form-field class="full-width"> | ||
<mat-label>{{ nameLabel }}</mat-label> | ||
|
||
<input [formControl]="nameControl" matInput placeholder="Your {{ nameLabel }}" | ||
type="text"> | ||
|
||
<mat-error *ngIf="nameControl.hasError('pattern')"> | ||
Please enter a valid {{ nameLabel }} | ||
</mat-error> | ||
|
||
<mat-error *ngIf="nameControl.hasError('required')"> | ||
{{ nameLabel }} is <strong>required</strong> | ||
</mat-error> | ||
</mat-form-field> |
4 changes: 4 additions & 0 deletions
4
todo-app-frontend/src/app/pages/auth/auth-utils/name-field/name-field.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.full-width { | ||
width: 100%; | ||
margin: 5px; | ||
} |
39 changes: 39 additions & 0 deletions
39
todo-app-frontend/src/app/pages/auth/auth-utils/name-field/name-field.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR } from "@angular/forms"; | ||
|
||
@Component({ | ||
selector: 'app-name-field', | ||
templateUrl: './name-field.component.html', | ||
styleUrls: ['./name-field.component.scss'], | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: NameFieldComponent, | ||
multi: true, | ||
} | ||
] | ||
}) | ||
export class NameFieldComponent implements ControlValueAccessor { | ||
@Input() nameLabel: string = ""; | ||
@Input() nameControl !: FormControl; | ||
|
||
constructor() { | ||
} | ||
|
||
registerOnChange(onChange: any): void { | ||
this.onChange = onChange; | ||
} | ||
|
||
registerOnTouched(onTouched: any): void { | ||
this.onTouched = onTouched; | ||
} | ||
|
||
writeValue(obj: any): void { | ||
} | ||
|
||
private onChange = () => { | ||
}; | ||
|
||
private onTouched = () => { | ||
}; | ||
} |
6 changes: 3 additions & 3 deletions
6
todo-app-frontend/src/app/pages/auth/auth-utils/password-field/password-field.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.