Add request check to login process

pull/1/head
Florian Hartwich 2017-07-27 16:38:35 +02:00
parent 120f413476
commit 61ccd6eeb9
7 changed files with 34 additions and 19 deletions

View File

@ -59,8 +59,8 @@ const createBackup = () => {
// Execute daily @ 02:30 AM
const cronJobSignature = cron.job('00 30 02 * * *', createAllSignatures);
// Execute daily @ 04:00 AM, on Mon, Thu and Sat
const cronJobBackup = cron.job('00 00 04 * * *', createBackup);
// Execute every on Mon, Thu and Sat @ 04:00 AM
const cronJobBackup = cron.job('00 00 04 * * mon,thu,sat', createBackup);
module.exports = {
cronJobSignature: cronJobSignature,

View File

@ -31,16 +31,8 @@ export class AppComponent {
});
if (this.loginService.hasPermission(2)) {
const fraction = this.loginService.getCurrentUser().squad.fraction;
this.promotionService.getUnconfirmedPromotions(fraction).subscribe((items) => {
if (items.length > 0) {
this.promotionService.hasUnprocessedPromotion = true;
}
});
this.awardingService.getUnconfirmedAwards(fraction).subscribe((items) => {
if (items.length > 0) {
this.awardingService.hasUnprocessedAwards = true;
}
})
this.promotionService.checkUnconfirmedPromotions(fraction);
this.awardingService.checkUnprocessedAwards(fraction);
}
}

View File

@ -1,5 +1,5 @@
import {Component, OnInit} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {Router} from "@angular/router";
import {LoginService} from "../services/login-service/login-service";
@ -19,8 +19,7 @@ export class LoginComponent implements OnInit {
returnUrl: string;
constructor(private route: ActivatedRoute,
private router: Router,
constructor(private router: Router,
private loginService: LoginService) {
}
@ -40,7 +39,6 @@ export class LoginComponent implements OnInit {
this.router.navigate([this.returnUrl]);
},
error => {
console.log(error)
this.error = error._body;
this.showErrorLabel = true;
setTimeout(() => {

View File

@ -17,6 +17,14 @@ export class AwardingService {
.map(res => res.json())
}
checkUnprocessedAwards(fraction?: string) {
this.getUnconfirmedAwards(fraction).subscribe((items) => {
if (items.length > 0) {
this.hasUnprocessedAwards = true
}
})
}
/**
* get awards array with populated decorations
*/

View File

@ -7,7 +7,6 @@ import {LoginService} from "./login-service/login-service";
export class HttpClient {
constructor(private router: Router,
private loginService: LoginService,
private http: Http) {
}
@ -19,7 +18,8 @@ export class HttpClient {
headers.append('x-access-token', currentUser.token);
return headers;
} else {
this.loginService.logout();
//logout
localStorage.removeItem('currentUser');
this.router.navigate(['/login'])
}
}

View File

@ -5,12 +5,16 @@ import "rxjs/add/operator/map";
import {AppConfig} from "../../app.config";
import {AUTH_ENABLED} from "../../app.tokens";
import {AppUser} from "../../models/model-interfaces";
import {AwardingService} from "../awarding-service/awarding.service";
import {PromotionService} from "../promotion-service/promotion.service";
@Injectable()
export class LoginService {
constructor(@Optional() @Inject(AUTH_ENABLED) public authEnabled = false,
private http: Http,
private config: AppConfig) {
private config: AppConfig,
private awardingService: AwardingService,
private promotionService: PromotionService) {
}
login(username: string, password: string) {
@ -21,6 +25,11 @@ export class LoginService {
if (user && user.token) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(user));
if (user.permission >= 3) {
const fraction = user.squad.fraction;
this.awardingService.checkUnprocessedAwards(fraction);
this.promotionService.checkUnconfirmedPromotions(fraction);
}
}
});
}

View File

@ -17,6 +17,14 @@ export class PromotionService {
.map(res => res.json())
}
checkUnconfirmedPromotions(fraction?: string) {
this.getUnconfirmedPromotions(fraction).subscribe((items) => {
if (items.length > 0) {
this.hasUnprocessedPromotion = true
}
})
}
getSquadPromotions(squadId: string) {
return this.http.get(this.config.apiUrl + this.config.apiPromotionPath + '?squadId=' + squadId)
.map(res => res.json())