Login Page partially Completed
This commit is contained in:
@@ -1,7 +1,17 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="form">
|
<div class="form">
|
||||||
<form>
|
<form [formGroup]=loginForm (ngSubmit)="login()">
|
||||||
login works!
|
<div class="form-control">
|
||||||
|
<label for="userName">Username: </label>
|
||||||
|
<input type="text" id="userName" name="userName" formControlName="userName">
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label for="password">Password: </label>
|
||||||
|
<input type="password" id="password" name="password" formControlName="password">
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Component } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { FormControl, ReactiveFormsModule, FormGroup } from '@angular/forms';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
@@ -9,6 +9,35 @@ import { ReactiveFormsModule } from '@angular/forms';
|
|||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
styleUrl: './login.component.scss'
|
styleUrl: './login.component.scss'
|
||||||
})
|
})
|
||||||
export class LoginComponent {
|
export class LoginComponent implements OnInit {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
loginForm = new FormGroup({
|
||||||
|
userName: new FormControl(''),
|
||||||
|
password: new FormControl('')
|
||||||
|
})
|
||||||
|
|
||||||
|
sample_user = [{
|
||||||
|
userName: 'admin',
|
||||||
|
password: 'admin'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userName: 'rashik',
|
||||||
|
password: '123'
|
||||||
|
}]
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
// do something
|
||||||
|
}
|
||||||
|
|
||||||
|
login() {
|
||||||
|
let username = this.loginForm.value.userName;
|
||||||
|
let password = this.loginForm.value.password;
|
||||||
|
if (this.sample_user.find(user=> user.userName === username && user.password === password)) {
|
||||||
|
console.log('Login Successful');
|
||||||
|
} else {
|
||||||
|
console.log('Login Failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user