Add auth module.
This commit is contained in:
51
src/app/auth/auth.component.ts
Normal file
51
src/app/auth/auth.component.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||
import {CustomValidator} from '../_helpers';
|
||||
|
||||
@Component({
|
||||
selector: 'app-auth',
|
||||
templateUrl: './auth.component.html',
|
||||
styleUrls: ['./auth.component.scss']
|
||||
})
|
||||
export class AuthComponent implements OnInit {
|
||||
registerForm: FormGroup;
|
||||
submitted: boolean = false;
|
||||
loading: boolean = false;
|
||||
error: any;
|
||||
|
||||
constructor(
|
||||
private formBuilder: FormBuilder,
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.registerForm = this.formBuilder.group({
|
||||
email: ['', Validators.required],
|
||||
password: ['', [
|
||||
// 1. Password Field is Required
|
||||
Validators.required,
|
||||
// 2. check whether the entered password has a number
|
||||
CustomValidator.patternValidator(/\d/, { hasNumber: true }),
|
||||
// 3. check whether the entered password has upper case letter
|
||||
CustomValidator.patternValidator(/[A-Z]/, { hasCapitalCase: true }),
|
||||
// 4. check whether the entered password has a lower-case letter
|
||||
CustomValidator.patternValidator(/[a-z]/, { hasSmallCase: true }),
|
||||
// 6. Has a minimum length of 8 characters
|
||||
Validators.minLength(8)]],
|
||||
confirmPassword: ['', Validators.required],
|
||||
terms: ['', Validators.required]
|
||||
}, {
|
||||
// validator for the form group
|
||||
validator: CustomValidator.passwordMatchValidator
|
||||
});
|
||||
}
|
||||
|
||||
get form(): any { return this.registerForm.controls; }
|
||||
|
||||
onSubmit(): void {
|
||||
this.submitted = true;
|
||||
|
||||
if (this.registerForm.invalid) { return; }
|
||||
|
||||
this.loading = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user