Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | 111x 1x 1x 1x 1x 1x 1x 1x 28x 798x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28x | import { Component, inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { MessageService } from 'primeng/api';
import { ReactiveFormsModule } from '@angular/forms';
import { NgClass, NgIf } from '@angular/common';
import { StyleService } from '../../services/style.service';
import { TwinpadApiService } from '../../services/twinpad-api.service';
@Component({
selector: 'app-register',
imports: [ReactiveFormsModule, NgClass, NgIf],
templateUrl: './register.component.html',
styleUrl: './register.component.scss'
})
export class RegisterComponent implements OnInit{
messageService = inject(MessageService);
firstname: string;
lastname: string;
email: string;
password: string;
registerForm: FormGroup;
passwordValidatorRegex: RegExp = /^(?=[^A-Z]*[A-Z])(?=[^a-z]*[a-z])(?=\D*\d)(?=.*[!@#$%^&-_~*]).{10,}$/;
companyLogo: string;
constructor(private router: Router, private fb: FormBuilder, private twinpadApiService: TwinpadApiService,
private styleService: StyleService
){}
ngOnInit() {
this.companyLogo = this.styleService.defaultLogo;
// Initialize the form
this.registerForm = this.fb.group({
firstname: ['', [Validators.required]],
lastname: ['', [Validators.required]],
email: ['', [Validators.required, Validators.email]], // Add validation for email
password: ['', [Validators.required, Validators.pattern(this.passwordValidatorRegex)]]
});
// Watch for email input changes
this.registerForm.get('email')?.valueChanges.subscribe((email: string) => {
this.updateCompanyLogo(email);
});
}
get passwordFromField() {
return this.registerForm.get('password');
}
register() {
this.firstname = this.registerForm.get('firstname')?.value;
this.lastname = this.registerForm.get('lastname')?.value;
this.email = this.registerForm.get('email')?.value;
this.password = this.registerForm.get('password')?.value;
Iif(this.firstname === "" || this.lastname === "" || this.email === "" || this.password === "") {
this.messageService.add({ severity: "error", summary: "User failed to be created", detail: "One or many fields are missing" });
return false;
}
return this.twinpadApiService.register(this.firstname, this.lastname, this.email, this.password).subscribe(
{
next: _value => {
this.messageService.add({severity:'success', summary: 'User created', detail: "User successfully created" });
setTimeout(() => {
this.router.navigate(['/login'], {
queryParams: { email: this.email }
});
}, 1500);
},
error: err => {
this.messageService.add({severity:'error', summary: 'User failed to be created', detail: err.error.detail });
}
});
}
updateCompanyLogo(email: string) {
// Parse the domain from the email
this.companyLogo = this.styleService.getCustomerLogoFromEmail(email);
// Set the company logo based on the domain
}
}
|