Login Page partially Completed

This commit is contained in:
Mosiur Rahman
2025-01-05 00:36:37 +06:00
parent 2d5991dbf7
commit f5a86a0b5d
2 changed files with 44 additions and 5 deletions

View File

@@ -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>

View File

@@ -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');
}
}
} }