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