working test for login
This commit is contained in:
19
interfaceServices/fake_loginInterface.php
Normal file
19
interfaceServices/fake_loginInterface.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,14 +1,28 @@
|
|||||||
import { Injectable } from '@angular/core';
|
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 { Observable } from 'rxjs/Observable';
|
||||||
import 'rxjs/add/operator/map'
|
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()
|
@Injectable()
|
||||||
export class AuthenticationService {
|
export class AuthenticationService {
|
||||||
|
|
||||||
|
loginUrl = "http://192.241.155.78/interfaceServices/fake_loginInterface.php";
|
||||||
|
params;
|
||||||
|
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
login(username: string, password: string) {
|
login( userData ) {
|
||||||
return this.http.post<any>('/api/authenticate', { username: username, password: password })
|
|
||||||
|
this.params = new HttpParams({
|
||||||
|
fromObject: userData
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.http.post<any>(this.loginUrl, this.params, httpOptions)
|
||||||
.map(user => {
|
.map(user => {
|
||||||
// login successful if there's a jwt token in the response
|
// login successful if there's a jwt token in the response
|
||||||
if (user && user.token) {
|
if (user && user.token) {
|
||||||
|
|||||||
@@ -76,15 +76,16 @@ export class LoginComponent implements OnInit {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login( form ) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.authenticationService.login(this.model.username, this.model.password)
|
this.authenticationService.login( form )
|
||||||
.subscribe(
|
.subscribe(
|
||||||
data => {
|
data => {
|
||||||
this.router.navigate([this.returnUrl]);
|
this.router.navigate(["game-grid"]);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
this.alertService.error(error);
|
//console.log(error)
|
||||||
|
this.alertService.error( "Bad username or password" );
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user