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 {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;
} }
} }
} }

View File

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

View File

@ -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 {

View File

@ -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() {

View File

@ -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());
} }
} }