frontend: enhance invalid role error messages in login components for clarity
This commit is contained in:
parent
48c0133504
commit
270fbc0e5e
@ -24,7 +24,11 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
@if (loginErrorMessage) {
|
@if (loginErrorMessage) {
|
||||||
<mat-error class="login-error">{{ loginErrorMessage }}</mat-error>
|
<mat-error class="login-error">{{ loginErrorMessage }}
|
||||||
|
@if (invalidRole) {
|
||||||
|
<a [routerLink]="'/login'">go to the home page</a>
|
||||||
|
}
|
||||||
|
</mat-error>
|
||||||
}
|
}
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<div class="signup-section">
|
<div class="signup-section">
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { FormGroup, Validators, FormsModule, ReactiveFormsModule, FormControl } from '@angular/forms';
|
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
import { MatCardModule } from '@angular/material/card';
|
||||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
import { MatInputModule } from '@angular/material/input';
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { AuthService } from '../../../services';
|
import { Router, RouterModule } from '@angular/router';
|
||||||
import { Router } from '@angular/router';
|
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
|
||||||
import { UserRole } from 'shared-meet-components';
|
import { UserRole } from 'shared-meet-components';
|
||||||
|
import { AuthService } from '../../../services';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ov-login',
|
selector: 'ov-login',
|
||||||
@ -20,7 +20,8 @@ import { UserRole } from 'shared-meet-components';
|
|||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
MatCardModule,
|
MatCardModule,
|
||||||
MatIconModule
|
MatIconModule,
|
||||||
|
RouterModule
|
||||||
],
|
],
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
styleUrl: './login.component.scss'
|
styleUrl: './login.component.scss'
|
||||||
@ -31,6 +32,7 @@ export class ConsoleLoginComponent {
|
|||||||
password: new FormControl('', [Validators.required, Validators.minLength(4)])
|
password: new FormControl('', [Validators.required, Validators.minLength(4)])
|
||||||
});
|
});
|
||||||
loginErrorMessage: string | undefined;
|
loginErrorMessage: string | undefined;
|
||||||
|
invalidRole = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
@ -49,8 +51,10 @@ export class ConsoleLoginComponent {
|
|||||||
// Check if the user has the expected role
|
// Check if the user has the expected role
|
||||||
const role = await this.authService.getUserRole();
|
const role = await this.authService.getUserRole();
|
||||||
if (role !== UserRole.ADMIN) {
|
if (role !== UserRole.ADMIN) {
|
||||||
this.authService.logout();
|
await this.authService.logout();
|
||||||
this.loginErrorMessage = 'Invalid username or password';
|
this.invalidRole = true;
|
||||||
|
this.loginErrorMessage =
|
||||||
|
'You have been authenticated as a user with insufficient permissions. Please log in with an admin account or';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,12 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@if (loginErrorMessage) {
|
@if (loginErrorMessage) {
|
||||||
<div class="loginError" id="login-error">{{ loginErrorMessage }}</div>
|
<div class="loginError" id="login-error">
|
||||||
|
{{ loginErrorMessage }}
|
||||||
|
@if (invalidRole) {
|
||||||
|
<a [routerLink]="'/console/login'">go to the admin console page</a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<button mat-button id="join-btn" type="submit" [disabled]="loginForm.invalid">Login</button>
|
<button mat-button id="join-btn" type="submit" [disabled]="loginForm.invalid">Login</button>
|
||||||
|
|||||||
@ -44,6 +44,11 @@ $formGap: 0.375rem;
|
|||||||
padding-right: 4px;
|
padding-right: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loginError a {
|
||||||
|
color: $loginError;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
import { NgClass } from '@angular/common';
|
import { NgClass } from '@angular/common';
|
||||||
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
import { MatButton } from '@angular/material/button';
|
import { MatButton } from '@angular/material/button';
|
||||||
import { MatIcon } from '@angular/material/icon';
|
import { MatIcon } from '@angular/material/icon';
|
||||||
import { MatToolbar } from '@angular/material/toolbar';
|
import { MatToolbar } from '@angular/material/toolbar';
|
||||||
import { MatTooltip } from '@angular/material/tooltip';
|
import { MatTooltip } from '@angular/material/tooltip';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
||||||
import { ContextService, AuthService } from '../../services/index';
|
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
|
||||||
import { UserRole } from 'shared-meet-components';
|
import { UserRole } from 'shared-meet-components';
|
||||||
|
import { AuthService, ContextService } from '../../services/index';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [MatToolbar, MatTooltip, MatIcon, FormsModule, ReactiveFormsModule, NgClass, MatButton],
|
imports: [MatToolbar, MatTooltip, MatIcon, FormsModule, ReactiveFormsModule, NgClass, MatButton, RouterModule],
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
styleUrl: './login.component.scss'
|
styleUrl: './login.component.scss'
|
||||||
})
|
})
|
||||||
@ -27,6 +27,7 @@ export class LoginComponent {
|
|||||||
password: new FormControl('', [Validators.required, Validators.minLength(4)])
|
password: new FormControl('', [Validators.required, Validators.minLength(4)])
|
||||||
});
|
});
|
||||||
loginErrorMessage: string | undefined;
|
loginErrorMessage: string | undefined;
|
||||||
|
invalidRole = false;
|
||||||
redirectTo = ''; // By default, redirect to RoomCreatorComponent
|
redirectTo = ''; // By default, redirect to RoomCreatorComponent
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -58,8 +59,10 @@ export class LoginComponent {
|
|||||||
// Check if the user has the expected role
|
// Check if the user has the expected role
|
||||||
const role = await this.authService.getUserRole();
|
const role = await this.authService.getUserRole();
|
||||||
if (role !== UserRole.USER) {
|
if (role !== UserRole.USER) {
|
||||||
this.authService.logout();
|
await this.authService.logout();
|
||||||
this.loginErrorMessage = 'Invalid username or password';
|
this.invalidRole = true;
|
||||||
|
this.loginErrorMessage =
|
||||||
|
'You have been authenticated as an admin, but admin users cannot join meetings. Please log in with a user account or';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user