You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
import { Route } from '@angular/compiler/src/core';
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
import { Router } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
import { Login } from 'src/app/models/login';
|
|
import { User } from 'src/app/models/user';
|
|
import { UserService } from 'src/app/services/user.service';
|
|
|
|
@Component({
|
|
selector: 'app-login',
|
|
templateUrl: './login.component.html',
|
|
styleUrls: ['./login.component.css'],
|
|
})
|
|
export class LoginComponent implements OnInit {
|
|
username = new FormControl();
|
|
password = new FormControl();
|
|
responseMessage: string = '';
|
|
temp: Observable<User>;
|
|
errorMessage: string = '';
|
|
|
|
constructor(private _userService: UserService, private router: Router) {}
|
|
|
|
signup() {
|
|
this.router.navigateByUrl('/signup');
|
|
}
|
|
|
|
userLogin() {
|
|
let user: Login = {
|
|
userfirstname: this.username.value,
|
|
userpassword: this.password.value,
|
|
};
|
|
this.temp = this._userService.findUserByUsername(this.username.value);
|
|
this.temp.subscribe((v) => {
|
|
if (v.userpassword == this.password.value) {
|
|
this.temp.subscribe((v) => (this._userService.currentUser = v));
|
|
this.router.navigateByUrl('/home');
|
|
alert('Login Successfull !!');
|
|
} else {
|
|
this.errorMessage = 'Wrong Password.';
|
|
alert('Login falied !!');
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnInit(): void {}
|
|
}
|