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 {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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,9 +22,7 @@ export class ArmyComponent implements OnInit {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
// init army data
|
||||
this.armyService.getArmy()
|
||||
.subscribe(army => {
|
||||
this.armyService.getArmies().subscribe(army => {
|
||||
this.army = army;
|
||||
});
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@ export interface AppUser {
|
|||
secret?: string;
|
||||
activated: boolean;
|
||||
permission: number;
|
||||
token?: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue