Http -> HttpClient for army/admin/login (CC-63)

pull/46/head
HardiReady 2018-10-13 09:07:36 +02:00
parent e099ff572f
commit 2291ec20bf
5 changed files with 16 additions and 20 deletions

View File

@ -6,7 +6,6 @@ import {SquadService} from '../services/army-management/squad.service';
import {Fraction} from '../utils/fraction.enum';
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
@Component({
selector: 'admin-panel',
templateUrl: './admin.component.html',
@ -66,5 +65,4 @@ export class AdminComponent implements OnInit {
return o1._id === o2._id;
}
}
}

View File

@ -22,11 +22,9 @@ export class ArmyComponent implements OnInit {
}
ngOnInit() {
// init army data
this.armyService.getArmy()
.subscribe(army => {
this.army = army;
});
this.armyService.getArmies().subscribe(army => {
this.army = army;
});
};
select(memberId) {

View File

@ -7,6 +7,7 @@ export interface AppUser {
secret?: string;
activated: boolean;
permission: number;
token?: string;
}
export interface User {

View File

@ -1,15 +1,16 @@
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import 'rxjs/add/operator/map';
import {AppConfig} from '../../app.config';
import {AwardingService} from '../army-management/awarding.service';
import {PromotionService} from '../army-management/promotion.service';
import {CookieService} from 'ngx-cookie-service';
import {HttpClient} from '@angular/common/http';
import {AppUser} from '../../models/model-interfaces';
@Injectable()
export class LoginService {
constructor(private http: Http,
constructor(private http: HttpClient,
private config: AppConfig,
private cookieService: CookieService,
private awardingService: AwardingService,
@ -17,10 +18,10 @@ export class LoginService {
}
login(username: string, password: string) {
return this.http.post(this.config.apiAuthenticationPath, {username: username, password: password})
.map((response: Response) => {
return this.http.post<AppUser>(this.config.apiAuthenticationPath, {username: username, password: password})
.map((response) => {
// login successful if there's a jwt token in the response
const user = response.json();
const user = response;
if (user && user.token) {
// store user details and jwt token in cookie
this.cookieService.set('currentUser', JSON.stringify(user));
@ -34,9 +35,7 @@ export class LoginService {
}
signUp(username: string, password: string, secret: string) {
return this.http.post(this.config.apiSignupPath, {username: username, password: password, secret: secret})
.map((response: Response) => {
});
return this.http.post(this.config.apiSignupPath, {username: username, password: password, secret: secret});
}
logout() {

View File

@ -1,17 +1,17 @@
import {Injectable} from '@angular/core';
import {AppConfig} from '../../app.config';
import {Http} from '@angular/http';
import {HttpClient} from '@angular/common/http';
import {Army} from '../../models/model-interfaces';
@Injectable()
export class ArmyService {
constructor(private http: Http,
constructor(private http: HttpClient,
private config: AppConfig) {
}
getArmy() {
return this.http.get(this.config.apiOverviewPath)
.map(res => res.json());
getArmies() {
return this.http.get<Army[]>(this.config.apiOverviewPath);
}
}