Compare commits

..

No commits in common. "prototype" and "master" have entirely different histories.

27 changed files with 18 additions and 275 deletions

View File

@ -8,9 +8,6 @@ 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,32 +29,17 @@ export class SidebarComponent implements OnInit, OnChanges {
async setMenu(isSidebarOpen: boolean) {
this.menuItems = [];
this.menuItems = [
{ label: isSidebarOpen ? this.translateService.instant('sidebar.home') : '', icon: 'pi pi-home', routerLink: 'home' },
{ label: isSidebarOpen ? this.translateService.instant('sidebar.home') : '', icon: 'pi pi-th-large', 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,5 +1,4 @@
export enum AuthRoles {
Supporter = 0,
User = 1,
Admin = 2
Normal = 0,
Admin = 1
}

View File

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

View File

@ -33,8 +33,7 @@ export class AuthUserComponent implements OnInit {
isEditingNew: boolean = false;
authRoles = [
{ label: AuthRoles[AuthRoles.User].toString(), value: AuthRoles.User },
{ label: AuthRoles[AuthRoles.Supporter].toString(), value: AuthRoles.Supporter },
{ label: AuthRoles[AuthRoles.Normal].toString(), value: AuthRoles.Normal },
{ label: AuthRoles[AuthRoles.Admin].toString(), value: AuthRoles.Admin }
]
@ -44,7 +43,7 @@ export class AuthUserComponent implements OnInit {
lastName: "",
eMail: "",
password: "",
authRole: AuthRoles.User
authRole: AuthRoles.Normal
};
isFirstNameInvalid: boolean = false;
@ -213,7 +212,6 @@ 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;
@ -221,10 +219,7 @@ 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.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) {
} 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 }));
}
@ -309,6 +304,7 @@ 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,13 +27,11 @@ export class AuthGuard implements CanActivate {
}
const role = route.data.role;
if (role == null) {
return false;
}
if (!await this.authService.hasUserPermission(role)) {
this.router.navigate(['/home']);
return false;
if (role) {
if (!await this.authService.hasUserPermission(role)) {
this.router.navigate(['/home']);
return false;
}
}
return true;
}

View File

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

View File

@ -1,25 +0,0 @@
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

@ -1,15 +0,0 @@
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

@ -1,13 +0,0 @@
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

@ -1,19 +0,0 @@
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

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

View File

@ -1,25 +0,0 @@
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

@ -1,16 +0,0 @@
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

@ -1,13 +0,0 @@
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

@ -1,19 +0,0 @@
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

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

View File

@ -1,25 +0,0 @@
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

@ -1,15 +0,0 @@
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

@ -1,13 +0,0 @@
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

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

View File

@ -5,10 +5,7 @@
"logout": "Ausloggen"
},
"sidebar": {
"home": "Dashboard",
"host": "Hosts",
"gameserver": "Server",
"support": "Tickets",
"home": "Home",
"config": "Konfiguration",
"auth_user_list": "Benutzer"
},
@ -67,8 +64,6 @@
"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",
@ -87,7 +82,7 @@
}
},
"auth": {
"header": "GSWI",
"header": "App",
"login": {},
"register": {},
"forgot_password": {

View File

@ -5,10 +5,7 @@
"logout": "Logout"
},
"sidebar": {
"home": "Dashboard",
"host": "Hosts",
"gameserver": "Server",
"support": "Tickets",
"home": "Home",
"config": "Configuration",
"auth_user_list": "User"
},
@ -67,8 +64,6 @@
"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",