9 Commits

16 changed files with 195 additions and 183 deletions

View File

@@ -86,10 +86,10 @@
"no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯", "no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯",
"not_implemented_yet": "Ey Alter, das kann ich noch nicht...", "not_implemented_yet": "Ey Alter, das kann ich noch nicht...",
"presence": { "presence": {
"booting": "{} Ich fahre gerade hoch...", "booting": "Ich fahre gerade hoch...",
"restart": "{} Muss neue Kekse holen...", "restart": "Muss neue Kekse holen...",
"running": "{} Ich esse Kekse :D", "running": "Ich esse Kekse :D",
"shutdown": "{} Ich werde bestimmt wieder kommen..." "shutdown": "Ich werde bestimmt wieder kommen..."
} }
}, },
"modules": { "modules": {

View File

@@ -129,7 +129,6 @@ class AuthController:
return "", 200 return "", 200
@Route.post(f"{BasePath}/refresh") @Route.post(f"{BasePath}/refresh")
@Route.authorize
async def refresh(self) -> Response: async def refresh(self) -> Response:
dto: TokenDTO = JSONProcessor.process(TokenDTO, request.get_json(force=True, silent=True)) dto: TokenDTO = JSONProcessor.process(TokenDTO, request.get_json(force=True, silent=True))
result = await self._auth_service.refresh_async(dto) result = await self._auth_service.refresh_async(dto)

View File

@@ -10,11 +10,12 @@ class FeatureFlagsEnum(Enum):
boot_log_module = "BootLogModule" boot_log_module = "BootLogModule"
core_module = "CoreModule" core_module = "CoreModule"
core_extension_module = "CoreExtensionModule" core_extension_module = "CoreExtensionModule"
data_module = ("DataModule",) data_module = "DataModule"
database_module = ("DatabaseModule",) database_module = "DatabaseModule"
level_module = "LevelModule" level_module = "LevelModule"
moderator_module = "ModeratorModule" moderator_module = "ModeratorModule"
permission_module = "PermissionModule" permission_module = "PermissionModule"
# features # features
api_only = "ApiOnly" api_only = "ApiOnly"
presence = "Presence" presence = "Presence"
version_in_presence = "VersionInPresence"

View File

@@ -1,5 +1,4 @@
import traceback import traceback
from typing import Optional, Callable
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.console import Console from cpl_core.console import Console
@@ -27,6 +26,7 @@ class FeatureFlagsSettings(ConfigurationModelABC):
# features # features
FeatureFlagsEnum.api_only.value: False, # 13.10.2022 #70 FeatureFlagsEnum.api_only.value: False, # 13.10.2022 #70
FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56 FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56
FeatureFlagsEnum.version_in_presence.value: False, # 21.03.2023 #253
} }
def get_flag(self, key: FeatureFlagsEnum) -> bool: def get_flag(self, key: FeatureFlagsEnum) -> bool:

View File

@@ -111,7 +111,11 @@ class ClientUtilsService(ClientUtilsABC):
import bot import bot
name = self._t.transform(t_key).format(bot.__version__) if self._feature_flags.get_flag(FeatureFlagsEnum.version_in_presence):
name = f"{bot.__version__} {self._t.transform(t_key)}"
else:
name = self._t.transform(t_key)
await self._bot.change_presence(activity=discord.Game(name=name)) await self._bot.change_presence(activity=discord.Game(name=name))
self._logger.info(__name__, f"Set presence {name}") self._logger.info(__name__, f"Set presence {name}")

View File

@@ -82,7 +82,7 @@ class QueryABC(ObjectType):
break break
elif type(element) == AutoRoleRule: elif type(element) == AutoRoleRule:
element: AutoRole = element.game_server element: AutoRole = element
for u in user.users: for u in user.users:
u: User = u u: User = u
guild = bot.get_guild(u.server.discord_id) guild = bot.get_guild(u.server.discord_id)
@@ -124,28 +124,36 @@ class QueryABC(ObjectType):
elif type(element) == User: elif type(element) == User:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.id == element.id: guild = bot.get_guild(u.server.discord_id)
member = guild.get_member(u.discord_id)
if u.id == element.id or permissions.is_member_moderator(member):
access = True access = True
break break
elif type(element) == UserJoinedServer: elif type(element) == UserJoinedServer:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.id == element.user.id: guild = bot.get_guild(u.server.discord_id)
member = guild.get_member(u.discord_id)
if u.id == element.id or permissions.is_member_moderator(member):
access = True access = True
break break
elif type(element) == UserJoinedVoiceChannel: elif type(element) == UserJoinedVoiceChannel:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.id == element.user.id: guild = bot.get_guild(u.server.discord_id)
member = guild.get_member(u.discord_id)
if u.id == element.id or permissions.is_member_moderator(member):
access = True access = True
break break
elif type(element) == UserJoinedGameServer: elif type(element) == UserJoinedGameServer:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.id == element.user.id: guild = bot.get_guild(u.server.discord_id)
member = guild.get_member(u.discord_id)
if u.id == element.id or permissions.is_member_moderator(member):
access = True access = True
break break

