lock
This commit is contained in:
parent
ee8c8423e7
commit
21a5ebda0a
@ -20,4 +20,17 @@ class AuthController(
|
|||||||
return ResponseEntity.ok(currentUser)
|
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 {environment} from "../../environments/environment";
|
||||||
import {NgIf} from "@angular/common";
|
import {NgIf} from "@angular/common";
|
||||||
import {CuteLoadingComponent} from "../../corelib/components/cute-loading/cute-loading.component";
|
import {CuteLoadingComponent} from "../../corelib/components/cute-loading/cute-loading.component";
|
||||||
|
import {UserService} from "../../corelib/service/user.service";
|
||||||
|
import {Router} from "@angular/router";
|
||||||
|
|
||||||
interface CreateMetabaseUserResponse {
|
interface CreateMetabaseUserResponse {
|
||||||
email: string;
|
email: string;
|
||||||
@ -29,10 +31,18 @@ export class MetabaseComponent {
|
|||||||
user: GetMetabaseUserResponse | null = null;
|
user: GetMetabaseUserResponse | null = null;
|
||||||
createResponse: CreateMetabaseUserResponse | null = null;
|
createResponse: CreateMetabaseUserResponse | null = null;
|
||||||
|
|
||||||
constructor(private httpClient: HttpClient) { }
|
constructor(private httpClient: HttpClient, private userService: UserService, private router: Router) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.getUser();
|
this.userService.isAdmin().then(isAdmin => {
|
||||||
|
if (!isAdmin) {
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
} else {
|
||||||
|
this.getUser();
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resetPassword() {
|
resetPassword() {
|
||||||
|
|||||||
@ -7,6 +7,10 @@ interface UserInfo {
|
|||||||
username: string;
|
username: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IsAdminResponse {
|
||||||
|
isAdmin: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This stuff gets saved to localStorage ONLY.
|
* This stuff gets saved to localStorage ONLY.
|
||||||
*/
|
*/
|
||||||
@ -47,6 +51,20 @@ export class UserService {
|
|||||||
return this.currentUser !== null;
|
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> {
|
public updateUser(): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.httpClient.get<UserInfo>(`${environment.apiUrl}/auth`)
|
this.httpClient.get<UserInfo>(`${environment.apiUrl}/auth`)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user