Compare commits

..

2 Commits

Author SHA1 Message Date
167af90f20 Improved permissions 2022-02-21 18:27:20 +01:00
8717491d57 Added default routes 2022-02-21 17:11:26 +01:00
27 changed files with 275 additions and 18 deletions

View File

@ -8,6 +8,9 @@ import { AuthGuard } from './modules/shared/guards/auth/auth.guard';
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent, pathMatch: 'full' },
{ path: 'host', loadChildren: () => import('./modules/view/host/host.module').then(m => m.HostModule), canActivate: [AuthGuard], data: { role: AuthRoles.Admin } },
{ path: 'gameserver', loadChildren: () => import('./modules/view/gameserver/gameserver.module').then(m => m.GameserverModule), canActivate: [AuthGuard], data: { role: AuthRoles.User } },
{ path: 'support', loadChildren: () => import('./modules/view/support/support.module').then(m => m.SupportModule), canActivate: [AuthGuard], data: { role: AuthRoles.Supporter } },
{ path: 'change-password', loadChildren: () => import('./modules/view/change-password/change-password.module').then(m => m.ChangePasswordModule), canActivate: [AuthGuard] },
{ path: 'user-settings', loadChildren: () => import('./modules/view/user-settings/user-settings.module').then(m => m.UserSettingsModule), canActivate: [AuthGuard] },
{ path: 'auth', loadChildren: () => import('./modules/auth/auth.module').then(m => m.AuthModule) },

View File

