From 0bc7af7e1e3035afb7ee5e984494f0b085de9bc4 Mon Sep 17 00:00:00 2001 From: Nikodem Keller Date: Fri, 13 Sep 2024 04:26:39 +0200 Subject: [PATCH] Snackbar for log-in and register --- src/app/user/log-in/log-in.component.ts | 13 ++++++++----- src/app/user/register/register.component.ts | 15 ++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/app/user/log-in/log-in.component.ts b/src/app/user/log-in/log-in.component.ts index 449ba1c..4a977ac 100644 --- a/src/app/user/log-in/log-in.component.ts +++ b/src/app/user/log-in/log-in.component.ts @@ -1,8 +1,9 @@ -import { Component } from '@angular/core'; -import {UserService} from "../user.service"; +import {Component} from '@angular/core'; import {Router} from "@angular/router"; import {FormsModule} from "@angular/forms"; import {AuthService} from "../../auth/auth.service"; +import {SnackbarService} from "../../shared/snackbar/snackbar.service"; +import {SnackbarType} from "../../shared/snackbar/snackbar-type"; @Component({ selector: 'app-log-in', @@ -17,7 +18,10 @@ export class LogInComponent { username: string = ''; password: string = ''; - constructor(private router: Router, private authService: AuthService) {} + constructor(private router: Router, + private authService: AuthService, + private snackbarService: SnackbarService, + ) {} onSubmit() { this.authService.login(this.username, this.password).subscribe({ @@ -25,8 +29,7 @@ export class LogInComponent { this.router.navigate(['/']); }, error: err => { - console.error('Login failed', err); - // handle error (show message to user, etc.) + this.snackbarService.displaySnackbar("Wrong username or password", SnackbarType.DARK); } }); } diff --git a/src/app/user/register/register.component.ts b/src/app/user/register/register.component.ts index 3b0dffa..36d00b7 100644 --- a/src/app/user/register/register.component.ts +++ b/src/app/user/register/register.component.ts @@ -1,7 +1,9 @@ -import { Component } from '@angular/core'; +import {Component} from '@angular/core'; import {Router} from "@angular/router"; import {FormsModule} from "@angular/forms"; import {AuthService} from "../../auth/auth.service"; +import {SnackbarService} from "../../shared/snackbar/snackbar.service"; +import {SnackbarType} from "../../shared/snackbar/snackbar-type"; @Component({ selector: 'app-register', @@ -18,11 +20,14 @@ export class RegisterComponent { confirmPassword: string = ''; login: string = ''; - constructor(private router: Router, private authService: AuthService) {} + constructor(private router: Router, + private authService: AuthService, + private snackbarService: SnackbarService, + ) {} onSubmit() { if (this.password !== this.confirmPassword) { - console.error('Passwords do not match'); + this.snackbarService.displaySnackbar('Passwords do not match',SnackbarType.DARK); return; } @@ -34,11 +39,11 @@ export class RegisterComponent { this.authService.register(user).subscribe({ next: response => { + this.snackbarService.displaySnackbar('Your registration was successful!',SnackbarType.DARK); this.router.navigate(['/log-in']); }, error: err => { - console.error('Registration failed', err); - // handle error (show message to user, etc.) + this.snackbarService.displaySnackbar('Username already exist',SnackbarType.DARK); } }); }