From 59d8cfe0204d5566122ba5989eee2b561c7fe5bd Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Sat, 5 May 2018 15:33:13 -0400 Subject: [PATCH] working test for login --- interfaceServices/fake_loginInterface.php | 19 +++++++++++++++++++ src/app/_services/authentication.service.ts | 20 +++++++++++++++++--- src/app/login/login.component.ts | 9 +++++---- 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 interfaceServices/fake_loginInterface.php diff --git a/interfaceServices/fake_loginInterface.php b/interfaceServices/fake_loginInterface.php new file mode 100644 index 0000000..8e451a9 --- /dev/null +++ b/interfaceServices/fake_loginInterface.php @@ -0,0 +1,19 @@ + diff --git a/src/app/_services/authentication.service.ts b/src/app/_services/authentication.service.ts index eeb9816..0638b81 100644 --- a/src/app/_services/authentication.service.ts +++ b/src/app/_services/authentication.service.ts @@ -1,14 +1,28 @@ import { Injectable } from '@angular/core'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map' +const httpOptions = { + headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) + //headers: new HttpHeaders({ 'Content-Type': 'application/json' }) +} + @Injectable() export class AuthenticationService { + + loginUrl = "http://192.241.155.78/interfaceServices/fake_loginInterface.php"; + params; + constructor(private http: HttpClient) { } - login(username: string, password: string) { - return this.http.post('/api/authenticate', { username: username, password: password }) + login( userData ) { + + this.params = new HttpParams({ + fromObject: userData + }); + + return this.http.post(this.loginUrl, this.params, httpOptions) .map(user => { // login successful if there's a jwt token in the response if (user && user.token) { diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 9c15832..e4cf593 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -76,15 +76,16 @@ export class LoginComponent implements OnInit { } - login() { + login( form ) { this.loading = true; - this.authenticationService.login(this.model.username, this.model.password) + this.authenticationService.login( form ) .subscribe( data => { - this.router.navigate([this.returnUrl]); + this.router.navigate(["game-grid"]); }, error => { - this.alertService.error(error); + //console.log(error) + this.alertService.error( "Bad username or password" ); this.loading = false; }); }