From 61ccd6eeb930c8ca9f795861e245ad5413293945 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Thu, 27 Jul 2017 16:38:35 +0200 Subject: [PATCH] Add request check to login process --- api/cron-job/cron.js | 4 ++-- static/src/app/app.component.ts | 12 ++---------- static/src/app/login/login.component.ts | 6 ++---- .../services/awarding-service/awarding.service.ts | 8 ++++++++ static/src/app/services/http-client.ts | 4 ++-- .../src/app/services/login-service/login-service.ts | 11 ++++++++++- .../services/promotion-service/promotion.service.ts | 8 ++++++++ 7 files changed, 34 insertions(+), 19 deletions(-) diff --git a/api/cron-job/cron.js b/api/cron-job/cron.js index d4be4aa..15acbfe 100644 --- a/api/cron-job/cron.js +++ b/api/cron-job/cron.js @@ -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, diff --git a/static/src/app/app.component.ts b/static/src/app/app.component.ts index 2712b94..648d830 100644 --- a/static/src/app/app.component.ts +++ b/static/src/app/app.component.ts @@ -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); } } diff --git a/static/src/app/login/login.component.ts b/static/src/app/login/login.component.ts index 9611de0..17e11c2 100644 --- a/static/src/app/login/login.component.ts +++ b/static/src/app/login/login.component.ts @@ -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(() => { diff --git a/static/src/app/services/awarding-service/awarding.service.ts b/static/src/app/services/awarding-service/awarding.service.ts index 0b7d953..0c81b4e 100644 --- a/static/src/app/services/awarding-service/awarding.service.ts +++ b/static/src/app/services/awarding-service/awarding.service.ts @@ -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 */ diff --git a/static/src/app/services/http-client.ts b/static/src/app/services/http-client.ts index 1a735b8..309c40b 100644 --- a/static/src/app/services/http-client.ts +++ b/static/src/app/services/http-client.ts @@ -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']) } } diff --git a/static/src/app/services/login-service/login-service.ts b/static/src/app/services/login-service/login-service.ts index f7a4e7a..3b0aaa7 100644 --- a/static/src/app/services/login-service/login-service.ts +++ b/static/src/app/services/login-service/login-service.ts @@ -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); + } } }); } diff --git a/static/src/app/services/promotion-service/promotion.service.ts b/static/src/app/services/promotion-service/promotion.service.ts index 3580e0a..8433728 100644 --- a/static/src/app/services/promotion-service/promotion.service.ts +++ b/static/src/app/services/promotion-service/promotion.service.ts @@ -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())