This commit is contained in:
2020-03-02 18:47:04 +01:00
committed by smuddy
parent 5b746e0db5
commit ccd91aa81c
93 changed files with 444 additions and 89 deletions

View File

@@ -0,0 +1,36 @@
import {Component, OnInit} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {AngularFireAuth} from '@angular/fire/auth';
import {Router} from '@angular/router';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.less']
})
export class LoginComponent implements OnInit {
public form: FormGroup;
public errorMessage: string;
constructor(public afAuth: AngularFireAuth, private router: Router) {
}
ngOnInit() {
this.form = new FormGroup({
user: new FormControl(null, [Validators.required, Validators.email]),
pass: new FormControl(null, [Validators.required]),
});
}
public async onLogin() {
this.form.updateValueAndValidity();
if (this.form.valid) {
try {
await this.afAuth.auth.signInWithEmailAndPassword(this.form.value.user, this.form.value.pass);
await this.router.navigateByUrl('/');
} catch (ex) {
this.errorMessage = ex.code;
}
}
}
}