diff --git a/api.php b/phpComponets/api.php similarity index 100% rename from api.php rename to phpComponets/api.php diff --git a/phpComponets/login.php b/phpComponets/login.php new file mode 100644 index 0000000..dc10d56 --- /dev/null +++ b/phpComponets/login.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/phpComponets/register.php b/phpComponets/register.php new file mode 100644 index 0000000..dc10d56 --- /dev/null +++ b/phpComponets/register.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..267d144 --- /dev/null +++ b/registration.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 80b80d0..55e21c8 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -4,13 +4,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' +import { RegisterComponent } from './register/register.component' const routes: Routes = [ { path: '', redirectTo: '/login', pathMatch: 'full' }, { path: 'game-grid', component: GameGridComponent }, { path: 'view-card', component: ViewCardComponent }, { path: 'view-card/:gid', component: ViewCardComponent }, - { path: 'login', component: LoginComponent } + { path: 'login', component: LoginComponent }, + { path: 'register', component: RegisterComponent } ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 051be75..2326761 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -3,14 +3,16 @@ import { NgModule } from '@angular/core'; import {HttpClientModule} from '@angular/common/http'; import { ReactiveFormsModule } from '@angular/forms'; -import { AppComponent } from './app.component'; import { GamesService } from './games.service'; +import { AbstractControl } from '@angular/forms'; + +import { AppComponent } from './app.component'; import { GameGridComponent } from './game-grid/game-grid.component'; import { AppRoutingModule } from './/app-routing.module'; import { ViewCardComponent } from './view-card/view-card.component'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; -import { MatCardModule } from '@angular/material'; +import {MatCardModule} from '@angular/material'; import {MatToolbarModule} from '@angular/material/toolbar'; import {MatMenuModule} from '@angular/material/menu'; import {MatIconModule} from '@angular/material/icon'; @@ -22,6 +24,8 @@ import {MatFormFieldModule} from '@angular/material/form-field'; import { LoginComponent } from './login/login.component'; import { RegisterComponent } from './register/register.component'; +import { RegistrationService } from './registration.service'; + @NgModule({ @@ -47,7 +51,7 @@ import { RegisterComponent } from './register/register.component'; MatPaginatorModule, MatFormFieldModule ], - providers: [GamesService], + providers: [GamesService, RegistrationService], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/src/app/login/login.component.css b/src/app/login/login.component.css index e72457a..e69de29 100644 --- a/src/app/login/login.component.css +++ b/src/app/login/login.component.css @@ -1,16 +0,0 @@ -.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 65e3899..48a0cfb 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -1,8 +1,8 @@
-
- +
+

Login

@@ -16,9 +16,6 @@ [type]="'text'" [name]="'userName'"> -
- This field is required -
-
- This field is required -
- +
diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index cffc864..6de9e8a 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -33,6 +33,7 @@ export class LoginComponent implements OnInit { const formGroup = {}; formGroup["userName"] = new FormControl( "", this.mapValidators({ required: true }) ); + formGroup["password"] = new FormControl( "", this.mapValidators({ required: true }) ); this.form = new FormGroup(formGroup); } diff --git a/src/app/register/register.component.html b/src/app/register/register.component.html index 665902b..24345a3 100644 --- a/src/app/register/register.component.html +++ b/src/app/register/register.component.html @@ -1,3 +1,57 @@ -

- register works! -

+ +
+ + + +

