diff --git a/frontend/src/app/components/auth/landing-page/landing-page.component.html b/frontend/src/app/components/auth/landing-page/landing-page.component.html index 218fc95..9c165d7 100644 --- a/frontend/src/app/components/auth/landing-page/landing-page.component.html +++ b/frontend/src/app/components/auth/landing-page/landing-page.component.html @@ -21,7 +21,7 @@ [class.error-border]=" (!mail.valid && mail.touched) || (mail.touched && - !isUserEmailValid(authData.mail.toLowerCase()) && + !isUserEmailValid(authData.mail) && authData.mail.length > 0) " required @@ -30,7 +30,7 @@ @if (!mail.valid && mail.touched) {
Please enter your email
} @else { @if (mail.touched && authData.mail.length > 0 && - !isUserEmailValid(authData.mail.toLowerCase())) { + !isUserEmailValid(authData.mail)) {This is not a valid email format
}} diff --git a/frontend/src/app/components/auth/landing-page/landing-page.component.ts b/frontend/src/app/components/auth/landing-page/landing-page.component.ts index 732b510..e3e11eb 100644 --- a/frontend/src/app/components/auth/landing-page/landing-page.component.ts +++ b/frontend/src/app/components/auth/landing-page/landing-page.component.ts @@ -19,18 +19,35 @@ export class LandingPageComponent { send: false, }; + /** + * Initializes the LandingPageComponent with Router, AuthService, and ErrorService. + */ constructor( private router: Router, - public errorService: ErrorService, - private authService: AuthService + private authService: AuthService, + public errorService: ErrorService ) {} - isUserEmailValid(emailValue: string) { + /** + * Validates the given email address. + * Converts to lowercase before checking against the regex. + * + * @param emailValue The email address to validate. + * @returns True if the email format is valid, false otherwise. + */ + isUserEmailValid(emailValue: string): boolean { const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/; - return emailRegex.test(emailValue); + return emailRegex.test(emailValue.toLowerCase()); } - async onSubmit(ngForm: NgForm, mailInput: any) { + /** + * Handles form submission. + * If the form is valid, checks for duplicate email addresses. + * + * @param ngForm The submitted form. + * @param mailInput The input field for the email. + */ + async onSubmit(ngForm: NgForm, mailInput: any): PromisePlease enter your email
} @else { @if (mail.touched && authData.mail.length > 0 && - !isUserEmailValid(authData.mail.toLowerCase())) { + !isUserEmailValid(authData.mail)) {This is not a valid email format
}} diff --git a/frontend/src/app/components/auth/login/login.component.ts b/frontend/src/app/components/auth/login/login.component.ts index 1682640..b08a54d 100644 --- a/frontend/src/app/components/auth/login/login.component.ts +++ b/frontend/src/app/components/auth/login/login.component.ts @@ -15,6 +15,8 @@ import { environment } from '../../../../environments/environment'; styleUrl: './login.component.scss', }) export class LoginComponent { + showPassword: boolean = false; + authData = { mail: '', password: '', @@ -23,49 +25,64 @@ export class LoginComponent { guestLogin: false, }; - showPassword: boolean = false; - + /** + * Initializes the LoginComponent with Router, AuthService, and ErrorService. + */ constructor( + private router: Router, public authService: AuthService, - public errorService: ErrorService, - private router: Router + public errorService: ErrorService ) {} - isUserEmailValid(emailValue: string) { + /** + * Validates the given email address. + * Converts to lowercase before checking against the regex. + * + * @param emailValue The email address to validate. + * @returns True if the email format is valid, false otherwise. + */ + isUserEmailValid(emailValue: string): boolean { const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/; - return emailRegex.test(emailValue); + return emailRegex.test(emailValue.toLowerCase()); } - async guestLogin(ngForm: NgForm) { - this.authData.mail = environment.guestMail; - this.authData.password = environment.guestPassword; - this.authData.guestLogin = true; - const body = { - email: environment.guestMail, - password: environment.guestPassword, - }; + /** + * Logs the user in as a guest using predefined credentials from the environment. + * Resets form and navigates to the main application area on success. + * + * @param ngForm The login form instance. + */ + async guestLogin(ngForm: NgForm): PromisePlease enter your email
} @else { @if (mail.touched && authData.mail.length > 0 && - !isUserEmailValid(authData.mail.toLowerCase())) { + !isUserEmailValid(authData.mail)) {This is not a valid email format
}} diff --git a/frontend/src/app/components/auth/register/register.component.ts b/frontend/src/app/components/auth/register/register.component.ts index 7dd9bef..ff6d8f5 100644 --- a/frontend/src/app/components/auth/register/register.component.ts +++ b/frontend/src/app/components/auth/register/register.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { BtnLargeComponent } from '../../../shared/components/buttons/btn-large/btn-large.component'; import { FormsModule, NgForm } from '@angular/forms'; -import { ActivatedRoute, Router, RouterLink } from '@angular/router'; +import { ActivatedRoute, RouterLink } from '@angular/router'; import { CommonModule } from '@angular/common'; import { AuthService } from '../../../services/auth.service'; import { ErrorService } from '../../../services/error.service'; @@ -14,6 +14,8 @@ import { ErrorService } from '../../../services/error.service'; styleUrl: './register.component.scss', }) export class RegisterComponent implements OnInit { + registrationSuccess: boolean = false; + authData = { mail: '', password: '', @@ -22,34 +24,56 @@ export class RegisterComponent implements OnInit { send: false, }; - registrationSuccess: boolean = false; - + /** + * Initializes the LoginComponent with ActivatedRoute, AuthService, and ErrorService. + */ constructor( private route: ActivatedRoute, public authService: AuthService, public errorService: ErrorService ) {} + /** + * Initializes the component by setting up necessary data. + */ ngOnInit(): void { + this.setEmailFromQueryParams(); + } + + /** + * Sets the email address from the query parameters in the URL. + */ + private setEmailFromQueryParams(): void { this.route.queryParams.subscribe((params) => { this.authData.mail = params['mail'] || ''; }); } - isUserEmailValid(emailValue: string) { + /** + * Validates the given email address. + * Converts to lowercase before checking against the regex. + * + * @param emailValue The email address to validate. + * @returns True if the email format is valid, false otherwise. + */ + isUserEmailValid(emailValue: string): boolean { const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/; - return emailRegex.test(emailValue); + return emailRegex.test(emailValue.toLowerCase()); } - async onSubmit(ngForm: NgForm) { + /** + * Handles form submission for user registration. + * Sends registration request and handles success/error responses. + * + * @param ngForm The registration form instance. + */ + async onSubmit(ngForm: NgForm): Promise