Check is LoggedIn from Session

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57064 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-09-13 08:26:09 +00:00
parent 69c86456b8
commit 95ee0d8984
5 changed files with 688 additions and 808 deletions

View File

@ -1,11 +1,10 @@
import {Component, Input} from '@angular/core'; import {Component, Input} from '@angular/core';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {ContextsService} from './service/contexts.service'; import {ContextsService} from './service/contexts.service';
import {ClaimEntity} from './claimHelper.class'; import {ClaimContext, ClaimEntity} from './claimHelper.class';
import {Session} from '../../login/utils/helper.class'; import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {EnvProperties} from '../../utils/properties/env-properties'; import {EnvProperties} from '../../utils/properties/env-properties';
import {UserManagementService} from "../../services/user-management.service";
declare var UIkit: any; declare var UIkit: any;
@ -45,9 +44,7 @@ export class ClaimContextSearchFormComponent {
this.getCommunities(); this.getCommunities();
} }
constructor(private _contextService: ContextsService, constructor(private _contextService: ContextsService, private router: Router) {
private router: Router,
private userManagementService: UserManagementService) {
} }
@ -112,8 +109,7 @@ export class ClaimContextSearchFormComponent {
} }
getCommunities() { getCommunities() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if (!Session.isLoggedIn()) {
if (!isLoggedIn) {
this.saveStateAndRedirectLogin(); this.saveStateAndRedirectLogin();
} else { } else {
@ -149,17 +145,16 @@ export class ClaimContextSearchFormComponent {
} }
); );
} }
});
} }
getCategories() { getCategories() {
this.loading = true; this.loading = true;
// this.categories=[]; // this.categories=[];
if (this.selectedCommunityId != '0') { if (this.selectedCommunityId != '0') {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if (!Session.isLoggedIn()) {
if (!isLoggedIn) {
this.saveStateAndRedirectLogin(); this.saveStateAndRedirectLogin();
} else { } else {
if (this.categories[this.selectedCommunityId]) { if (this.categories[this.selectedCommunityId]) {
this.loading = false; this.loading = false;
@ -183,10 +178,8 @@ export class ClaimContextSearchFormComponent {
} }
); );
} }
});
} }
} }
/* /*
getConcepts() { getConcepts() {
this.loading = true; this.loading = true;
@ -225,7 +218,6 @@ export class ClaimContextSearchFormComponent {
this.loading = false; this.loading = false;
} }
}*/ }*/
/* /*
getSubConcepts(conceptId) { getSubConcepts(conceptId) {
this.loading = true; this.loading = true;
@ -269,10 +261,8 @@ export class ClaimContextSearchFormComponent {
} }
browseConcepts(categoryId) { browseConcepts(categoryId) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if (!Session.isLoggedIn()) {
if (!isLoggedIn) {
this.saveStateAndRedirectLogin(); this.saveStateAndRedirectLogin();
} else { } else {
if (this.conceptsClass[categoryId] != null) { if (this.conceptsClass[categoryId] != null) {
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId]; this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId];
@ -302,7 +292,7 @@ export class ClaimContextSearchFormComponent {
} }
); );
} }
});
} }
browseSubConcepts(categoryId, conceptId) { browseSubConcepts(categoryId, conceptId) {

View File

@ -1,14 +1,17 @@
import {Component, QueryList, ViewChild, ViewChildren, ViewEncapsulation} from '@angular/core'; import {Component, ViewChild, ViewChildren, QueryList, Input, ViewEncapsulation} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router'; import {Location} from '@angular/common';
import {Meta, Title} from '@angular/platform-browser'; import {ActivatedRoute, Params, Router} from '@angular/router';
import {Title, Meta} from '@angular/platform-browser';
import {DataTableDirective} from 'angular-datatables'; import {DataTableDirective} from 'angular-datatables';
import {Subject} from 'rxjs'; import {Observable, Subject } from 'rxjs';
import{EnvProperties} from '../../utils/properties/env-properties'; import{EnvProperties} from '../../utils/properties/env-properties';
import {ErrorCodes} from '../../utils/properties/errorCodes'; import {ErrorCodes} from '../../utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../../utils/errorMessages.component'; import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
import {ClaimsDatatablePipe} from '../../utils/pipes/claimsDatatable.pipe';
import {RouterHelper} from '../../utils/routerHelper.class'; import {RouterHelper} from '../../utils/routerHelper.class';
import {ModalSelect} from '../../utils/modal/selectModal.component'; import {ModalSelect} from '../../utils/modal/selectModal.component';
@ -18,7 +21,6 @@ import {ClaimsByTokenService} from './claimsByToken.service';
import {Session} from '../../login/utils/helper.class'; import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {UserManagementService} from "../../services/user-management.service";
@Component({ @Component({
@ -87,14 +89,12 @@ export class ClaimsByTokenComponent {
constructor (private route: ActivatedRoute, constructor (private route: ActivatedRoute,
private _router: Router, private _router: Router,
private claimsByTokenService: ClaimsByTokenService, private claimsByTokenService: ClaimsByTokenService,
private _meta: Meta, private _title: Title, private _meta: Meta, private _title: Title) {
private userManagementService: UserManagementService) {
this.errorCodes = new ErrorCodes(); this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent(); this.errorMessages = new ErrorMessagesComponent();
this.pending_status = this.errorCodes.LOADING; this.pending_status = this.errorCodes.LOADING;
this.curated_status = this.errorCodes.LOADING; this.curated_status = this.errorCodes.LOADING;
} }
ngOnInit() { ngOnInit() {
this.route.data this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => { .subscribe((data: { envSpecific: EnvProperties }) => {
@ -146,24 +146,17 @@ export class ClaimsByTokenComponent {
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (isLoggedIn) {
$.fn['dataTable'].ext.search.push((settings, data, dataIndex) => { $.fn['dataTable'].ext.search.push((settings, data, dataIndex) => {
if(settings.sTableId == 'table1') { if(settings.sTableId == 'table1') {
return !!this.filterData(data, this.keyword1); if (this.filterData(data, this.keyword1)) {
return true;
}
return false;
} else if(settings.sTableId == 'table2') { } else if(settings.sTableId == 'table2') {
return !!this.filterData(data, this.keyword2); if (this.filterData(data, this.keyword2)) {
return true;
} }
}); return false;
} else {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} }
}); });
} }
@ -208,8 +201,12 @@ export class ClaimsByTokenComponent {
}); });
} }
filterData(row: any, query: string): boolean { filterData(row: any, query: string) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
let returnValue: boolean = false; let returnValue: boolean = false;
if(query) { if(query) {
for(var i=0; i <3; i++){ for(var i=0; i <3; i++){
var r= this.filterQuery(row[i], query); var r= this.filterQuery(row[i], query);
@ -223,8 +220,10 @@ export class ClaimsByTokenComponent {
return false; return false;
} }
} }
return true; return true;
} }
}
filterQuery(data, query){ filterQuery(data, query){
if(data.toLowerCase().indexOf(query.toLowerCase()) > -1){ if(data.toLowerCase().indexOf(query.toLowerCase()) > -1){
@ -235,14 +234,8 @@ export class ClaimsByTokenComponent {
} }
refreshTable(page:number, whichTable: string) { refreshTable(page:number, whichTable: string) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else { } else {
if(whichTable == "pending") { if(whichTable == "pending") {
var table = $('#table1').DataTable(); var table = $('#table1').DataTable();
@ -262,21 +255,14 @@ export class ClaimsByTokenComponent {
this.totalCuratedResults.count = info.recordsDisplay; this.totalCuratedResults.count = info.recordsDisplay;
} }
} }
});
//table.mfActivePage=$event.value; //table.mfActivePage=$event.value;
//table.setPage(table.mfActivePage, this.rowsOnPage); //table.setPage(table.mfActivePage, this.rowsOnPage);
} }
validateJWTandToken() { validateJWTandToken() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else { } else {
if(this.openaireId) { if(this.openaireId) {
this.pending_status = this.errorCodes.LOADING; this.pending_status = this.errorCodes.LOADING;
@ -371,18 +357,11 @@ export class ClaimsByTokenComponent {
this.accessStatus = "invalid"; this.accessStatus = "invalid";
} }
} }
});
} }
selectApprove(id:string, event, mode: string) { selectApprove(id:string, event, mode: string) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else { } else {
var value = event.currentTarget.checked; var value = event.currentTarget.checked;
if(value){ if(value){
@ -403,18 +382,11 @@ export class ClaimsByTokenComponent {
// } // }
} }
} }
});
} }
selectDisapprove(id:string, event, mode: string) { selectDisapprove(id:string, event, mode: string) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else { } else {
var value = event.currentTarget.checked; var value = event.currentTarget.checked;
if(value){ if(value){
@ -435,13 +407,11 @@ export class ClaimsByTokenComponent {
// } // }
} }
} }
});
} }
isSelected(id:string, set:Set<string>) { isSelected(id:string, set:Set<string>) {
return set.has(id); return set.has(id);
} }
/* /*
isSelectedWrong(id:string) { isSelectedWrong(id:string) {
return this.selectedWrong.has(id); return this.selectedWrong.has(id);
@ -468,14 +438,8 @@ export class ClaimsByTokenComponent {
} }
cancelEditOfCuration(claim: any) { cancelEditOfCuration(claim: any) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else { } else {
if(claim.approved) { if(claim.approved) {
//this.selectedRight_CuratedMode.add(claim.id); //this.selectedRight_CuratedMode.add(claim.id);
@ -485,18 +449,11 @@ export class ClaimsByTokenComponent {
//this.selectedWrong_CuratedMode.add(claim.id); //this.selectedWrong_CuratedMode.add(claim.id);
} }
} }
});
} }
saveEdited(claim: any, editable_index: number) { saveEdited(claim: any, editable_index: number) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else { } else {
this.curated_status = this.errorCodes.LOADING; this.curated_status = this.errorCodes.LOADING;
@ -527,18 +484,11 @@ export class ClaimsByTokenComponent {
); );
} }
} }
});
} }
saveChanges() { saveChanges() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else { } else {
this.pending_status = this.errorCodes.LOADING; this.pending_status = this.errorCodes.LOADING;
//this.openLoading(); //this.openLoading();
@ -558,25 +508,17 @@ export class ClaimsByTokenComponent {
} }
); );
} }
});
} }
clearCheckboxes() { clearCheckboxes() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else { } else {
this.pending_status = this.errorCodes.LOADING; this.pending_status = this.errorCodes.LOADING;
this.selectedRight_PendingMode.clear(); this.selectedRight_PendingMode.clear();
this.selectedWrong_PendingMode.clear(); this.selectedWrong_PendingMode.clear();
this.pending_status = this.errorCodes.DONE; this.pending_status = this.errorCodes.DONE;
} }
});
} }
public openLoading(){ public openLoading(){
@ -584,7 +526,6 @@ export class ClaimsByTokenComponent {
this.loading.open(); this.loading.open();
} }
} }
public closeLoading(){ public closeLoading(){
if(this.loading){ if(this.loading){
this.loading.close(); this.loading.close();

View File

@ -1,6 +1,9 @@
import {Component, Input} from '@angular/core'; import {Component, ViewChild, Input} from '@angular/core';
import {Location} from '@angular/common'; import {Location} from '@angular/common';
import {Observable} from 'rxjs';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
import {ModalLoading} from '../../utils/modal/loading.component';
import {AlertModal} from '../../utils/modal/alert';
import {Session} from '../../login/utils/helper.class'; import {Session} from '../../login/utils/helper.class';
import {EnvProperties} from '../../utils/properties/env-properties'; import {EnvProperties} from '../../utils/properties/env-properties';
import {MailPrefsService} from './mailPrefs.service'; import {MailPrefsService} from './mailPrefs.service';
@ -8,7 +11,6 @@ import {ConnectHelper} from '../connectHelper';
import {ErrorCodes} from '../../utils/properties/errorCodes'; import {ErrorCodes} from '../../utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../../utils/errorMessages.component'; import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {UserManagementService} from "../../services/user-management.service";
declare var UIkit: any; declare var UIkit: any;
@ -32,6 +34,7 @@ export class MailPrefsComponent {
//public showForbiddenMessage:boolean = false; //public showForbiddenMessage:boolean = false;
public userValidMessage:string = ""; public userValidMessage:string = "";
public savedMessage: string = ""; public savedMessage: string = "";
public fetchId:string; public fetchId:string;
private errorCodes: ErrorCodes; private errorCodes: ErrorCodes;
@ -39,10 +42,7 @@ export class MailPrefsComponent {
@Input() showSaveResetButtons: boolean = true; @Input() showSaveResetButtons: boolean = true;
constructor(private _mailPrefsService: MailPrefsService, constructor (private _mailPrefsService: MailPrefsService, private route: ActivatedRoute, private _router:Router, private location: Location) {
private route: ActivatedRoute, private _router: Router,
private location: Location,
private userManagementService: UserManagementService) {
this.errorCodes = new ErrorCodes(); this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent(); this.errorMessages = new ErrorMessagesComponent();
this.status = this.errorCodes.LOADING; this.status = this.errorCodes.LOADING;
@ -57,26 +57,21 @@ export class MailPrefsComponent {
if(!this.communityId) { if(!this.communityId) {
this.communityId = params['communityId']; this.communityId = params['communityId'];
} }
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.fetchId = user.email; this.fetchId = Session.getUserEmail();
this.getEmailPreferences(); this.getEmailPreferences();
});
}); });
}); });
} }
getEmailPreferences() { getEmailPreferences() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again."; //this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) { if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} }
} else { } else {
this.status = this.errorCodes.LOADING; this.status = this.errorCodes.LOADING;
@ -125,20 +120,13 @@ export class MailPrefsComponent {
); );
} }
} }
});
} }
changeNotify(notification: any, checked: boolean, index: number) { changeNotify(notification: any, checked: boolean, index: number) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again."; //this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) { if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} }
} else { } else {
this.savedMessage = ""; this.savedMessage = "";
@ -146,20 +134,13 @@ export class MailPrefsComponent {
notification.notify = checked; notification.notify = checked;
this.prefsChanged[index] = true; this.prefsChanged[index] = true;
} }
});
} }
changeFrequency(index: number) { changeFrequency(index: number) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again."; //this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) { if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} }
} else { } else {
this.savedMessage = ""; this.savedMessage = "";
@ -168,21 +149,14 @@ export class MailPrefsComponent {
this.prefsChanged[index] = true; this.prefsChanged[index] = true;
} }
} }
});
} }
saveNotification(index: number) { saveNotification(index: number) {
if(this.notifications.length > 0 && this.initialNotifications.length > 0) { if(this.notifications.length > 0 && this.initialNotifications.length > 0) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again."; //this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) { if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} }
} else { } else {
if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) { if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) {
@ -210,7 +184,8 @@ export class MailPrefsComponent {
this.status = this.errorCodes.NOT_SAVED; this.status = this.errorCodes.NOT_SAVED;
} }
); );
} else { }
else {
/*UIkit.notification({ /*UIkit.notification({
message : '<strong>No changes selected for '+this.notifications[index].openaireName+' email preferences<strong>', message : '<strong>No changes selected for '+this.notifications[index].openaireName+' email preferences<strong>',
status : 'primary', status : 'primary',
@ -220,21 +195,14 @@ export class MailPrefsComponent {
this.savedMessage = "Notification settings for claims saved!"; this.savedMessage = "Notification settings for claims saved!";
} }
} }
});
} }
} }
restoreNotification(index: number) { restoreNotification(index: number) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { if(!Session.isLoggedIn()){
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again."; //this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) { if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} }
} else { } else {
if(this.notifications.length > 0 && this.initialNotifications.length > 0) { if(this.notifications.length > 0 && this.initialNotifications.length > 0) {
@ -245,9 +213,7 @@ export class MailPrefsComponent {
this.prefsChanged[index] = false; this.prefsChanged[index] = false;
} }
} }
});
} }
/* /*
prefsChanged(index: number) : boolean { prefsChanged(index: number) : boolean {
if(this.notifications.length > 0 && this.initialNotifications.length > 0) { if(this.notifications.length > 0 && this.initialNotifications.length > 0) {

View File

@ -1,47 +1,31 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Route, CanLoad} from '@angular/router';
Router, import {Observable} from 'rxjs/Observable';
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Route,
CanLoad,
UrlSegment
} from '@angular/router';
import {Observable} from 'rxjs';
import {Session} from './utils/helper.class'; import {Session} from './utils/helper.class';
import {LoginErrorCodes} from './utils/guardHelper.class'; import {LoginErrorCodes} from './utils/guardHelper.class';
import {filter, map, mergeMap} from "rxjs/operators";
import {CommunityService} from "../connect/community/community.service";
import {UserManagementService} from "../services/user-management.service";
import {EnvironmentSpecificService} from "../utils/properties/environment-specific.service";
@Injectable() @Injectable()
export class LoginGuard implements CanActivate { export class LoginGuard implements CanActivate, CanLoad {
constructor(private router: Router, constructor(private router: Router) {
private userManagementService: UserManagementService,
private propertiesService: EnvironmentSpecificService) {
} }
check(path: string): Observable<boolean> |boolean { check(path: string): boolean {
const loggedIn = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => { let loggedIn = false;
return this.userManagementService.isLoggedIn(properties['userInfoUrl']).pipe(map( isLoggedIn => { if (Session.isLoggedIn()) {
return isLoggedIn; loggedIn = true;
})); }
})); if (!loggedIn) {
loggedIn.pipe(filter( isLoggedIn => !isLoggedIn)).subscribe( () => { this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}});
this.router.navigate(['/user-info'], {
queryParams: {
'errorCode': LoginErrorCodes.NOT_LOGIN,
'redirectUrl': path
} }
});
});
return loggedIn; return loggedIn;
} }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check(state.url); return this.check(state.url);
} }
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
return this.check('/' + route.path);
}
} }

View File

@ -51,21 +51,18 @@ export class UserComponent {
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user; this.user = user;
this.loggedIn = !!this.user; this.loggedIn = !!this.user;
});
this.errorMessage = ""; this.errorMessage = "";
this.sub = this.route.queryParams.subscribe(params => { this.sub = this.route.queryParams.subscribe(params => {
this.errorCode = params["errorCode"]; this.errorCode = params["errorCode"];
this.redirectUrl = params["redirectUrl"]; this.redirectUrl = params["redirectUrl"];
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.user = user;
this.loggedIn = !!this.user;
});
this.errorMessage = ""; this.errorMessage = "";
if (this.loggedIn && this.errorCode == '1') { if (this.loggedIn && this.errorCode == '1') {
this.redirect(); this.redirect();
} }
}); });
});
} }
ngOnDestroy() { ngOnDestroy() {
this.sub.unsubscribe(); this.sub.unsubscribe();
if (this.sublogin) { if (this.sublogin) {
@ -74,7 +71,7 @@ export class UserComponent {
} }
redirect() { redirect() {
if(this.redirectUrl && this.redirectUrl != null && this.redirectUrl != ""){ if (this.redirectUrl && this.redirectUrl != "") {
this.redirectUrl = decodeURIComponent(this.redirectUrl); this.redirectUrl = decodeURIComponent(this.redirectUrl);
var baseUrl = this.redirectUrl; var baseUrl = this.redirectUrl;
var queryParams = ""; var queryParams = "";
@ -101,7 +98,7 @@ export class UserComponent {
} }
logIn() { logIn() {
if(this.redirectUrl && this.redirectUrl != null && this.redirectUrl != ""){ if (this.redirectUrl && this.redirectUrl != "") {
this.redirectUrl = decodeURIComponent(this.redirectUrl); this.redirectUrl = decodeURIComponent(this.redirectUrl);
var baseUrl = this.redirectUrl; var baseUrl = this.redirectUrl;
var queryParams = ""; var queryParams = "";
@ -119,6 +116,7 @@ export class UserComponent {
window.location.href = this.properties.loginUrl; window.location.href = this.properties.loginUrl;
} }
getTheRolesFormatted(roles: string[]) { getTheRolesFormatted(roles: string[]) {
let formattedRoles = []; let formattedRoles = [];
for (let role of roles) { for (let role of roles) {
@ -130,6 +128,7 @@ export class UserComponent {
} }
return formattedRoles.join(", "); return formattedRoles.join(", ");
} }
isUserManager() { isUserManager() {
return Session.isUserManager(this.user); return Session.isUserManager(this.user);
} }