mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-15 09:42:56 -07:00
Fixed the issue where the sidebar nav doesn't load
This commit is contained in:
parent
9f5c19ecf6
commit
e141743f08
4 changed files with 18 additions and 21 deletions
|
@ -167,8 +167,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div [ngClass]="user.name && roleClass()">
|
<div>
|
||||||
<app-my-nav [showNav]="showNav" [isAdmin]="isAdmin" [applicationName]="applicationName" [username]="user.name" (logoutClick)="logOut();"
|
<app-my-nav [showNav]="showNav" [isAdmin]="isAdmin" [applicationName]="applicationName" [username]="username" (logoutClick)="logOut();"
|
||||||
(themeChange)="onSetTheme($event)"></app-my-nav>
|
(themeChange)="onSetTheme($event)"></app-my-nav>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ export class AppComponent implements OnInit {
|
||||||
public voteEnabled = false;
|
public voteEnabled = false;
|
||||||
public applicationName: string = "Ombi"
|
public applicationName: string = "Ombi"
|
||||||
public isAdmin: boolean;
|
public isAdmin: boolean;
|
||||||
|
public username: string;
|
||||||
|
|
||||||
private checkedForUpdate: boolean;
|
private checkedForUpdate: boolean;
|
||||||
|
|
||||||
|
@ -86,6 +87,9 @@ export class AppComponent implements OnInit {
|
||||||
this.currentUrl = event.url;
|
this.currentUrl = event.url;
|
||||||
if (event instanceof NavigationStart) {
|
if (event instanceof NavigationStart) {
|
||||||
this.user = this.authService.claims();
|
this.user = this.authService.claims();
|
||||||
|
if(this.user && this.user.username) {
|
||||||
|
this.username = this.user.username;
|
||||||
|
}
|
||||||
this.isAdmin = this.authService.hasRole("admin");
|
this.isAdmin = this.authService.hasRole("admin");
|
||||||
this.showNav = this.authService.loggedIn();
|
this.showNav = this.authService.loggedIn();
|
||||||
|
|
||||||
|
@ -101,17 +105,6 @@ export class AppComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public roleClass() {
|
|
||||||
if (this.user) {
|
|
||||||
if (this.user.roles.some(r => r === "Admin")) {
|
|
||||||
return "adminUser";
|
|
||||||
} else if (this.user.roles.some(r => r === "PowerUser")) {
|
|
||||||
return "powerUser";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "user";
|
|
||||||
}
|
|
||||||
|
|
||||||
public openMobileApp(event: any) {
|
public openMobileApp(event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (!this.customizationSettings.applicationUrl) {
|
if (!this.customizationSettings.applicationUrl) {
|
||||||
|
|
|
@ -11,4 +11,5 @@ export interface IUserLogin {
|
||||||
export interface ILocalUser {
|
export interface ILocalUser {
|
||||||
roles: string[];
|
roles: string[];
|
||||||
name: string;
|
name: string;
|
||||||
|
username:string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,20 +10,20 @@ import { ILocalUser, IUserLogin } from "./IUserLogin";
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService extends ServiceHelpers {
|
export class AuthService extends ServiceHelpers {
|
||||||
|
|
||||||
constructor(http: HttpClient, @Inject(APP_BASE_HREF) href:string, private jwtHelperService: JwtHelperService) {
|
constructor(http: HttpClient, @Inject(APP_BASE_HREF) href: string, private jwtHelperService: JwtHelperService) {
|
||||||
super(http, "/api/v1/token", href);
|
super(http, "/api/v1/token", href);
|
||||||
}
|
}
|
||||||
|
|
||||||
public login(login: IUserLogin): Observable<any> {
|
public login(login: IUserLogin): Observable<any> {
|
||||||
return this.http.post(`${this.url}/`, JSON.stringify(login), {headers: this.headers});
|
return this.http.post(`${this.url}/`, JSON.stringify(login), { headers: this.headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
public oAuth(pin: number): Observable<any> {
|
public oAuth(pin: number): Observable<any> {
|
||||||
return this.http.get<any>(`${this.url}/${pin}`, {headers: this.headers});
|
return this.http.get<any>(`${this.url}/${pin}`, { headers: this.headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
public requiresPassword(login: IUserLogin): Observable<boolean> {
|
public requiresPassword(login: IUserLogin): Observable<boolean> {
|
||||||
return this.http.post<boolean>(`${this.url}/requirePassword`, JSON.stringify(login), {headers: this.headers});
|
return this.http.post<boolean>(`${this.url}/requirePassword`, JSON.stringify(login), { headers: this.headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
public loggedIn() {
|
public loggedIn() {
|
||||||
|
@ -49,17 +49,20 @@ export class AuthService extends ServiceHelpers {
|
||||||
|
|
||||||
const u = { name, roles: [] as string[] };
|
const u = { name, roles: [] as string[] };
|
||||||
if (roles instanceof Array) {
|
if (roles instanceof Array) {
|
||||||
u.roles = roles;
|
u.roles = roles;
|
||||||
} else {
|
} else {
|
||||||
u.roles.push(roles);
|
u.roles.push(roles);
|
||||||
}
|
}
|
||||||
return <ILocalUser> u;
|
return <ILocalUser>u;
|
||||||
}
|
}
|
||||||
return <ILocalUser> { };
|
return <ILocalUser>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasRole(role: string): boolean {
|
public hasRole(role: string): boolean {
|
||||||
return this.claims().roles.some(r => r.toUpperCase() === role.toUpperCase());
|
if (this.claims().roles) {
|
||||||
|
return this.claims().roles.some(r => r.toUpperCase() === role.toUpperCase());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public logout() {
|
public logout() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue