locale + darktheme support, fixes boolean profilefield
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Router} from '@angular/router';
|
||||
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {AuthService} from '../services/auth.service';
|
||||
import {ProfileService} from '../services/profile.service';
|
||||
import {I18nService} from '../services/i18n.service';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -35,7 +38,7 @@ export class AuthGuard implements CanActivate {
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthenticatedGuard implements CanActivate {
|
||||
constructor(private authService: AuthService, private router: Router) {}
|
||||
constructor(private authService: AuthService, private profileService: ProfileService, private i18nService: I18nService, private router: Router) {}
|
||||
|
||||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
const that = this;
|
||||
@@ -44,6 +47,27 @@ export class AuthenticatedGuard implements CanActivate {
|
||||
this.router.navigateByUrl('/login');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
this.profileService.getAll(["locale", "darkTheme"]).toPromise().then((profileFields: any) => {
|
||||
let reload = false;
|
||||
for(let profileField of profileFields) {
|
||||
if(profileField.name == "darkTheme" && profileField.value != localStorage.getItem("bstly.darkTheme")) {
|
||||
localStorage.setItem("bstly.darkTheme", profileField.value);
|
||||
reload = true;
|
||||
} else if(profileField.name == "locale" && this.i18nService.locales.indexOf(profileField.value) != -1 && localStorage.getItem("bstly.locale") != profileField.value) {
|
||||
if(this.i18nService.locale != profileField.value) {
|
||||
localStorage.setItem("bstly.locale", profileField.value);
|
||||
reload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(reload) {
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
|
||||
return true;
|
||||
}).catch(function(error) {
|
||||
return that.router.parseUrl('/unavailable');
|
||||
|
||||
Reference in New Issue
Block a user