Register

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + \ No newline at end of file diff --git a/src/app/register/register.component.ts b/src/app/register/register.component.ts index b7db7f8..982afb7 100644 --- a/src/app/register/register.component.ts +++ b/src/app/register/register.component.ts @@ -1,4 +1,10 @@ import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { FormBuilder, FormGroup, FormControl, Validators, AbstractControl } from '@angular/forms'; + +import { RegistrationService } from '../registration.service'; + +//import { ValidateUserName } from '../validators/username.validator'; @Component({ selector: 'app-register', @@ -7,9 +13,91 @@ import { Component, OnInit } from '@angular/core'; }) export class RegisterComponent implements OnInit { - constructor() { } + form: any; + loading = false; + //userNameValidator = new UserNameValidator(null); + + constructor( + private registrationService: RegistrationService + ){ } + + ngOnInit() { + + this.buildForm(); + } + + buildForm(){ + const formGroup = {}; + + formGroup["firstName"] = new FormControl( "", this.mapValidators({ + required: true, + min: "3", + max: "50" + }) ); + formGroup["lastName"] = new FormControl( "", this.mapValidators({ + required: true, + min: "3", + max: "50" + }) ); + formGroup["email"] = new FormControl( "", this.mapValidators({ + required: true, + email: true, + max: "100" + }) ); + formGroup["userName"] = new FormControl( "", this.mapValidators({ + ValidateUserName: true, + required: true, + min: "5", + max: "25" + }) ); + formGroup["password"] = new FormControl( "", this.mapValidators({ + required: true, + min: "7", + max: "25" + }) ); + + 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 ); + } + }else if( key == "email" ) { + if( validators.email ){ + formValidators.push( Validators.email ); + } + }else if( key == "min" ) { + formValidators.push(Validators.min(validators[key])); + }else if( key == "max" ) { + formValidators.push(Validators.max(validators[key])); + }else if( key == "ValidateUserName" ){ + formValidators.push( this.validateUserName ); + } + } + return formValidators; + } + + validateUserName( control: AbstractControl ){ + + this.registrationService.validateUserName( control.value ).subscribe( data => { + console.log( data ); + if( control.value != data.username ){ + return{ + validUserName: true + }; + } + return null; + + }); + + } + + - ngOnInit() { - } } diff --git a/src/app/registration.service.spec.ts b/src/app/registration.service.spec.ts new file mode 100644 index 0000000..ec88bc1 --- /dev/null +++ b/src/app/registration.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { RegistrationService } from './registration.service'; + +describe('RegistrationService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [RegistrationService] + }); + }); + + it('should be created', inject([RegistrationService], (service: RegistrationService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/registration.service.ts b/src/app/registration.service.ts new file mode 100644 index 0000000..e2a4fa1 --- /dev/null +++ b/src/app/registration.service.ts @@ -0,0 +1,36 @@ +import { Injectable } from '@angular/core'; + +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/map'; + +@Injectable() +export class RegistrationService { + + APIURL = "http://192.241.155.78/ludosdata/api.php"; + + constructor( + private http: HttpClient + ){ } + + /* + validateUserName( userName ): Observable { + return this.http.get( "http://www.pugludos.com/registration.php?key=validation&type=username&value=" + userName ) + .map(res => { + return( + res + ); + }); + } + */ + + validateUserName( userName ): Observable { + return this.http.get( this.APIURL + "/users?filter=email,cs," + userName + "&transform=1" ) + .map(res => { + return( + res + ); + }); + } + +} diff --git a/src/app/validators/username.validator.ts b/src/app/validators/username.validator.ts new file mode 100644 index 0000000..4cfb897 --- /dev/null +++ b/src/app/validators/username.validator.ts @@ -0,0 +1,31 @@ + +import { AbstractControl } from '@angular/forms'; +import { RegistrationService } from '../registration.service'; + + +export class ValidateUserName{ + +constructor( + private RS: RegistrationService + ){ } + + validateUserName( control: AbstractControl ){ + //var RS = new RegistrationService(null); + /* + this.registrationService2.validateUserName( control.value ).subscribe( data => { + console.log( data ); + if( control.value != data.username ){ + return{ + validUserName: true + }; + } + return null; + + }); + */ + } + + +} + + diff --git a/src/styles.css b/src/styles.css index 550b41f..1102ac8 100644 --- a/src/styles.css +++ b/src/styles.css @@ -1,2 +1,18 @@ /* You can add global styles to this file, and also import other style files */ -@import "~@angular/material/prebuilt-themes/indigo-pink.css"; \ No newline at end of file +@import "~@angular/material/prebuilt-themes/indigo-pink.css"; + +.lrCard{ + min-width: 300px; + width:20%; + margin:0 auto; +} + +.fullWidth{ + width:100%; +} + +.lrContainer{ + margin-top: 10%; + justify-content: center; + align-items: center; +} \ No newline at end of file