working test for login

This commit is contained in:
2018-05-05 15:33:13 -04:00
parent cd10c7aaad
commit 59d8cfe020
3 changed files with 41 additions and 7 deletions

View File

@@ -0,0 +1,19 @@
<?php
$username = $_POST["userName"];
$password = $_POST["password"];
if( $username == "admin" && $password == "admin" ){
$userData = array();
$userDatap["id"] = "12345";
$userDatap["username"] = "admin";
$userDatap["firstName"] = "TestFirst";
$userDatap["lastName"] = "TestLast";
$userDatap["token"] = "fake-jwt-token";
echo( json_encode( $userDatap ) );
}else{
http_response_code(400);
}
?>

View File

@@ -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<any>('/api/authenticate', { username: username, password: password })
login( userData ) {
this.params = new HttpParams({
fromObject: userData
});
return this.http.post<any>(this.loginUrl, this.params, httpOptions)
.map(user => {
// login successful if there's a jwt token in the response
if (user && user.token) {

View File

@@ -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;
});
}