From ddfca9c1378e36e0645cd7279360f591fe17db16 Mon Sep 17 00:00:00 2001 From: "s.ventura" Date: Tue, 23 Jan 2024 17:04:13 +0100 Subject: [PATCH] add logIn component --- db.json | 10 +++++ src/app/app-routing.module.ts | 11 ++++- src/app/app.module.ts | 3 +- src/app/classes/templog.ts | 12 ++++++ src/app/interfaces/templog.ts | 6 +++ src/app/login/login.component.css | 0 src/app/login/login.component.html | 17 ++++++++ src/app/login/login.component.spec.ts | 23 +++++++++++ src/app/login/login.component.ts | 42 ++++++++++++++++++++ src/app/nav/nav.component.html | 3 ++ src/app/user-detail/user-detail.component.ts | 2 - 11 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 src/app/classes/templog.ts create mode 100644 src/app/interfaces/templog.ts create mode 100644 src/app/login/login.component.css create mode 100644 src/app/login/login.component.html create mode 100644 src/app/login/login.component.spec.ts create mode 100644 src/app/login/login.component.ts diff --git a/db.json b/db.json index a0fabe53..b08fb7e1 100644 --- a/db.json +++ b/db.json @@ -29,6 +29,16 @@ "province": "pe", "phone": "23453453454", "age": 18 + }, + { + "id": "1fl2", + "name": "Giulio", + "lastname": "Diomede", + "email": "flavio.bonta@gmail.com", + "fiscalcode": "tdyfuvyghuj", + "province": "pe", + "phone": "23453453454", + "age": 18 } ] } \ No newline at end of file diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 7011f01c..7e9a07e6 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -6,8 +6,8 @@ import { UserComponent } from './user/user.component'; import { UserDetailComponent } from './user-detail/user-detail.component'; import { FormsModule } from '@angular/forms'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; -import { UserService } from './services/user.service'; import { UserDataComponent } from './user-data/user-data.component'; +import { LoginComponent } from './login/login.component'; const routes: Routes = [ @@ -26,6 +26,11 @@ const routes: Routes = [ path: 'users/new', component: UserDetailComponent, }, + { + path: 'users/login', + pathMatch:'full', + component: LoginComponent , + }, { path: 'users/:id/edit', component: UserDetailComponent, @@ -35,6 +40,7 @@ const routes: Routes = [ component: UserDataComponent, }, + ]; @NgModule({ @@ -42,6 +48,9 @@ const routes: Routes = [ UsersComponent, UserComponent, UserDetailComponent, + LoginComponent, + UserDataComponent, + ], imports: [RouterModule.forRoot(routes), FormsModule, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e3b47eda..a602b389 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -3,7 +3,6 @@ import { BrowserModule, provideClientHydration } from '@angular/platform-browser import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { NavComponent } from './nav/nav.component'; -import { UserDataComponent } from './user-data/user-data.component'; import { HttpClientModule } from '@angular/common/http'; @@ -11,7 +10,7 @@ import { HttpClientModule } from '@angular/common/http'; declarations: [ AppComponent, NavComponent, - UserDataComponent, + ], imports: [ diff --git a/src/app/classes/templog.ts b/src/app/classes/templog.ts new file mode 100644 index 00000000..605560b4 --- /dev/null +++ b/src/app/classes/templog.ts @@ -0,0 +1,12 @@ +import { TempLogInterface } from "../interfaces/templog"; + +export class TempLog implements TempLogInterface{ + name: string; + lastname: string; + + constructor(){ + this.name = ''; + this.lastname = ''; + } + +} \ No newline at end of file diff --git a/src/app/interfaces/templog.ts b/src/app/interfaces/templog.ts new file mode 100644 index 00000000..9507ffda --- /dev/null +++ b/src/app/interfaces/templog.ts @@ -0,0 +1,6 @@ +export interface TempLogInterface { + + name: string; + lastname: string; + + } \ No newline at end of file diff --git a/src/app/login/login.component.css b/src/app/login/login.component.css new file mode 100644 index 00000000..e69de29b diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html new file mode 100644 index 00000000..093aa12f --- /dev/null +++ b/src/app/login/login.component.html @@ -0,0 +1,17 @@ +
+
+ + +
+
+ + + +
+ + +
diff --git a/src/app/login/login.component.spec.ts b/src/app/login/login.component.spec.ts new file mode 100644 index 00000000..f1c475b7 --- /dev/null +++ b/src/app/login/login.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoginComponent } from './login.component'; + +describe('LoginComponent', () => { + let component: LoginComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [LoginComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(LoginComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts new file mode 100644 index 00000000..7170b255 --- /dev/null +++ b/src/app/login/login.component.ts @@ -0,0 +1,42 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { User } from '../classes/user'; +import { TempLog } from '../classes/templog'; +import { UserService } from '../services/user.service'; +import { Router } from '@angular/router'; + +@Component({ + selector: 'app-login', + templateUrl: './login.component.html', + styleUrl: './login.component.css' + +}) +export class LoginComponent implements OnInit { + @Input() templog = new TempLog ; + users: User[] = []; + + + constructor(private userService: UserService, private router: Router){ + + } + ngOnInit(): void { + this.userService.getUsers() + .subscribe(user => this.users = user); + + } + makeLogIn(){ + for (const user of this.users) { + + if((user.name == this.templog.name) && (user.lastname == this.templog.lastname)){ + this.router.navigateByUrl('/users/' + user.id ) + } + } + + } + emptyIn(){ + this.templog.name=''; + this.templog.lastname=''; + return this.templog + + } + +} diff --git a/src/app/nav/nav.component.html b/src/app/nav/nav.component.html index e7e83be8..f20f96b3 100644 --- a/src/app/nav/nav.component.html +++ b/src/app/nav/nav.component.html @@ -9,6 +9,9 @@ +