This commit is contained in:
Bartosz Sekula
2024-04-04 11:18:28 +02:00
parent d45a02042e
commit 47a21b1787
6 changed files with 52 additions and 13 deletions

View File

@@ -55,7 +55,11 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (this.authenticationService.isLoggedIn() && this.authenticationService.isOauth() && this.isLoginFragmentPresent()) {
if (
this.authenticationService.isLoggedIn() &&
this.authenticationService.isOauth() &&
this.isLoginFragmentPresent()
) {
return this.redirectSSOSuccessURL();
}

View File

@@ -100,6 +100,7 @@ export class AuthenticationService implements AuthenticationServiceInterface, ee
}
getToken(): string {
debugger;
if (this.isOauth()) {
return this.oidcAuthenticationService.getToken();
} else {

View File

@@ -15,7 +15,13 @@
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
export interface StorageServiceSettings {
storageType?: 'localStorage' | 'sessionStorage' | 'memoryStorage';
}
export const STORAGE_SERVICE_SETTINGS = new InjectionToken('STORAGE_SERVICE_SETTINGS');
@Injectable({
providedIn: 'root'
@@ -24,6 +30,7 @@ export class StorageService {
private memoryStore: { [key: string]: any } = {};
private readonly useLocalStorage: boolean = false;
private _prefix: string = '';
private storage?: Storage;
get prefix() {
return this._prefix;
@@ -33,8 +40,28 @@ export class StorageService {
this._prefix = prefix ? prefix + '_' : '';
}
constructor() {
constructor(
@Optional()
@Inject(STORAGE_SERVICE_SETTINGS) private settings?: StorageServiceSettings
) {
if (this.settings) {
debugger;
switch (this.settings.storageType) {
case 'sessionStorage':
this.useLocalStorage = this.storageAvailable(this.settings.storageType);
this.storage = window['sessionStorage'];
break;
case 'memoryStorage':
this.useLocalStorage = false;
break;
default:
this.useLocalStorage = this.storageAvailable(this.settings.storageType);
this.storage = window['localStorage'];
}
} else {
this.useLocalStorage = this.storageAvailable('localStorage');
this.storage = window['localStorage'];
}
}
/**
@@ -45,7 +72,7 @@ export class StorageService {
*/
getItem(key: string): string | null {
if (this.useLocalStorage) {
return localStorage.getItem(this.prefix + key);
return this.storage.getItem(this.prefix + key);
} else {
return Object.prototype.hasOwnProperty.call(this.memoryStore, this.prefix + key) ? this.memoryStore[this.prefix + key] : null;
}
@@ -59,7 +86,7 @@ export class StorageService {
*/
setItem(key: string, data: string) {
if (this.useLocalStorage) {
localStorage.setItem(this.prefix + key, data);
this.storage.setItem(this.prefix + key, data);
} else {
this.memoryStore[this.prefix + key] = data.toString();
}
@@ -68,7 +95,7 @@ export class StorageService {
/** Removes all currently stored items. */
clear() {
if (this.useLocalStorage) {
localStorage.clear();
this.storage.clear();
} else {
this.memoryStore = {};
}
@@ -81,7 +108,7 @@ export class StorageService {
*/
removeItem(key: string) {
if (this.useLocalStorage) {
localStorage.removeItem(`${this.prefix}` + key);
this.storage.removeItem(`${this.prefix}` + key);
} else {
delete this.memoryStore[this.prefix + key];
}
@@ -95,7 +122,7 @@ export class StorageService {
*/
hasItem(key: string): boolean {
if (this.useLocalStorage) {
return !!localStorage.getItem(this.prefix + key);
return !!this.storage.getItem(this.prefix + key);
} else {
return Object.prototype.hasOwnProperty.call(this.memoryStore, key);
}

View File

@@ -114,6 +114,7 @@ export class UserPreferencesService {
* @param value New value for the property
*/
set(property: string, value: any) {
console.trace();
if (!property) {
return;
}
@@ -132,6 +133,7 @@ export class UserPreferencesService {
* @param value New value for the property
*/
setWithoutStore(property: string, value: any) {
// debugger;
if (!property) {
return;
}

View File

@@ -38,8 +38,10 @@ export class TimeAgoPipe implements PipeTransform, OnDestroy {
private onDestroy$ = new Subject<boolean>();
constructor(public userPreferenceService: UserPreferencesService,
public appConfig: AppConfigService) {
constructor(
public userPreferenceService: UserPreferencesService,
public appConfig: AppConfigService
) {
this.userPreferenceService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))

View File

@@ -375,6 +375,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
}
return form;
}
return null;
}
@@ -396,9 +397,11 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
private refreshFormData() {
this.form = this.parseForm(this.formCloudRepresentationJSON);
if (this.form) {
this.onFormLoaded(this.form);
this.onFormDataRefreshed(this.form);
}
}
protected onFormLoaded(form: FormModel) {
if (form) {