From 3d263a956d1e12ac17a75ed9548fbbe185564317 Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Sat, 21 Apr 2018 20:55:21 -0400 Subject: [PATCH] loginv1 --- src/app/app-routing.module.ts | 7 ++- src/app/app.module.ts | 6 ++- src/app/login/login.component.css | 16 +++++++ src/app/login/login.component.html | 69 ++++++++++++++++++++++++++++-- src/app/login/login.component.ts | 59 +++++++++++++++++++++++-- 5 files changed, 148 insertions(+), 9 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 982d29e..80b80d0 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -3,12 +3,15 @@ import { RouterModule, Routes } from '@angular/router'; import { GameGridComponent } from './game-grid/game-grid.component' import { ViewCardComponent } from './view-card/view-card.component' +import { LoginComponent } from './login/login.component' const routes: Routes = [ - { path: '', redirectTo: '/game-grid', pathMatch: 'full' }, + { path: '', redirectTo: '/login', pathMatch: 'full' }, { path: 'game-grid', component: GameGridComponent }, { path: 'view-card', component: ViewCardComponent }, - { path: 'view-card/:gid', component: ViewCardComponent } + { path: 'view-card/:gid', component: ViewCardComponent }, + { path: 'login', component: LoginComponent } + ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 7277150..051be75 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -17,6 +17,9 @@ import {MatIconModule} from '@angular/material/icon'; import {MatButtonModule} from '@angular/material/button'; import {MatInputModule} from '@angular/material/input'; import {MatPaginatorModule} from '@angular/material/paginator'; +import {MatFormFieldModule} from '@angular/material/form-field'; + + import { LoginComponent } from './login/login.component'; import { RegisterComponent } from './register/register.component'; @@ -41,7 +44,8 @@ import { RegisterComponent } from './register/register.component'; MatIconModule, MatButtonModule, MatInputModule, - MatPaginatorModule + MatPaginatorModule, + MatFormFieldModule ], providers: [GamesService], bootstrap: [AppComponent] diff --git a/src/app/login/login.component.css b/src/app/login/login.component.css index e69de29..e72457a 100644 --- a/src/app/login/login.component.css +++ b/src/app/login/login.component.css @@ -0,0 +1,16 @@ +.loginCard{ + min-width: 300px; + width:20%; + margin:0 auto; +} + +.fullWidth{ + width:100%; +} + +.loginContainer{ + display: flex; + height: 400px; + justify-content: center; + align-items: center; +} \ No newline at end of file diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index cbdfa13..65e3899 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -1,3 +1,66 @@ -

- login works! -

+ + +
+
+ + + +

Login

+
+
+ + + + +
+ This field is required +
+ + + + +
+ This field is required +
+ + + + +
+ +
+ +
+ + + + \ No newline at end of file diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 5701fa2..cffc864 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -1,4 +1,7 @@ import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms'; + @Component({ selector: 'app-login', @@ -7,9 +10,59 @@ import { Component, OnInit } from '@angular/core'; }) export class LoginComponent implements OnInit { - constructor() { } + form: any; + loading = false; - ngOnInit() { - } + + constructor( + private route: ActivatedRoute, + private router: Router +) { } + + ngOnInit() { + // reset login status + //this.authenticationService.logout(); + + // get return url from route parameters or default to '/' + //this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/'; + + this.buildForm(); + } + + buildForm(){ + const formGroup = {}; + + formGroup["userName"] = new FormControl( "", this.mapValidators({ required: true }) ); + + this.form = new FormGroup(formGroup); + } + + private mapValidators(validators) { + const formValidators = []; + + for( var key in validators ){ + if( key == "required" ) { + if( validators.required ){ + formValidators.push( Validators.required ); + } + } + } + return formValidators; + } + + login() { + /* + this.loading = true; + this.authenticationService.login(this.model.username, this.model.password) + .subscribe( + data => { + this.router.navigate([this.returnUrl]); + }, + error => { + this.alertService.error(error); + this.loading = false; + }); + */ + } }