Login Page partially Completed

This commit is contained in:
Mosiur Rahman
2025-01-05 00:36:37 +06:00
committed by mosiur rahman
parent 5af95f296a
commit 854b4ecee6
2 changed files with 44 additions and 5 deletions

View File

@@ -1,7 +1,17 @@
<div class="container">
<div class="form">
<form>
login works!
<form [formGroup]=loginForm (ngSubmit)="login()">
<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>
</div>
</div>

View File

@@ -1,6 +1,6 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { Component, OnInit } from '@angular/core';
import { FormControl, ReactiveFormsModule, FormGroup } from '@angular/forms';
@Component({
selector: 'app-login',
@@ -9,6 +9,35 @@ import { ReactiveFormsModule } from '@angular/forms';
templateUrl: './login.component.html',
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');
}
}
}