Add login & logout
parent
cc193b6ae0
commit
0327597cd6
@ -1,27 +1,44 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FormControl, Validators } from '@angular/forms';
|
import { FormControl, Validators } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
import { AuthService } from '../../services/auth.service';
|
import { AuthService } from '../../services/auth.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
styleUrls: ['./login.component.scss']
|
styleUrls: ['./login.component.scss'],
|
||||||
})
|
})
|
||||||
export class LoginComponent implements OnInit {
|
export class LoginComponent implements OnInit {
|
||||||
email = new FormControl('', [Validators.required, Validators.email]);
|
email = new FormControl('', [Validators.required, Validators.email]);
|
||||||
password = new FormControl('', [Validators.required]);
|
password = new FormControl('', [Validators.required]);
|
||||||
hide = true;
|
hide = true;
|
||||||
loading = false;
|
loading = false;
|
||||||
constructor(private authService: AuthService) { }
|
errorOccurred = false;
|
||||||
|
errorMessage = '';
|
||||||
|
constructor(private authService: AuthService, private router: Router) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {}
|
||||||
}
|
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
|
this.errorMessage = '';
|
||||||
|
this.errorOccurred = false;
|
||||||
if (this.email.invalid || this.password.invalid) {
|
if (this.email.invalid || this.password.invalid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.authService.login(this.email.value, this.password.value).subscribe();
|
this.loading = true;
|
||||||
|
this.authService
|
||||||
|
.login(this.email.value, this.password.value)
|
||||||
|
.subscribe(
|
||||||
|
() => this.router.navigate(['bikes']),
|
||||||
|
(error) => {
|
||||||
|
this.errorOccurred = true;
|
||||||
|
this.errorMessage =
|
||||||
|
error.error.message ||
|
||||||
|
'Ein Fehler bei Einloggen ist aufgetreten. Überprüfen Sie Ihre Internetverbindung oder versuchen Sie es später erneut.';
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.add(() => {
|
||||||
|
this.loading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue