Improved permissions
This commit is contained in:
parent
8717491d57
commit
167af90f20
@ -10,7 +10,7 @@ const routes: Routes = [
|
||||
{ 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.Support } },
|
||||
{ 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) },
|
||||
|
@ -38,7 +38,7 @@ export class SidebarComponent implements OnInit, OnChanges {
|
||||
);
|
||||
}
|
||||
|
||||
if (await this.authService.hasUserPermission(AuthRoles.Support) && !await this.authService.hasUserPermission(AuthRoles.Admin)) {
|
||||
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' },
|
||||
);
|
||||
|
@ -1,5 +1,5 @@
|
||||
export enum AuthRoles {
|
||||
User = 0,
|
||||
Support = 1,
|
||||
Supporter = 0,
|
||||
User = 1,
|
||||
Admin = 2
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
export enum RegisterErrorMessages {
|
||||
InvalidEMail = "Invalid E-Mail",
|
||||
UserAlreadyExists = "User already exists",
|
||||
ConfirmationFailed = "Confirmation failed",
|
||||
}
|
@ -34,6 +34,7 @@ export class AuthUserComponent implements OnInit {
|
||||
|
||||
authRoles = [
|
||||
{ label: AuthRoles[AuthRoles.User].toString(), value: AuthRoles.User },
|
||||
{ label: AuthRoles[AuthRoles.Supporter].toString(), value: AuthRoles.Supporter },
|
||||
{ label: AuthRoles[AuthRoles.Admin].toString(), value: AuthRoles.Admin }
|
||||
]
|
||||
|
||||
@ -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();
|
||||
|
@ -27,12 +27,14 @@ export class AuthGuard implements CanActivate {
|
||||
}
|
||||
|
||||
const role = route.data.role;
|
||||
if (role) {
|
||||
if (role == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!await this.authService.hasUserPermission(role)) {
|
||||
this.router.navigate(['/home']);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ 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();
|
||||
|
@ -67,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",
|
||||
|
@ -67,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",
|
||||
|
Reference in New Issue
Block a user