lock
This commit is contained in:
parent
ee8c8423e7
commit
21a5ebda0a
@ -20,4 +20,17 @@ class AuthController(
|
||||
return ResponseEntity.ok(currentUser)
|
||||
}
|
||||
|
||||
data class IsAdminResponse(
|
||||
val isAdmin: Boolean
|
||||
)
|
||||
|
||||
@GetMapping("/auth/admin", produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
fun isAdmin(): ResponseEntity<IsAdminResponse> {
|
||||
if(!this.authService.isLoggedIn())
|
||||
return ResponseEntity.status(401).build()
|
||||
|
||||
val isAdmin = this.authService.isAdmin()
|
||||
return ResponseEntity.ok(IsAdminResponse(isAdmin))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@ import {HttpClient} from "@angular/common/http";
|
||||
import {environment} from "../../environments/environment";
|
||||
import {NgIf} from "@angular/common";
|
||||
import {CuteLoadingComponent} from "../../corelib/components/cute-loading/cute-loading.component";
|
||||
import {UserService} from "../../corelib/service/user.service";
|
||||
import {Router} from "@angular/router";
|
||||
|
||||
interface CreateMetabaseUserResponse {
|
||||
email: string;
|
||||
@ -29,11 +31,19 @@ export class MetabaseComponent {
|
||||
user: GetMetabaseUserResponse | null = null;
|
||||
createResponse: CreateMetabaseUserResponse | null = null;
|
||||
|
||||
constructor(private httpClient: HttpClient) { }
|
||||
constructor(private httpClient: HttpClient, private userService: UserService, private router: Router) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.userService.isAdmin().then(isAdmin => {
|
||||
if (!isAdmin) {
|
||||
this.router.navigate(['/']);
|
||||
} else {
|
||||
this.getUser();
|
||||
}
|
||||
}).catch(() => {
|
||||
this.router.navigate(['/']);
|
||||
});
|
||||
}
|
||||
|
||||
resetPassword() {
|
||||
this.httpClient.get<CreateMetabaseUserResponse>(`${environment.apiUrl}/metabase/reset`, { withCredentials: true })
|
||||
|
||||
@ -7,6 +7,10 @@ interface UserInfo {
|
||||
username: string;
|
||||
}
|
||||
|
||||
interface IsAdminResponse {
|
||||
isAdmin: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* This stuff gets saved to localStorage ONLY.
|
||||
*/
|
||||
@ -47,6 +51,20 @@ export class UserService {
|
||||
return this.currentUser !== null;
|
||||
}
|
||||
|
||||
public isAdmin(): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.httpClient.get<IsAdminResponse>(`${environment.apiUrl}/auth/admin`)
|
||||
.subscribe({
|
||||
next: (isAdmin) => {
|
||||
resolve(isAdmin.isAdmin);
|
||||
},
|
||||
error: () => {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public updateUser(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.httpClient.get<UserInfo>(`${environment.apiUrl}/auth`)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user