View File

@@ -1,18 +1,19 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from "@angular/core";
import { Router } from '@angular/router'; import { Router } from "@angular/router";
import { LangChangeEvent, TranslateService } from '@ngx-translate/core'; import { LangChangeEvent, TranslateService } from "@ngx-translate/core";
import { MenuItem, PrimeNGConfig } from 'primeng/api'; import { MenuItem, PrimeNGConfig } from "primeng/api";
import { catchError } from 'rxjs/operators'; import { catchError } from "rxjs/operators";
import { AuthService } from 'src/app/services/auth/auth.service'; import { AuthService } from "src/app/services/auth/auth.service";
import { SettingsService } from 'src/app/services/settings/settings.service'; import { SettingsService } from "src/app/services/settings/settings.service";
import { SpinnerService } from 'src/app/services/spinner/spinner.service'; import { SpinnerService } from "src/app/services/spinner/spinner.service";
import { ThemeService } from 'src/app/services/theme/theme.service'; import { ThemeService } from "src/app/services/theme/theme.service";
import { throwError } from "rxjs"; import { throwError } from "rxjs";
import { SidebarService } from "../../services/sidebar/sidebar.service";
@Component({ @Component({
selector: 'app-header', selector: "app-header",
templateUrl: './header.component.html', templateUrl: "./header.component.html",
styleUrls: ['./header.component.scss'] styleUrls: ["./header.component.scss"]
}) })
export class HeaderComponent implements OnInit { export class HeaderComponent implements OnInit {
langList: MenuItem[] = []; langList: MenuItem[] = [];
@@ -26,8 +27,10 @@ export class HeaderComponent implements OnInit {
private spinnerService: SpinnerService, private spinnerService: SpinnerService,
private settings: SettingsService, private settings: SettingsService,
private translateService: TranslateService, private translateService: TranslateService,
private config: PrimeNGConfig private config: PrimeNGConfig,
) { } private sidebarService: SidebarService,
) {
}
ngOnInit(): void { ngOnInit(): void {
this.initMenuLists(); this.initMenuLists();
@@ -38,9 +41,12 @@ export class HeaderComponent implements OnInit {
} }
initUserMenuList(): void { initUserMenuList(): void {
if (!this.authService.isLoggedIn$.value) {
return;
}
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
const mail = this.authService.getEMailFromDecodedToken(this.authService.getDecodedToken()); const mail = this.authService.getEMailFromDecodedToken(this.authService.getDecodedToken());
this.authService.getUserByEMail(mail ?? '') this.authService.getUserByEMail(mail ?? "")
.pipe(catchError(error => { .pipe(catchError(error => {
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
this.authService.logout(); this.authService.logout();
@@ -48,7 +54,7 @@ export class HeaderComponent implements OnInit {
})) }))
.subscribe(user => { .subscribe(user => {
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
this.sidebarService.setMenu(true);
this.userMenuList = [ this.userMenuList = [
{ {
@@ -59,22 +65,22 @@ export class HeaderComponent implements OnInit {
separator: true separator: true
}, },
{ {
label: this.translateService.instant('header.change_password'), command: () => { label: this.translateService.instant("header.change_password"), command: () => {
this.changePassword(); this.changePassword();
}, },
icon: 'pi pi-key' icon: "pi pi-key"
}, },
{ {
label: this.translateService.instant('header.settings'), command: () => { label: this.translateService.instant("header.settings"), command: () => {
this.userSettings(); this.userSettings();
}, },
icon: 'pi pi-cog' icon: "pi pi-cog"
}, },
{ {
label: this.translateService.instant('header.logout'), command: () => { label: this.translateService.instant("header.logout"), command: () => {
this.logout(); this.logout();
}, },
icon: 'pi pi-sign-out' icon: "pi pi-sign-out"
} }
]; ];
}); });
@@ -83,17 +89,17 @@ export class HeaderComponent implements OnInit {
initMenuLists(): void { initMenuLists(): void {
this.langList = [ this.langList = [
{ {
label: 'English', command: () => { label: "English", command: () => {
this.translate('en'); this.translate("en");
this.setLang('en'); this.setLang("en");
}, }
}, },
{ {
label: 'Deutsch', command: () => { label: "Deutsch", command: () => {
this.translate('de'); this.translate("de");
this.setLang('de'); this.setLang("de");
}, }
}, }
]; ];
this.initUserMenuList(); this.initUserMenuList();
@@ -117,11 +123,11 @@ export class HeaderComponent implements OnInit {
} }
changePassword(): void { changePassword(): void {
this.router.navigate(['/change-password']); this.router.navigate(["/change-password"]);
} }
userSettings(): void { userSettings(): void {
this.router.navigate(['/user-settings']); this.router.navigate(["/user-settings"]);
} }
logout(): void { logout(): void {
@@ -130,7 +136,7 @@ export class HeaderComponent implements OnInit {
translate(lang: string) { translate(lang: string) {
this.translateService.use(lang); this.translateService.use(lang);
this.translateService.get('primeng').subscribe(res => this.config.setTranslation(res)); this.translateService.get("primeng").subscribe(res => this.config.setTranslation(res));
} }
loadLang(): void { loadLang(): void {
@@ -138,28 +144,26 @@ export class HeaderComponent implements OnInit {
const mail = this.authService.getEMailFromDecodedToken(token); const mail = this.authService.getEMailFromDecodedToken(token);
if (!mail) { if (!mail) {
this.translate('en'); this.translate("en");
return; return;
} }
let lang = localStorage.getItem(`${mail}_lang`); let lang = localStorage.getItem(`${mail}_lang`);
if (!lang) { if (!lang) {
lang = 'en'; lang = "en";
this.setLang(lang); this.setLang(lang);
} }
this.translate(lang); this.translate(lang);
} }
setLang(lang: string): void { setLang(lang: string): void {
this.authService.isUserLoggedInAsync().then(result => { if (!this.authService.isLoggedIn$.value) {
if (!result) { return;
return; }
}
const token = this.authService.getDecodedToken(); const token = this.authService.getDecodedToken();
const mail = this.authService.getEMailFromDecodedToken(token); const mail = this.authService.getEMailFromDecodedToken(token);
localStorage.setItem(`${mail}_lang`, lang); localStorage.setItem(`${mail}_lang`, lang);
});
} }
} }

View File

@@ -1,18 +1,18 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from "@angular/router";
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from "@ngx-translate/core";
import { catchError } from 'rxjs/operators'; import { catchError } from "rxjs/operators";
import { ResetPasswordDTO } from 'src/app/models/auth/reset-password.dto'; import { ResetPasswordDTO } from "src/app/models/auth/reset-password.dto";
import { AuthService } from 'src/app/services/auth/auth.service'; import { AuthService } from "src/app/services/auth/auth.service";
import { SpinnerService } from 'src/app/services/spinner/spinner.service'; import { SpinnerService } from "src/app/services/spinner/spinner.service";
import { ToastService } from 'src/app/services/toast/toast.service'; import { ToastService } from "src/app/services/toast/toast.service";
import { throwError } from "rxjs"; import { throwError } from "rxjs";
@Component({ @Component({
selector: 'app-forget-password', selector: "app-forget-password",
templateUrl: './forget-password.component.html', templateUrl: "./forget-password.component.html",
styleUrls: ['./forget-password.component.scss'] styleUrls: ["./forget-password.component.scss"]
}) })
export class ForgetPasswordComponent implements OnInit { export class ForgetPasswordComponent implements OnInit {
@@ -35,19 +35,18 @@ export class ForgetPasswordComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
private toastService: ToastService, private toastService: ToastService,
private translate: TranslateService private translate: TranslateService
) { } ) {
}
ngOnInit(): void { ngOnInit(): void {
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
this.authService.isUserLoggedInAsync().then(result => { if (!this.authService.isLoggedIn$.value) {
if (result) { this.router.navigate(["/dashboard"]);
this.router.navigate(['/dashboard']); }
}
this.initForms(); this.initForms();
this.checkResetPasswordId(); this.checkResetPasswordId();
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
});
} }
initForms(): void { initForms(): void {
@@ -62,11 +61,11 @@ export class ForgetPasswordComponent implements OnInit {
} }
login(): void { login(): void {
this.router.navigate(['/auth/login']); this.router.navigate(["/auth/login"]);
} }
register(): void { register(): void {
this.router.navigate(['/auth/register']); this.router.navigate(["/auth/register"]);
} }
forgotPassword(): void { forgotPassword(): void {
@@ -82,35 +81,37 @@ export class ForgetPasswordComponent implements OnInit {
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
return throwError(() => error); return throwError(() => error);
})).subscribe(res => { })).subscribe(res => {
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
this.ready = true; this.ready = true;
setTimeout(() => { this.router.navigate(['/dashboard']); }, 5000); setTimeout(() => {
}); this.router.navigate(["/dashboard"]);
}, 5000);
});
} }
checkResetPasswordId(): void { checkResetPasswordId(): void {
const id = this.route.snapshot.params['id']; const id = this.route.snapshot.params["id"];
if (id) { if (id) {
this.resetPasswordId = id; this.resetPasswordId = id;
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
this.authService.getEMailFromforgotPasswordId(id) this.authService.getEMailFromforgotPasswordId(id)
.pipe(catchError(error => { .pipe(catchError(error => {
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
this.router.navigate(['/auth/forgot-password']); this.router.navigate(["/auth/forgot-password"]);
return throwError(() => error); return throwError(() => error);
})).subscribe(email => { })).subscribe(email => {
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
if (email) { if (email) {
this.emailForm.value.email = email; this.emailForm.value.email = email;
} else { } else {
this.router.navigate(['/auth/forgot-password']); this.router.navigate(["/auth/forgot-password"]);
} }
}); });
} }
} }
resetPassword(): void { resetPassword(): void {
const id = this.route.snapshot.params['id']; const id = this.route.snapshot.params["id"];
if (this.emailForm.value.password !== this.emailForm.value.passwordRepeat) { if (this.emailForm.value.password !== this.emailForm.value.passwordRepeat) {
this.repeatErrors.password = true; this.repeatErrors.password = true;
return; return;
@@ -124,14 +125,14 @@ export class ForgetPasswordComponent implements OnInit {
this.authService.resetPassword(resetPasswordDTO) this.authService.resetPassword(resetPasswordDTO)
.pipe(catchError(error => { .pipe(catchError(error => {
this.router.navigate(['/auth/login']); this.router.navigate(["/auth/login"]);
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
return throwError(() => error); return throwError(() => error);
})) }))
.subscribe(resp => { .subscribe(resp => {
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
this.toastService.success(this.translate.instant('auth.forgot_password.message.reset_password'), this.translate.instant('auth.forgot_password.message.reset_password_d')); this.toastService.success(this.translate.instant("auth.forgot_password.message.reset_password"), this.translate.instant("auth.forgot_password.message.reset_password_d"));
this.router.navigate(['/auth/login']); this.router.navigate(["/auth/login"]);
}); });
} }
} }

View File

@@ -48,16 +48,14 @@ export class LoginComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.initLoginForm(); this.initLoginForm();
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
this.authService.isUserLoggedInAsync().then(result => { if (this.authService.isLoggedIn$.value) {
if (result) { this.router.navigate(["/dashboard"]);
this.router.navigate(["/dashboard"]); return;
return; }
}
this.checkDiscordLogin(); this.checkDiscordLogin();
this.resetStateFlags(); this.resetStateFlags();
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
});
} }
checkDiscordLogin() { checkDiscordLogin() {

View File

@@ -49,12 +49,10 @@ export class RegistrationComponent implements OnInit, OnDestroy {
private settings: SettingsService private settings: SettingsService
) { ) {
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
this.authService.isUserLoggedInAsync().then(res => { if (!this.authService.isLoggedIn$.value) {
if (res) { this.router.navigate(["/dashboard"]);
this.router.navigate(["/dashboard"]); }
} this.spinnerService.hideSpinner();
this.spinnerService.hideSpinner();
});
} }
ngOnInit(): void { ngOnInit(): void {

View File

@@ -1,4 +1,4 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { Queries } from "../../../../models/graphql/queries.model"; import { Queries } from "../../../../models/graphql/queries.model";
import { UserListQuery } from "../../../../models/graphql/query.model"; import { UserListQuery } from "../../../../models/graphql/query.model";
@@ -10,17 +10,21 @@ import { AuthService } from "src/app/services/auth/auth.service";
import { ToastService } from "src/app/services/toast/toast.service"; import { ToastService } from "src/app/services/toast/toast.service";
import { TranslateService } from "@ngx-translate/core"; import { TranslateService } from "@ngx-translate/core";
import { Server } from "../../../../models/data/server.model"; import { Server } from "../../../../models/data/server.model";
import { Subject } from "rxjs";
import { takeUntil } from "rxjs/operators";
@Component({ @Component({
selector: "app-profile", selector: "app-profile",
templateUrl: "./profile.component.html", templateUrl: "./profile.component.html",
styleUrls: ["./profile.component.scss"] styleUrls: ["./profile.component.scss"]
}) })
export class ProfileComponent implements OnInit { export class ProfileComponent implements OnInit, OnDestroy {
user: User = { createdAt: "", modifiedAt: "" }; user: User = { createdAt: "", modifiedAt: "" };
private server: Server = {}; private server: Server = {};
private unsubscriber = new Subject<void>();
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
@@ -32,42 +36,47 @@ export class ProfileComponent implements OnInit {
) { ) {
} }
ngOnInit() { public ngOnInit(): void {
this.data.getServerFromRoute(this.route).then(async (server) => { this.route.params.pipe(takeUntil(this.unsubscriber)).subscribe(params => {
if (!this.route.snapshot.params["memberId"] || this.route.snapshot.params["memberId"] == "undefined") { this.data.getServerFromRoute(this.route).then(async (server) => {
this.router.navigate([`/server/${server.id}`]); if (!params["memberId"] || params["memberId"] == "undefined") {
return; await this.router.navigate([`/server/${server.id}`]);
} return;
this.server = server; }
this.server = server;
let authUser = await this.auth.getLoggedInUser(); let authUser = await this.auth.getLoggedInUser();
this.spinner.showSpinner(); this.spinner.showSpinner();
let user: UserDTO | null = authUser?.users?.find(u => u.server == server.id) ?? null; let user: UserDTO | null = authUser?.users?.find(u => u.server == server.id) ?? null;
if (!user || user?.id != this.route.snapshot.params["memberId"] && !user?.isModerator) { if (!user || user?.id != params["memberId"] && !user?.isModerator) {
this.toast.error(this.translate.instant("view.server.profile.permission_denied"), this.translate.instant("view.server.profile.permission_denied_d")); this.toast.error(this.translate.instant("view.server.profile.permission_denied"), this.translate.instant("view.server.profile.permission_denied_d"));
this.spinner.hideSpinner(); this.spinner.hideSpinner();
this.router.navigate(["/server", server.id]); await this.router.navigate(["/server", server.id]);
return; return;
} }
this.data.query<UserListQuery>(Queries.usersQuery, { this.data.query<UserListQuery>(Queries.usersQuery, {
serverId: this.server.id, serverId: this.server.id,
filter: { filter: {
id: this.route.snapshot.params["memberId"] id: params["memberId"]
}
},
(x: { servers: Server[] }) => {
return x.servers[0];
} }
}, ).subscribe(users => {
(x: { servers: Server[] }) => { if (!users.users[0]) {
return x.servers[0]; this.router.navigate([`/server/${server.id}`]);
} }
).subscribe(users => { this.user = users.users[0];
if (!users.users[0]) { this.spinner.hideSpinner();
this.router.navigate([`/server/${server.id}`]); });
}
this.user = users.users[0];
this.spinner.hideSpinner();
}); });
}); });
}
public ngOnDestroy(): void {
this.unsubscriber.next();
this.unsubscriber.complete();
} }
} }

View File

@@ -2,7 +2,7 @@ import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import { JwtHelperService } from "@auth0/angular-jwt"; import { JwtHelperService } from "@auth0/angular-jwt";
import { firstValueFrom, Observable, Subject, Subscription, throwError } from "rxjs"; import { BehaviorSubject, firstValueFrom, Observable, Subject, Subscription, throwError } from "rxjs";
import { catchError } from "rxjs/operators"; import { catchError } from "rxjs/operators";
import { AdminUpdateUserDTO } from "src/app/models/auth/admin-update-user.dto"; import { AdminUpdateUserDTO } from "src/app/models/auth/admin-update-user.dto";
import { AuthRoles } from "src/app/models/auth/auth-roles.enum"; import { AuthRoles } from "src/app/models/auth/auth-roles.enum";
@@ -23,8 +23,7 @@ import { OAuthDTO } from "../../models/auth/oauth.dto";
}) })
export class AuthService { export class AuthService {
private isLoggedIn!: boolean; isLoggedIn$ = new BehaviorSubject<boolean>(false);
isLoggedIn$ = new Subject<boolean>();
constructor( constructor(
private appsettings: SettingsService, private appsettings: SettingsService,
@@ -33,9 +32,6 @@ export class AuthService {
private jwtHelper: JwtHelperService, private jwtHelper: JwtHelperService,
private spinnerService: SpinnerService private spinnerService: SpinnerService
) { ) {
this.isLoggedIn$.subscribe(value => {
this.isLoggedIn = value;
});
} }
/* data requests */ /* data requests */
@@ -212,7 +208,7 @@ export class AuthService {
getDecodedToken(token: TokenDTO | undefined = undefined): { [key: string]: any } | null { getDecodedToken(token: TokenDTO | undefined = undefined): { [key: string]: any } | null {
if (token) { if (token) {
return this.jwtHelper.decodeToken(token.token); return this.jwtHelper.decodeToken(token.token);
} }
return this.jwtHelper.decodeToken(this.getToken().token); return this.jwtHelper.decodeToken(this.getToken().token);
@@ -279,16 +275,12 @@ export class AuthService {
return false; return false;
} }
if (this.isLoggedIn) { this.spinnerService.showSpinner();
this.spinnerService.showSpinner(); const resfreshedToken = await firstValueFrom(await this.refresh(token));
this.spinnerService.hideSpinner();
const resfreshedToken = await firstValueFrom(await this.refresh(token)); if (resfreshedToken) {
this.saveToken(resfreshedToken);
this.spinnerService.hideSpinner(); return true;
if (resfreshedToken) {
this.saveToken(resfreshedToken);
return true;
}
} }
return false; return false;

View File

@@ -4,18 +4,18 @@ import { Themes } from "src/app/models/view/themes.enum";
import { AuthService } from "../auth/auth.service"; import { AuthService } from "../auth/auth.service";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: "root"
}) })
export class ThemeService { export class ThemeService {
themeName: string = Themes.Default; themeName: string = Themes.Default;
sidebarWidth = '150px'; sidebarWidth = "150px";
isSidebarOpen = false; isSidebarOpen = false;
themeName$ = new BehaviorSubject<string>(Themes.Default); themeName$ = new BehaviorSubject<string>(Themes.Default);
isSidebarOpen$ = new BehaviorSubject<boolean>(true); isSidebarOpen$ = new BehaviorSubject<boolean>(true);
sidebarWidth$ = new BehaviorSubject<string>('175px'); sidebarWidth$ = new BehaviorSubject<string>("175px");
constructor( constructor(
private authService: AuthService private authService: AuthService
@@ -25,7 +25,7 @@ export class ThemeService {
}); });
this.isSidebarOpen$.subscribe(isSidebarOpen => { this.isSidebarOpen$.subscribe(isSidebarOpen => {
this.isSidebarOpen = isSidebarOpen; this.isSidebarOpen = isSidebarOpen;
this.sidebarWidth$.next(isSidebarOpen ? '175px' : '75px'); this.sidebarWidth$.next(isSidebarOpen ? "175px" : "75px");
}); });
this.sidebarWidth$.subscribe(sidebarWidth => { this.sidebarWidth$.subscribe(sidebarWidth => {
this.sidebarWidth = sidebarWidth; this.sidebarWidth = sidebarWidth;
@@ -63,20 +63,18 @@ export class ThemeService {
return; return;
} }
this.authService.isUserLoggedInAsync().then(result => { if (!this.authService.isLoggedIn$.value) {
if (!result) { localStorage.setItem(`default_themeName`, Themes.Default);
localStorage.setItem(`default_themeName`, Themes.Default); this.themeName$.next(Themes.Default);
this.themeName$.next(Themes.Default); }
}
const token = this.authService.getDecodedToken(); const token = this.authService.getDecodedToken();
const mail = this.authService.getEMailFromDecodedToken(token); const mail = this.authService.getEMailFromDecodedToken(token);
if (mail) { if (mail) {
localStorage.setItem(`${mail}_themeName`, name); localStorage.setItem(`${mail}_themeName`, name);
} }
localStorage.setItem(`default_themeName`, name); localStorage.setItem(`default_themeName`, name);
this.themeName$.next(name); this.themeName$.next(name);
});
} }
loadMenu() { loadMenu() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 948 B

After

Width:  |  Height:  |  Size: 69 KiB