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.
51 lines
1.5 KiB
51 lines
1.5 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>;
|
|
// temp : User;
|
|
temps : Observable<string>;
|
|
userList : Observable<User[]>;
|
|
|
|
constructor(private _userService : UserService, private router : Router) {}
|
|
|
|
userLogin() {
|
|
// alert(this.username.value+" | "+this.password.value);
|
|
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.responseMessage = "Login success !!";
|
|
else
|
|
this.responseMessage = "Password Incorrect.";
|
|
});
|
|
|
|
if(this.responseMessage == "Login success !!") {
|
|
this.temp.subscribe(v => this._userService.currentUser = v);
|
|
this.router.navigateByUrl('/home');
|
|
}
|
|
else
|
|
alert(this.responseMessage);
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
}
|