Adds adaptions to user user authentationc

parent 37bf3ffa
<div id="quizSummaryHeader" <div *ngIf="questionGroupItem"
id="quizSummaryHeader"
class="quizSummary mt-md-3 px-md-0"> class="quizSummary mt-md-3 px-md-0">
<div class="row no-gutters"> <div class="row no-gutters">
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
[class.error]="elem.selectable && !elem.isActive" [class.error]="elem.selectable && !elem.isActive"
[id]="elem.id" [id]="elem.id"
[routerLink]="getLinkTarget(elem)" [routerLink]="getLinkTarget(elem)"
[queryParams]="getQueryParams(elem)"
[title]="elem.textName | translate" [title]="elem.textName | translate"
[attr.data-intro]="elem.showIntro ? (('region.footer.footer_bar.description.' + elem.id) | translate) : null" [attr.data-intro]="elem.showIntro ? (('region.footer.footer_bar.description.' + elem.id) | translate) : null"
(click)="toggleSetting(elem)"> (click)="toggleSetting(elem)">
......
import { isPlatformBrowser, isPlatformServer } from '@angular/common'; import { isPlatformServer } from '@angular/common';
import { Component, Inject, Input, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core'; import { Component, EventEmitter, Inject, Input, PLATFORM_ID } from '@angular/core';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { IFooterBarElement } from '../../../lib/footerbar-element/interfaces'; import { IFooterBarElement } from '../../../lib/footerbar-element/interfaces';
import { CurrentQuizService } from '../../service/current-quiz/current-quiz.service'; import { CurrentQuizService } from '../../service/current-quiz/current-quiz.service';
import { FileUploadService } from '../../service/file-upload/file-upload.service'; import { FileUploadService } from '../../service/file-upload/file-upload.service';
...@@ -13,7 +11,7 @@ import { TrackingService } from '../../service/tracking/tracking.service'; ...@@ -13,7 +11,7 @@ import { TrackingService } from '../../service/tracking/tracking.service';
templateUrl: './footer-bar.component.html', templateUrl: './footer-bar.component.html',
styleUrls: ['./footer-bar.component.scss'], styleUrls: ['./footer-bar.component.scss'],
}) })
export class FooterBarComponent implements OnInit, OnDestroy { export class FooterBarComponent {
public static TYPE = 'FooterBarComponent'; public static TYPE = 'FooterBarComponent';
private _footerElements: Array<IFooterBarElement> = []; private _footerElements: Array<IFooterBarElement> = [];
...@@ -22,9 +20,8 @@ export class FooterBarComponent implements OnInit, OnDestroy { ...@@ -22,9 +20,8 @@ export class FooterBarComponent implements OnInit, OnDestroy {
return this._footerElements; return this._footerElements;
} }
@Input() set footerElements(value: Array<IFooterBarElement>) { @Input() set footerElementEmitter(value: EventEmitter<Array<IFooterBarElement>>) {
this.hasRightScrollElement = value.length > 1; value.subscribe(elements => this._footerElements = elements);
this._footerElements = value;
} }
private _footerElemIndex = 1; private _footerElemIndex = 1;
...@@ -47,11 +44,8 @@ export class FooterBarComponent implements OnInit, OnDestroy { ...@@ -47,11 +44,8 @@ export class FooterBarComponent implements OnInit, OnDestroy {
this._hasRightScrollElement = value; this._hasRightScrollElement = value;
} }
private _routerSubscription: Subscription;
constructor( constructor(
@Inject(PLATFORM_ID) private platformId: Object, @Inject(PLATFORM_ID) private platformId: Object,
private router: Router,
private footerBarService: FooterBarService, private footerBarService: FooterBarService,
private currentQuizService: CurrentQuizService, private currentQuizService: CurrentQuizService,
private trackingService: TrackingService, private trackingService: TrackingService,
...@@ -59,29 +53,14 @@ export class FooterBarComponent implements OnInit, OnDestroy { ...@@ -59,29 +53,14 @@ export class FooterBarComponent implements OnInit, OnDestroy {
) { ) {
} }
public ngOnInit(): void {
this._routerSubscription = this.router.events.subscribe((val) => {
if (isPlatformBrowser(this.platformId)) {
const navbarFooter = document.getElementById('navbar-footer-container');
if (navbarFooter) {
navbarFooter.scrollLeft = 0;
}
}
this.footerElemIndex = 1;
if (val.hasOwnProperty('url')) {
this.footerBarService.footerElemTheme.linkTarget = val['url'].indexOf('lobby') > -1 ? '/quiz/flow/theme' : '/themes';
}
});
}
public ngOnDestroy(): void {
this._routerSubscription.unsubscribe();
}
public getLinkTarget(elem: IFooterBarElement): Function | string { public getLinkTarget(elem: IFooterBarElement): Function | string {
return typeof elem.linkTarget === 'function' ? elem.linkTarget(elem) : elem.linkTarget; return typeof elem.linkTarget === 'function' ? elem.linkTarget(elem) : elem.linkTarget;
} }
public getQueryParams(elem: IFooterBarElement): object {
return elem.queryParams;
}
public toggleSetting(elem: IFooterBarElement): void { public toggleSetting(elem: IFooterBarElement): void {
this.currentQuizService.toggleSetting(elem); this.currentQuizService.toggleSetting(elem);
elem.onClickCallback(elem); elem.onClickCallback(elem);
......
<div class="row"> <div class="row">
<div class="text-light col-12"> <div class="text-light col-12">
<h4>Organize members in teams</h4> <h4>{{'component.membergroup-manager.title' | translate}}</h4>
<div class="row"> <div class="row">
<div class="col-12 col-sm-5"> <div class="col-12 col-sm-5">
<form> <form>
<div class="form-group"> <div class="form-group">
<label for="max-users-per-group">Max users per team</label> <label for="max-users-per-group">{{'component.membergroup-manager.max-users' | translate}}</label>
<input type="number" <input type="number"
class="form-control" class="form-control"
id="max-users-per-group" id="max-users-per-group"
placeholder="Max users per group" [placeholder]="'component.membergroup-manager.max-users' | translate"
[ngModelOptions]="{standalone: true}" [ngModelOptions]="{standalone: true}"
[(ngModel)]="maxMembersPerGroup"/> [(ngModel)]="maxMembersPerGroup"/>
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</div> </div>
<div class="col-12 col-sm-7 mb-2"> <div class="col-12 col-sm-7 mb-2">
<label class="d-block">Add users automatically to teams</label> <label class="d-block">{{'component.membergroup-manager.autojoin-to-team' | translate}}</label>
<label class="btn pointer mb-0" <label class="btn pointer mb-0"
[class.btn-success]="autoJoinToGroup" [class.btn-success]="autoJoinToGroup"
[class.btn-danger]="!autoJoinToGroup"> [class.btn-danger]="!autoJoinToGroup">
...@@ -40,10 +40,10 @@ ...@@ -40,10 +40,10 @@
<div class="input-group"> <div class="input-group">
<input type="text" <input type="text"
class="form-control" class="form-control"
placeholder="Add member group" [placeholder]="'component.membergroup-manager.create-team-placeholder' | translate"
(keyup.enter)="addMemberGroup()" (keyup.enter)="addMemberGroup()"
[(ngModel)]="memberGroupName" [(ngModel)]="memberGroupName"
aria-label="Add member group" [attr.aria-label]="'component.membergroup-manager.create-team-placeholder' | translate"
aria-describedby="add-member-group"> aria-describedby="add-member-group">
<div class="input-group-append"> <div class="input-group-append">
...@@ -52,16 +52,16 @@ ...@@ -52,16 +52,16 @@
(click)="addMemberGroup()" (click)="addMemberGroup()"
[class.disabled]="memberGroups.indexOf(memberGroupName) > -1 || !memberGroupName.length" [class.disabled]="memberGroups.indexOf(memberGroupName) > -1 || !memberGroupName.length"
[disabled]="memberGroups.indexOf(memberGroupName) > -1 || !memberGroupName.length"> [disabled]="memberGroups.indexOf(memberGroupName) > -1 || !memberGroupName.length">
<span>Add a new team</span> <span>{{'component.membergroup-manager.create-team' | translate}}</span>
</button> </button>
</div> </div>
</div> </div>
<h6 class="mt-4">Currently added teams:</h6> <h6 class="mt-4">{{'component.membergroup-manager.current-teams' | translate}}</h6>
<p *ngIf="!memberGroups.length">No teams added yet</p> <p *ngIf="!memberGroups.length">{{'component.membergroup-manager.no-current-teams' | translate}}</p>
<ul *ngFor="let group of memberGroups" <ul *ngFor="let group of memberGroups"
class="list-unstyled"> class="list-unstyled">
<li class="border-bottom p-2 mx-2"> <li class="border-bottom p-2">
<span>{{group}}</span> <span>{{group}}</span>
<span class="pointer float-right" <span class="pointer float-right"
(click)="removeMemberGroup(group)"><i class="fas fa-trash"></i></span> (click)="removeMemberGroup(group)"><i class="fas fa-trash"></i></span>
......
<h4 class="text-light text-center mb-5 mt-sm-5">Please enter your login credentials to proceed to the requested resource</h4> <ng-container *ngIf="!isLoading">
<h4 class="text-light text-center mb-5 mt-sm-5">Please enter your login credentials to proceed to the requested resource</h4>
<div class="input-group input-group-sm"> <div class="input-group input-group-sm">
<input type="text" <input type="text"
class="form-control" class="form-control"
name="username" name="username"
placeholder="Username" placeholder="Username"
(keypress)="trySubmit($event)" (keypress)="trySubmit($event)"
[(ngModel)]="username"/> [(ngModel)]="username"/>
<input type="password" <input type="password"
class="form-control my-2 my-sm-0" class="form-control my-2 my-sm-0"
name="password" name="password"
placeholder="Password" placeholder="Password"
(keypress)="trySubmit($event)" (keypress)="trySubmit($event)"
[(ngModel)]="password"/> [(ngModel)]="password"/>
<div class="input-group-append"> <div class="input-group-append">
<button class="btn btn-info" <button class="btn btn-info"
(click)="login()">Login (click)="login()">Login
</button> </button>
</div>
</div> </div>
</div>
<h4 *ngIf="authorizationFailed" <h4 *ngIf="authorizationFailed"
class="text-danger text-center mt-5">Authorization failed class="text-danger text-center mt-5">Authorization failed
</h4> </h4>
\ No newline at end of file </ng-container>
\ No newline at end of file
...@@ -20,6 +20,12 @@ export class LoginComponent implements OnInit { ...@@ -20,6 +20,12 @@ export class LoginComponent implements OnInit {
return this._authorizationFailed; return this._authorizationFailed;
} }
private _isLoading = true;
get isLoading(): boolean {
return this._isLoading;
}
private return = ''; private return = '';
constructor( constructor(
...@@ -29,13 +35,20 @@ export class LoginComponent implements OnInit { ...@@ -29,13 +35,20 @@ export class LoginComponent implements OnInit {
private headerLabelService: HeaderLabelService, private headerLabelService: HeaderLabelService,
private footerBarService: FooterBarService, private footerBarService: FooterBarService,
) { ) {
this.userService.isLoggedIn = false; this.userService.logout();
this.headerLabelService.headerLabel = 'Login'; this.headerLabelService.headerLabel = 'Login';
this.footerBarService.replaceFooterElements([]); this.footerBarService.replaceFooterElements([]);
} }
public ngOnInit(): void { public ngOnInit(): void {
this.route.queryParams.subscribe(params => this.return = params['return'] || '/'); this.route.queryParams.subscribe(params => {
if (params['logout']) {
this.router.navigate(['/']);
return;
}
this._isLoading = false;
this.return = params['return'] || '/';
});
} }
public async login(): Promise<void> { public async login(): Promise<void> {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<div class="container-fluid"> <div class="container-fluid">
<div class="row flex-sm-nowrap h-100"> <div class="row flex-sm-nowrap h-100">
<div class="footer-bar-wrapper flex-grow-0 flex-shrink-0 p-0 relative"> <div class="footer-bar-wrapper flex-grow-0 flex-shrink-0 p-0 relative">
<app-footer-bar [footerElements]="getFooterBarElements()"></app-footer-bar> <app-footer-bar [footerElementEmitter]="getFooterBarElements()"></app-footer-bar>
<div class="d-none d-md-block"> <div class="d-none d-md-block">
<router-outlet name="additionalData-md" <router-outlet name="additionalData-md"
class="d-none d-md-block"></router-outlet> class="d-none d-md-block"></router-outlet>
......
import { isPlatformServer } from '@angular/common'; import { isPlatformServer } from '@angular/common';
import { AfterViewInit, Component, Inject, OnInit, PLATFORM_ID } from '@angular/core'; import { AfterViewInit, Component, EventEmitter, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart, Router } from '@angular/router'; import { NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import * as introJs from 'intro.js'; import * as introJs from 'intro.js';
...@@ -11,6 +11,7 @@ import { I18nService } from '../../service/i18n/i18n.service'; ...@@ -11,6 +11,7 @@ import { I18nService } from '../../service/i18n/i18n.service';
import { StorageService } from '../../service/storage/storage.service'; import { StorageService } from '../../service/storage/storage.service';
import { ThemesService } from '../../service/themes/themes.service'; import { ThemesService } from '../../service/themes/themes.service';
import { TrackingService } from '../../service/tracking/tracking.service'; import { TrackingService } from '../../service/tracking/tracking.service';
import { UserService } from '../../service/user/user.service';
import { DB_TABLE, STORAGE_KEY } from '../../shared/enums'; import { DB_TABLE, STORAGE_KEY } from '../../shared/enums';
// Update global window.* object interface (https://stackoverflow.com/a/12709880/7992104) // Update global window.* object interface (https://stackoverflow.com/a/12709880/7992104)
...@@ -53,15 +54,17 @@ export class RootComponent implements OnInit, AfterViewInit { ...@@ -53,15 +54,17 @@ export class RootComponent implements OnInit, AfterViewInit {
private translateService: TranslateService, private translateService: TranslateService,
private router: Router, private router: Router,
private storageService: StorageService, private storageService: StorageService,
private userService: UserService,
) { ) {
this.themesService.updateCurrentlyUsedTheme(); this.themesService.updateCurrentlyUsedTheme();
} }
public getFooterBarElements(): Array<IFooterBarElement> { public getFooterBarElements(): EventEmitter<Array<IFooterBarElement>> {
return this.footerBarService.footerElements; return this.footerBarService.footerElements;
} }
public ngOnInit(): void { public ngOnInit(): void {
this.userService.loadConfig();
this.router.events.subscribe((event: any) => { this.router.events.subscribe((event: any) => {
if (event instanceof RouteConfigLoadStart) { if (event instanceof RouteConfigLoadStart) {
this._isLoading = true; this._isLoading = true;
......
...@@ -3,7 +3,7 @@ import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; ...@@ -3,7 +3,7 @@ import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { IQuestionGroup } from 'arsnova-click-v2-types/src/questions/interfaces'; import { IQuestionGroup } from 'arsnova-click-v2-types/src/questions/interfaces';
import { questionGroupReflection } from 'arsnova-click-v2-types/src/questions/questionGroup_reflection'; import { questionGroupReflection } from 'arsnova-click-v2-types/src/questions/questionGroup_reflection';
import { Subscription } from 'rxjs'; import { Observable, of } from 'rxjs';
import { DB_TABLE, STORAGE_KEY } from '../../shared/enums'; import { DB_TABLE, STORAGE_KEY } from '../../shared/enums';
import { FooterBarService } from '../footer-bar/footer-bar.service'; import { FooterBarService } from '../footer-bar/footer-bar.service';
import { StorageService } from '../storage/storage.service'; import { StorageService } from '../storage/storage.service';
...@@ -82,12 +82,18 @@ export class ActiveQuestionGroupService { ...@@ -82,12 +82,18 @@ export class ActiveQuestionGroupService {
} }
} }
public loadData(): Subscription { public loadData(): Observable<IQuestionGroup> {
return this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.ACTIVE_QUESTION_GROUP).subscribe(parsedObject => { if (this._activeQuestionGroup) {
return of(this._activeQuestionGroup);
}
const data = this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.ACTIVE_QUESTION_GROUP);
data.subscribe(parsedObject => {
if (parsedObject) { if (parsedObject) {
this._activeQuestionGroup = questionGroupReflection[parsedObject.TYPE](parsedObject); this._activeQuestionGroup = questionGroupReflection[parsedObject.TYPE](parsedObject);
} }
}); });
return data;
} }
private dec2hex(dec): string { private dec2hex(dec): string {
......
...@@ -10,9 +10,7 @@ import { DefaultSettings } from '../../../../lib/default.settings'; ...@@ -10,9 +10,7 @@ import { DefaultSettings } from '../../../../lib/default.settings';
}) })
export class QuizApiService { export class QuizApiService {
constructor( constructor(private http: HttpClient) { }
private http: HttpClient,
) { }
public QUIZ_STATUS_URL(quizName: string): string { public QUIZ_STATUS_URL(quizName: string): string {
return `${DefaultSettings.httpApiEndpoint}/quiz/status/${quizName}`; return `${DefaultSettings.httpApiEndpoint}/quiz/status/${quizName}`;
...@@ -82,6 +80,14 @@ export class QuizApiService { ...@@ -82,6 +80,14 @@ export class QuizApiService {
return `${DefaultSettings.httpApiEndpoint}/quiz/upload`; return `${DefaultSettings.httpApiEndpoint}/quiz/upload`;
} }
public QUIZ_EXPIRY_GET_URL(): string {
return `${DefaultSettings.httpApiEndpoint}/expiry-quiz/`;
}
public QUIZ_EXPIRY_POST_URL(): string {
return `${DefaultSettings.httpApiEndpoint}/expiry-quiz/quiz`;
}
public getQuizStatus(quizName): Observable<IMessage> { public getQuizStatus(quizName): Observable<IMessage> {
return this.http.get<IMessage>(this.QUIZ_STATUS_URL(quizName)); return this.http.get<IMessage>(this.QUIZ_STATUS_URL(quizName));
} }
...@@ -149,4 +155,20 @@ export class QuizApiService { ...@@ -149,4 +155,20 @@ export class QuizApiService {
public postQuizUpload(formData: FormData): Observable<IMessage> { public postQuizUpload(formData: FormData): Observable<IMessage> {
return this.http.post<IMessage>(this.QUIZ_UPLOAD_POST_URL(), formData); return this.http.post<IMessage>(this.QUIZ_UPLOAD_POST_URL(), formData);
} }
public getExpiryQuiz(): Observable<IMessage> {
return this.http.get<IMessage>(this.QUIZ_EXPIRY_GET_URL());
}
public postExpiryQuiz(data: object): Observable<IMessage> {
return this.http.post<IMessage>(this.QUIZ_EXPIRY_POST_URL(), data);
}
public postInitExpiryQuiz(data: object): Observable<IMessage> {
return this.http.post<IMessage>(this.QUIZ_EXPIRY_INIT_POST_URL(), data);
}
private QUIZ_EXPIRY_INIT_POST_URL(): string {
return `${DefaultSettings.httpApiEndpoint}/expiry-quiz/init`;
}
} }
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
import { USER_AUTHORIZATION } from '../../shared/enums';
import { UserService } from '../user/user.service'; import { UserService } from '../user/user.service';
@Injectable({ @Injectable({
...@@ -13,7 +14,7 @@ export class StaticLoginService implements CanActivate { ...@@ -13,7 +14,7 @@ export class StaticLoginService implements CanActivate {
await this.userService.loadConfig(); await this.userService.loadConfig();
if (this.userService.isLoggedIn) { if (this.isAllowedToProceed(route)) {
return true; return true;
} }
...@@ -24,4 +25,19 @@ export class StaticLoginService implements CanActivate { ...@@ -24,4 +25,19 @@ export class StaticLoginService implements CanActivate {
}); });
return false; return false;
} }
private isAllowedToProceed(route): boolean {
if (!this.userService.isLoggedIn) {
return false;
}
switch (route.routeConfig.path) {
case 'i18n-manager':
return this.userService.isAuthorizedFor(USER_AUTHORIZATION.EDIT_I18N);
case 'quiz-manager':
return this.userService.isAuthorizedFor(USER_AUTHORIZATION.CREATE_EXPIRED_QUIZ);
default:
return true;
}
}
} }
import { isPlatformServer } from '@angular/common'; import { isPlatformServer } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { AbstractQuestionGroup } from 'arsnova-click-v2-types/src/questions/questiongroup_abstract';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { DB_NAME, DB_TABLE, STORAGE_KEY } from '../../shared/enums'; import { DB_NAME, DB_TABLE, STORAGE_KEY } from '../../shared/enums';
import { IndexedDbService } from './indexed.db.service'; import { IndexedDbService } from './indexed.db.service';
...@@ -24,6 +25,10 @@ export class StorageService { ...@@ -24,6 +25,10 @@ export class StorageService {
} }
public create(table: DB_TABLE, key: string | STORAGE_KEY, value: any): Observable<any> { public create(table: DB_TABLE, key: string | STORAGE_KEY, value: any): Observable<any> {
if (value instanceof AbstractQuestionGroup) {
value = value.serialize();
}
return this.indexedDbService.put(table, { return this.indexedDbService.put(table, {
id: this.formatKey(key), id: this.formatKey(key),
value, value,
......
import { Injectable } from '@angular/core'; import { EventEmitter, Injectable } from '@angular/core';
import { DB_TABLE, STORAGE_KEY } from '../../shared/enums'; import { JwtHelperService } from '@auth0/angular-jwt';
import { ILoginSerialized } from 'arsnova-click-v2-types/src/common';
import { DB_TABLE, STORAGE_KEY, USER_AUTHORIZATION } from '../../shared/enums';
import { AuthorizeApiService } from '../api/authorize/authorize-api.service'; import { AuthorizeApiService } from '../api/authorize/authorize-api.service';
import { StorageService } from '../storage/storage.service'; import { StorageService } from '../storage/storage.service';
...@@ -12,11 +14,29 @@ export class UserService { ...@@ -12,11 +14,29 @@ export class UserService {
} }
set isLoggedIn(value: boolean) { set isLoggedIn(value: boolean) {
this._casTicket = null; if (!value) {
this._staticLoginToken = null; this._casTicket = null;
this._username = null; this._staticLoginToken = null;
this.persistTokens(); this._username = null;
this.deleteTokens();
} else {
this.persistTokens();
}
this._isLoggedIn = value; this._isLoggedIn = value;
this._staticLoginTokenContent = this.decodeToken();
this._loginNotifier.emit(value);
}
private _staticLoginTokenContent: ILoginSerialized;
get staticLoginTokenContent(): ILoginSerialized {
return this._staticLoginTokenContent;
}
private _loginNotifier = new EventEmitter<boolean>();
get loginNotifier(): EventEmitter<boolean> {
return this._loginNotifier;
} }
private _casTicket: string; private _casTicket: string;
...@@ -37,17 +57,18 @@ export class UserService { ...@@ -37,17 +57,18 @@ export class UserService {
return this._staticLoginToken; return this._staticLoginToken;
} }
constructor(private authorizeApiService: AuthorizeApiService, private storageService: StorageService) { constructor(private authorizeApiService: AuthorizeApiService, private storageService: StorageService, private jwtHelper: JwtHelperService) {
} }
public loadConfig(): Promise<boolean> { public loadConfig(): Promise<boolean> {
return new Promise<boolean>(async resolve => { return new Promise<boolean>(async resolve => {
if (!await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.TOKEN).toPromise()) { const tokens = await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.TOKEN).toPromise();
if (!tokens) {
resolve(true); resolve(true);
return; return;
} }
const tokens = await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.TOKEN).toPromise();
this._casTicket = tokens.casTicket; this._casTicket = tokens.casTicket;
this._staticLoginToken = tokens.staticLoginToken; this._staticLoginToken = tokens.staticLoginToken;
this._username = tokens.username; this._username = tokens.username;
...@@ -58,23 +79,34 @@ export class UserService { ...@@ -58,23 +79,34 @@ export class UserService {
} }
this.authorizeApiService.getValidateStaticLoginToken(this._username, this._staticLoginToken).subscribe(response => { this.authorizeApiService.getValidateStaticLoginToken(this._username, this._staticLoginToken).subscribe(response => {
this._isLoggedIn = response.status === 'STATUS:SUCCESSFUL' && response.step === 'AUTHENTICATE_STATIC'; this.isLoggedIn = response.status === 'STATUS:SUCCESSFUL' && response.step === 'AUTHENTICATE_STATIC';
resolve(true); resolve(this.isLoggedIn);
}); });
}); });
} }
public logout(): void {
this.isLoggedIn = false;
}
public decodeToken(): ILoginSerialized {
if (!this.staticLoginToken) {
return null;
}
return this.jwtHelper.decodeToken(this.staticLoginToken);
}
public authenticateThroughCas(token: string): Promise<boolean> { public authenticateThroughCas(token: string): Promise<boolean> {
return new Promise(async resolve => { return new Promise(async resolve => {
const data = await this.authorizeApiService.getAuthorizationForToken(token).toPromise(); co