@ -29,17 +29,32 @@ export class SidebarComponent implements OnInit, OnChanges {
async setMenu(isSidebarOpen: boolean) {
this.menuItems = [];
this.menuItems = [
{ label: isSidebarOpen ? this.translateService.instant('sidebar.home') : '', icon: 'pi pi-th-large', routerLink: 'home' },
{ label: isSidebarOpen ? this.translateService.instant('sidebar.home') : '', icon: 'pi pi-home', routerLink: 'home' },
];
if (await this.authService.hasUserPermission(AuthRoles.User) && !await this.authService.hasUserPermission(AuthRoles.Admin)) {
this.menuItems.push(
{ label: isSidebarOpen ? this.translateService.instant('sidebar.gameserver') : '', icon: 'pi pi-desktop', routerLink: 'gameserver' },
);
}
if (await this.authService.hasUserPermission(AuthRoles.Supporter) && !await this.authService.hasUserPermission(AuthRoles.Admin)) {
this.menuItems.push(
{ label: isSidebarOpen ? this.translateService.instant('sidebar.support') : '', icon: 'pi pi-ticket', routerLink: 'support' },
);
}
if (await this.authService.hasUserPermission(AuthRoles.Admin)) {
this.menuItems.push(
{ label: isSidebarOpen ? this.translateService.instant('sidebar.host') : '', icon: 'pi pi-sitemap', routerLink: 'host' },
{ label: isSidebarOpen ? this.translateService.instant('sidebar.gameserver') : '', icon: 'pi pi-desktop', routerLink: 'gameserver' },
{ label: isSidebarOpen ? this.translateService.instant('sidebar.support') : '', icon: 'pi pi-ticket', routerLink: 'support' },
{ separator: true },
{ label: isSidebarOpen ? this.translateService.instant('sidebar.config') : '', icon: 'pi pi-cog', routerLink: '/admin/settings' },
{ label: isSidebarOpen ? this.translateService.instant('sidebar.auth_user_list') : '', icon: 'pi pi-user-edit', routerLink: '/admin/users' },
);
this.menuItems = this.menuItems.slice();
}
this.menuItems = this.menuItems.slice();
}
async ngOnChanges(changes: SimpleChanges): Promise<void> {

View File

@ -1,4 +1,5 @@
export enum AuthRoles {
Normal = 0,
Admin = 1
Supporter = 0,
User = 1,
Admin = 2
}

View File

@ -1,4 +1,5 @@
export enum RegisterErrorMessages {
InvalidEMail = "Invalid E-Mail",
UserAlreadyExists = "User already exists",
ConfirmationFailed = "Confirmation failed",
}

View File

@ -33,7 +33,8 @@ export class AuthUserComponent implements OnInit {
isEditingNew: boolean = false;
authRoles = [
{ label: AuthRoles[AuthRoles.Normal].toString(), value: AuthRoles.Normal },
{ label: AuthRoles[AuthRoles.User].toString(), value: AuthRoles.User },
{ label: AuthRoles[AuthRoles.Supporter].toString(), value: AuthRoles.Supporter },
{ label: AuthRoles[AuthRoles.Admin].toString(), value: AuthRoles.Admin }
]
@ -43,7 +44,7 @@ export class AuthUserComponent implements OnInit {
lastName: "",
eMail: "",
password: "",
authRole: AuthRoles.Normal
authRole: AuthRoles.User
};
isFirstNameInvalid: boolean = false;
@ -212,6 +213,7 @@ export class AuthUserComponent implements OnInit {
this.spinnerService.showSpinner();
this.authService.register(newUser).pipe(catchError(error => {
this.spinnerService.hideSpinner();
console.log(error, error.error);
if (error.error !== null) {
const err: ErrorDTO = error.error;
@ -219,7 +221,10 @@ export class AuthUserComponent implements OnInit {
if (err.errorCode === ServiceErrorCode.InvalidData && err.message === RegisterErrorMessages.InvalidEMail) {
this.isEMailInvalid = true;
this.toastService.error(this.translate.instant('admin.auth_users.message.invalid_email'), this.translate.instant('admin.auth_users.message.invalid_email_d', { eMail: newUser.eMail }));
} else if (err.errorCode === ServiceErrorCode.InvalidUser && err.message === RegisterErrorMessages.UserAlreadyExists) {
} else if (err.errorCode === ServiceErrorCode.MailError && err.message === RegisterErrorMessages.ConfirmationFailed) {
this.isEMailInvalid = true;
this.toastService.error(this.translate.instant('admin.auth_users.message.confirmation_failed'), this.translate.instant('admin.auth_users.message.confirmation_failed_d', { eMail: newUser.eMail }));
}else if (err.errorCode === ServiceErrorCode.InvalidUser && err.message === RegisterErrorMessages.UserAlreadyExists) {
this.isEMailInvalid = true;
this.toastService.error(this.translate.instant('admin.auth_users.message.user_already_exists'), this.translate.instant('admin.auth_users.message.user_already_exists_d', { eMail: newUser.eMail }));
}
@ -304,7 +309,6 @@ export class AuthUserComponent implements OnInit {
addUser(table: Table) {
const newUser = JSON.parse(JSON.stringify(this.newUserTemplate));
newUser.id = Math.max.apply(Math, this.users.map(function (u) { return u.id; })) + 1;
console.log(newUser);
this.users.push(newUser);
this.triggerUserChangeDetection();

View File

@ -27,11 +27,13 @@ export class AuthGuard implements CanActivate {
}
const role = route.data.role;
if (role) {
if (!await this.authService.hasUserPermission(role)) {
this.router.navigate(['/home']);
return false;
}
if (role == null) {
return false;
}
if (!await this.authService.hasUserPermission(role)) {
this.router.navigate(['/home']);
return false;
}
return true;
}

View File

@ -0,0 +1 @@
<p>gameserver works!</p>

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { GameserverComponent } from './gameserver.component';
describe('GameserverComponent', () => {
let component: GameserverComponent;
let fixture: ComponentFixture<GameserverComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ GameserverComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(GameserverComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'gswi-gameserver',
templateUrl: './gameserver.component.html',
styleUrls: ['./gameserver.component.scss']
})
export class GameserverComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

View File

@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { GameserverComponent } from './components/gameserver/gameserver.component';
const routes: Routes = [
{ path: '', component: GameserverComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class GameserverRoutingModule { }

View File

@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { GameserverComponent } from './components/gameserver/gameserver.component';
import { GameserverRoutingModule } from './gameserver-routing.module';
import { SharedModule } from '../../shared/shared.module';
@NgModule({
declarations: [
GameserverComponent
],
imports: [
CommonModule,
GameserverRoutingModule,
SharedModule
]
})
export class GameserverModule { }

View File

@ -0,0 +1 @@
<p>host works!</p>

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HostComponent } from './host.component';
describe('HostComponent', () => {
let component: HostComponent;
let fixture: ComponentFixture<HostComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ HostComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(HostComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,16 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'gswi-host',
templateUrl: './host.component.html',
styleUrls: ['./host.component.scss']
})
export class HostComponent implements OnInit {
constructor() { }
ngOnInit(): void {
console.log('hello');
}
}

View File

@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HostComponent } from './components/host/host.component';
const routes: Routes = [
{ path: '', component: HostComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class HostRoutingModule { }

View File

@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HostComponent } from './components/host/host.component';
import { HostRoutingModule } from './host-routing.module';
import { SharedModule } from '../../shared/shared.module';
@NgModule({
declarations: [
HostComponent
],
imports: [
CommonModule,
HostRoutingModule,
SharedModule
]
})
export class HostModule { }

View File

@ -0,0 +1 @@
<p>support works!</p>

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SupportComponent } from './support.component';
describe('SupportComponent', () => {
let component: SupportComponent;
let fixture: ComponentFixture<SupportComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SupportComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(SupportComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'gswi-support',
templateUrl: './support.component.html',
styleUrls: ['./support.component.scss']
})
export class SupportComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

View File

@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SupportComponent } from './components/support/support.component';
const routes: Routes = [
{ path: '', component: SupportComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class SupportRoutingModule { }

View File

@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SupportComponent } from './components/support/support.component';
import { SupportRoutingModule } from './support-routing.module';
import { SharedModule } from '../../shared/shared.module';
@NgModule({
declarations: [
SupportComponent
],
imports: [
CommonModule,
SupportRoutingModule,
SharedModule
]
})
export class SupportModule { }

View File

@ -226,11 +226,12 @@ export class AuthService {
}
async hasUserPermission(role: AuthRoles): Promise<boolean> {
if (!role || !await this.isUserLoggedInAsync()) {
if (role == null || !await this.isUserLoggedInAsync()) {
return false;
}
const token = this.getDecodedToken();
return token['http://schemas.microsoft.com/ws/2008/06/identity/claims/role'] === AuthRoles[role];
const roleId: number = +AuthRoles[token['http://schemas.microsoft.com/ws/2008/06/identity/claims/role']];
return roleId >= +role;
}
getEMailFromDecodedToken(token: string): string {

View File

@ -5,7 +5,10 @@
"logout": "Ausloggen"
},
"sidebar": {
"home": "Home",
"home": "Dashboard",
"host": "Hosts",
"gameserver": "Server",
"support": "Tickets",
"config": "Konfiguration",
"auth_user_list": "Benutzer"
},
@ -64,6 +67,8 @@
"message": {
"invalid_email": "Ungültige E-Mail",
"invalid_email_d": "Die E-Mail {{eMail}} ist nicht gültig!",
"confirmation_failed": "Bestätigung fehlgeschlagen",
"confirmation_failed_d": "Bestätigung des Benutzers {{eMail}} fehlgeschlagen!",
"user_already_exists": "Benutzer existiert bereits",
"user_already_exists_d": "Der Benutzer {{eMail}} existiert bereits!",
"user_added": "Benutzer hinzugefügt",
@ -82,7 +87,7 @@
}
},
"auth": {
"header": "App",
"header": "GSWI",
"login": {},
"register": {},
"forgot_password": {

View File

@ -5,7 +5,10 @@
"logout": "Logout"
},
"sidebar": {
"home": "Home",
"home": "Dashboard",
"host": "Hosts",
"gameserver": "Server",
"support": "Tickets",
"config": "Configuration",
"auth_user_list": "User"
},
@ -64,6 +67,8 @@
"message": {
"invalid_email": "Invalid E-Mail",
"invalid_email_d": "The e-mail {{eMail}} is not valid!",
"confirmation_failed": "Confirmation failed",
"confirmation_failed_d": "Confirmation of user {{eMail}} failed!",
"user_already_exists": "User already exists",
"user_already_exists_d": "The user {{eMail}} already exists!",
"user_added": "User added",