From aa959578dd7ec8f8f19424158238955ff324e8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Wed, 25 Mar 2020 11:26:18 +0100 Subject: [PATCH] Split de la page de login en 2 composants --- Front/skydivelogs-app/src/app/app.module.ts | 10 +- .../app/create-user/create-user.component.css | 0 .../create-user/create-user.component.html | 49 ++++++++++ .../create-user/create-user.component.spec.ts | 25 +++++ .../app/create-user/create-user.component.ts | 80 +++++++++++++++ .../app/login-user/login-user.component.css | 0 .../app/login-user/login-user.component.html | 23 +++++ .../login-user/login-user.component.spec.ts | 25 +++++ .../app/login-user/login-user.component.ts | 69 +++++++++++++ .../src/app/login/login.component.html | 55 ++--------- .../src/app/login/login.component.ts | 98 +------------------ Front/skydivelogs-app/src/models/user.ts | 1 + 12 files changed, 291 insertions(+), 144 deletions(-) create mode 100644 Front/skydivelogs-app/src/app/create-user/create-user.component.css create mode 100644 Front/skydivelogs-app/src/app/create-user/create-user.component.html create mode 100644 Front/skydivelogs-app/src/app/create-user/create-user.component.spec.ts create mode 100644 Front/skydivelogs-app/src/app/create-user/create-user.component.ts create mode 100644 Front/skydivelogs-app/src/app/login-user/login-user.component.css create mode 100644 Front/skydivelogs-app/src/app/login-user/login-user.component.html create mode 100644 Front/skydivelogs-app/src/app/login-user/login-user.component.spec.ts create mode 100644 Front/skydivelogs-app/src/app/login-user/login-user.component.ts diff --git a/Front/skydivelogs-app/src/app/app.module.ts b/Front/skydivelogs-app/src/app/app.module.ts index 79b43a2..f7f3bf8 100644 --- a/Front/skydivelogs-app/src/app/app.module.ts +++ b/Front/skydivelogs-app/src/app/app.module.ts @@ -44,11 +44,14 @@ import { MatPaginatorModule } from "@angular/material/paginator"; import { MatProgressSpinnerModule } from "@angular/material/progress-spinner"; import { MatSelectModule } from "@angular/material/select"; import { MatTableModule } from "@angular/material/table"; +import { MatTabsModule } from "@angular/material/tabs"; import { CachingInterceptor } from "../interceptor/caching.interceptor"; //import { BasicAuthInterceptor } from '../interceptor/basic-auth.interceptor'; import { JwtAuthInterceptor } from "../interceptor/jwt-auth.interceptor"; import { ErrorInterceptor } from "../interceptor/error.interceptor"; +import { CreateUserComponent } from "./create-user/create-user.component"; +import { LoginUserComponent } from "./login-user/login-user.component"; const appRoutes: Routes = [ { path: "", component: DefaultComponent, canActivate: [AuthGuardService] }, @@ -109,7 +112,9 @@ const appRoutes: Routes = [ NewDropZoneComponent, NewJumpTypeComponent, DefaultComponent, - LoginComponent + LoginComponent, + CreateUserComponent, + LoginUserComponent ], imports: [ RouterModule.forRoot( @@ -132,7 +137,8 @@ const appRoutes: Routes = [ MatButtonModule, MatIconModule, MatAutocompleteModule, - MatProgressSpinnerModule + MatProgressSpinnerModule, + MatTabsModule ], exports: [HttpClientModule], providers: [ diff --git a/Front/skydivelogs-app/src/app/create-user/create-user.component.css b/Front/skydivelogs-app/src/app/create-user/create-user.component.css new file mode 100644 index 0000000..e69de29 diff --git a/Front/skydivelogs-app/src/app/create-user/create-user.component.html b/Front/skydivelogs-app/src/app/create-user/create-user.component.html new file mode 100644 index 0000000..b767d64 --- /dev/null +++ b/Front/skydivelogs-app/src/app/create-user/create-user.component.html @@ -0,0 +1,49 @@ +
+
+ + +
+
Username is required
+
+
+
+ + +
+
Password is required
+
+
+ +
+ + +
+
Firstname is required
+
+
+
+ + +
+
Lastname is required
+
+
+
+ + +
+
E-mail is required
+
+
+ + +
{{error}}
+
diff --git a/Front/skydivelogs-app/src/app/create-user/create-user.component.spec.ts b/Front/skydivelogs-app/src/app/create-user/create-user.component.spec.ts new file mode 100644 index 0000000..0489eff --- /dev/null +++ b/Front/skydivelogs-app/src/app/create-user/create-user.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateUserComponent } from './create-user.component'; + +describe('CreateUserComponent', () => { + let component: CreateUserComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateUserComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateUserComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/Front/skydivelogs-app/src/app/create-user/create-user.component.ts b/Front/skydivelogs-app/src/app/create-user/create-user.component.ts new file mode 100644 index 0000000..a0c0073 --- /dev/null +++ b/Front/skydivelogs-app/src/app/create-user/create-user.component.ts @@ -0,0 +1,80 @@ +import { Component, OnInit } from "@angular/core"; +import { Router, ActivatedRoute } from "@angular/router"; +import { FormBuilder, FormGroup, Validators } from "@angular/forms"; + +import { first } from "rxjs/operators"; + +import { AuthenticationService } from "../../services/authentication.service"; +import { User } from "../../models/user"; + +@Component({ + selector: "app-create-user", + templateUrl: "./create-user.component.html", + styleUrls: ["./create-user.component.css"] +}) +export class CreateUserComponent implements OnInit { + createForm: FormGroup; + loading = false; + submitted = false; + returnUrl: string; + error = ""; + + constructor( + private formBuilder: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private authenticationService: AuthenticationService + ) { + // redirect to home if already logged in + if (this.authenticationService.currentUserValue) { + this.router.navigate(["/"]); + } + } + + ngOnInit() { + this.createForm = this.formBuilder.group({ + username: ["", Validators.required], + password: ["", Validators.required], + firstname: ["", Validators.required], + lastname: ["", Validators.required], + email: ["", Validators.required] + }); + + // get return url from route parameters or default to '/' + this.returnUrl = this.route.snapshot.queryParams["returnUrl"] || "/"; + } + + get createCtrls() { + return this.createForm.controls; + } + + onCreateSubmit() { + this.submitted = true; + + // stop here if form is invalid + if (this.createForm.invalid) { + return; + } + + this.loading = true; + let createUser = new User(); + createUser.login = this.createCtrls.username.value; + createUser.password = this.createCtrls.password.value; + createUser.firstName = this.createCtrls.firstname.value; + createUser.lastName = this.createCtrls.lastname.value; + createUser.email = this.createCtrls.email.value; + + this.authenticationService + .create(createUser) + .pipe(first()) + .subscribe( + data => { + this.router.navigate([this.returnUrl]); + }, + error => { + this.error = error; + this.loading = false; + } + ); + } +} diff --git a/Front/skydivelogs-app/src/app/login-user/login-user.component.css b/Front/skydivelogs-app/src/app/login-user/login-user.component.css new file mode 100644 index 0000000..e69de29 diff --git a/Front/skydivelogs-app/src/app/login-user/login-user.component.html b/Front/skydivelogs-app/src/app/login-user/login-user.component.html new file mode 100644 index 0000000..700a19d --- /dev/null +++ b/Front/skydivelogs-app/src/app/login-user/login-user.component.html @@ -0,0 +1,23 @@ +
+
+ + +
+
Username is required
+
+
+
+ + +
+
Password is required
+
+
+ +
{{error}}
+
diff --git a/Front/skydivelogs-app/src/app/login-user/login-user.component.spec.ts b/Front/skydivelogs-app/src/app/login-user/login-user.component.spec.ts new file mode 100644 index 0000000..b73be11 --- /dev/null +++ b/Front/skydivelogs-app/src/app/login-user/login-user.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoginUserComponent } from './login-user.component'; + +describe('LoginUserComponent', () => { + let component: LoginUserComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LoginUserComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LoginUserComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/Front/skydivelogs-app/src/app/login-user/login-user.component.ts b/Front/skydivelogs-app/src/app/login-user/login-user.component.ts new file mode 100644 index 0000000..9a89694 --- /dev/null +++ b/Front/skydivelogs-app/src/app/login-user/login-user.component.ts @@ -0,0 +1,69 @@ +import { Component, OnInit } from "@angular/core"; +import { Router, ActivatedRoute } from "@angular/router"; +import { FormBuilder, FormGroup, Validators } from "@angular/forms"; + +import { first } from "rxjs/operators"; + +import { AuthenticationService } from "../../services/authentication.service"; + +@Component({ + selector: "app-login-user", + templateUrl: "./login-user.component.html", + styleUrls: ["./login-user.component.css"] +}) +export class LoginUserComponent implements OnInit { + loginForm: FormGroup; + loading = false; + submitted = false; + returnUrl: string; + error = ""; + + constructor( + private formBuilder: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private authenticationService: AuthenticationService + ) { + // redirect to home if already logged in + if (this.authenticationService.currentUserValue) { + this.router.navigate(["/"]); + } + } + + ngOnInit() { + this.loginForm = this.formBuilder.group({ + username: ["", Validators.required], + password: ["", Validators.required] + }); + + // get return url from route parameters or default to '/' + this.returnUrl = this.route.snapshot.queryParams["returnUrl"] || "/"; + } + + get loginCtrls() { + return this.loginForm.controls; + } + + onLoginSubmit() { + this.submitted = true; + + // stop here if form is invalid + if (this.loginForm.invalid) { + return; + } + + this.loading = true; + this.authenticationService + .login(this.loginCtrls.username.value, this.loginCtrls.password.value) + .pipe(first()) + .subscribe( + data => { + this.router.navigate([this.returnUrl]); + }, + error => { + this.error = error; + this.loading = false; + } + ); + } +} diff --git a/Front/skydivelogs-app/src/app/login/login.component.html b/Front/skydivelogs-app/src/app/login/login.component.html index 6557907..77e4427 100644 --- a/Front/skydivelogs-app/src/app/login/login.component.html +++ b/Front/skydivelogs-app/src/app/login/login.component.html @@ -2,53 +2,16 @@

Login to the Skydive log

-
-
- - -
-
Username is required
-
-
-
- - -
-
Password is required
-
-
- -
{{error}}
-
-
-
- - -
-
Username is required
-
-
-
- - -
-
Password is required
-
-
- -
{{error}}
-
+ + + + + + + + +
diff --git a/Front/skydivelogs-app/src/app/login/login.component.ts b/Front/skydivelogs-app/src/app/login/login.component.ts index 81d9e8c..952a284 100644 --- a/Front/skydivelogs-app/src/app/login/login.component.ts +++ b/Front/skydivelogs-app/src/app/login/login.component.ts @@ -1,11 +1,4 @@ import { Component, OnInit } from "@angular/core"; -import { Router, ActivatedRoute } from "@angular/router"; -import { FormBuilder, FormGroup, Validators } from "@angular/forms"; - -import { first } from "rxjs/operators"; - -import { AuthenticationService } from "../../services/authentication.service"; -import { User } from "../../models/user"; @Component({ selector: "app-login", @@ -13,94 +6,7 @@ import { User } from "../../models/user"; styleUrls: ["./login.component.css"] }) export class LoginComponent implements OnInit { - loginForm: FormGroup; - createForm: FormGroup; - loading = false; - submitted = false; - returnUrl: string; - error = ""; + constructor() {} - constructor( - private formBuilder: FormBuilder, - private route: ActivatedRoute, - private router: Router, - private authenticationService: AuthenticationService - ) { - // redirect to home if already logged in - if (this.authenticationService.currentUserValue) { - this.router.navigate(["/"]); - } - } - - ngOnInit() { - this.loginForm = this.formBuilder.group({ - username: ["", Validators.required], - password: ["", Validators.required] - }); - this.createForm = this.formBuilder.group({ - username: ["", Validators.required], - password: ["", Validators.required] - }); - - // get return url from route parameters or default to '/' - this.returnUrl = this.route.snapshot.queryParams["returnUrl"] || "/"; - } - - get loginCtrls() { - return this.loginForm.controls; - } - - get createCtrls() { - return this.createForm.controls; - } - - onLoginSubmit() { - this.submitted = true; - - // stop here if form is invalid - if (this.loginForm.invalid) { - return; - } - - this.loading = true; - this.authenticationService - .login(this.loginCtrls.username.value, this.loginCtrls.password.value) - .pipe(first()) - .subscribe( - data => { - this.router.navigate([this.returnUrl]); - }, - error => { - this.error = error; - this.loading = false; - } - ); - } - - onCreateSubmit() { - this.submitted = true; - - // stop here if form is invalid - if (this.createForm.invalid) { - return; - } - - this.loading = true; - let createUser = new User(); - createUser.login = this.createCtrls.username.value; - createUser.password = this.createCtrls.password.value; - - this.authenticationService - .create(createUser) - .pipe(first()) - .subscribe( - data => { - this.router.navigate([this.returnUrl]); - }, - error => { - this.error = error; - this.loading = false; - } - ); - } + ngOnInit() {} } diff --git a/Front/skydivelogs-app/src/models/user.ts b/Front/skydivelogs-app/src/models/user.ts index 11fea34..4034f76 100644 --- a/Front/skydivelogs-app/src/models/user.ts +++ b/Front/skydivelogs-app/src/models/user.ts @@ -4,6 +4,7 @@ export class User { password: string; firstName: string; lastName: string; + email: string; authdata?: string; token?: string; }