working test for login
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user