Http -> HttpClient for army/admin/login (CC-63)
parent
e099ff572f
commit
2291ec20bf
|
@ -6,7 +6,6 @@ import {SquadService} from '../services/army-management/squad.service';
|
||||||
import {Fraction} from '../utils/fraction.enum';
|
import {Fraction} from '../utils/fraction.enum';
|
||||||
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
|
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'admin-panel',
|
selector: 'admin-panel',
|
||||||
templateUrl: './admin.component.html',
|
templateUrl: './admin.component.html',
|
||||||
|
@ -66,5 +65,4 @@ export class AdminComponent implements OnInit {
|
||||||
return o1._id === o2._id;
|
return o1._id === o2._id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,7 @@ export class ArmyComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// init army data
|
this.armyService.getArmies().subscribe(army => {
|
||||||
this.armyService.getArmy()
|
|
||||||
.subscribe(army => {
|
|
||||||
this.army = army;
|
this.army = army;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@ export interface AppUser {
|
||||||
secret?: string;
|
secret?: string;
|
||||||
activated: boolean;
|
activated: boolean;
|
||||||
permission: number;
|
permission: number;
|
||||||
|
token?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {Http, Response} from '@angular/http';
|
|
||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
import {AppConfig} from '../../app.config';
|
import {AppConfig} from '../../app.config';
|
||||||
import {AwardingService} from '../army-management/awarding.service';
|
import {AwardingService} from '../army-management/awarding.service';
|
||||||
import {PromotionService} from '../army-management/promotion.service';
|
import {PromotionService} from '../army-management/promotion.service';
|
||||||
import {CookieService} from 'ngx-cookie-service';
|
import {CookieService} from 'ngx-cookie-service';
|
||||||
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
import {AppUser} from '../../models/model-interfaces';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LoginService {
|
export class LoginService {
|
||||||
constructor(private http: Http,
|
constructor(private http: HttpClient,
|
||||||
private config: AppConfig,
|
private config: AppConfig,
|
||||||
private cookieService: CookieService,
|
private cookieService: CookieService,
|
||||||
private awardingService: AwardingService,
|
private awardingService: AwardingService,
|
||||||
|
@ -17,10 +18,10 @@ export class LoginService {
|
||||||
}
|
}
|
||||||
|
|
||||||
login(username: string, password: string) {
|
login(username: string, password: string) {
|
||||||
return this.http.post(this.config.apiAuthenticationPath, {username: username, password: password})
|
return this.http.post<AppUser>(this.config.apiAuthenticationPath, {username: username, password: password})
|
||||||
.map((response: Response) => {
|
.map((response) => {
|
||||||
// login successful if there's a jwt token in the response
|
// login successful if there's a jwt token in the response
|
||||||
const user = response.json();
|
const user = response;
|
||||||
if (user && user.token) {
|
if (user && user.token) {
|
||||||
// store user details and jwt token in cookie
|
// store user details and jwt token in cookie
|
||||||
this.cookieService.set('currentUser', JSON.stringify(user));
|
this.cookieService.set('currentUser', JSON.stringify(user));
|
||||||
|
@ -34,9 +35,7 @@ export class LoginService {
|
||||||
}
|
}
|
||||||
|
|
||||||
signUp(username: string, password: string, secret: string) {
|
signUp(username: string, password: string, secret: string) {
|
||||||
return this.http.post(this.config.apiSignupPath, {username: username, password: password, secret: secret})
|
return this.http.post(this.config.apiSignupPath, {username: username, password: password, secret: secret});
|
||||||
.map((response: Response) => {
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logout() {
|
logout() {
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {AppConfig} from '../../app.config';
|
import {AppConfig} from '../../app.config';
|
||||||
import {Http} from '@angular/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
import {Army} from '../../models/model-interfaces';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ArmyService {
|
export class ArmyService {
|
||||||
|
|
||||||
constructor(private http: Http,
|
constructor(private http: HttpClient,
|
||||||
private config: AppConfig) {
|
private config: AppConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
getArmy() {
|
getArmies() {
|
||||||
return this.http.get(this.config.apiOverviewPath)
|
return this.http.get<Army[]>(this.config.apiOverviewPath);
|
||||||
.map(res => res.json());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue