added login functionality to LoginComponent

This commit is contained in:
2020-07-21 15:25:12 +02:00
parent 23e687de27
commit 205a65cf45

View File

@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms'; import { FormControl, FormGroup } from '@angular/forms';
import { AccountService } from '../account.service'; import { AccountService } from '../account.service';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { first } from 'rxjs/operators';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
@@ -18,11 +19,16 @@ export class LoginComponent implements OnInit {
onLogin() { onLogin() {
this.loading = true; this.loading = true;
if (this.form.invalid) { this.accountService.login(this.form.controls['username'], this.form.controls['password'])
return; .pipe(first())
} .subscribe(data => {
console.log(this.form.value); this.router.navigate([this.returnUrl]);
},
error => {
// TODO error handling
console.log(error);
this.loading = false;
});
} }
constructor(private accountService: AccountService, constructor(private accountService: AccountService,