Added endpoint for checking if user is an admin
This commit is contained in:
parent
1491e2b6f3
commit
c347a10e9f
@ -88,5 +88,9 @@ namespace api {
|
|||||||
cbk(dto::Responses::get_badreq_res("Validation error"));
|
cbk(dto::Responses::get_badreq_res("Validation error"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void admin::is_admin(req_type, cbk_type cbk) {
|
||||||
|
cbk(dto::Responses::get_success_res());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
@ -24,6 +24,7 @@ public:
|
|||||||
METHOD_ADD(admin::logout, "/logout", drogon::Post, "Login", "Admin");
|
METHOD_ADD(admin::logout, "/logout", drogon::Post, "Login", "Admin");
|
||||||
METHOD_ADD(admin::delete_user, "/delete", drogon::Post, "Login", "Admin");
|
METHOD_ADD(admin::delete_user, "/delete", drogon::Post, "Login", "Admin");
|
||||||
METHOD_ADD(admin::disable_2fa, "/disable_2fa", drogon::Post, "Login", "Admin");
|
METHOD_ADD(admin::disable_2fa, "/disable_2fa", drogon::Post, "Login", "Admin");
|
||||||
|
METHOD_ADD(admin::is_admin, "/is_admin", drogon::Get, "Login", "Admin");
|
||||||
METHOD_LIST_END
|
METHOD_LIST_END
|
||||||
|
|
||||||
void users(req_type, cbk_type);
|
void users(req_type, cbk_type);
|
||||||
@ -31,6 +32,7 @@ public:
|
|||||||
void logout(req_type, cbk_type);
|
void logout(req_type, cbk_type);
|
||||||
void delete_user(req_type, cbk_type);
|
void delete_user(req_type, cbk_type);
|
||||||
void disable_2fa(req_type, cbk_type);
|
void disable_2fa(req_type, cbk_type);
|
||||||
|
void is_admin(req_type, cbk_type);
|
||||||
};
|
};
|
||||||
|
|
||||||
class auth : public drogon::HttpController<auth> {
|
class auth : public drogon::HttpController<auth> {
|
||||||
|
@ -5,6 +5,7 @@ import { useRouter, RouterLink } from 'vue-router';
|
|||||||
import type { TokenInjectType } from '@/api';
|
import type { TokenInjectType } from '@/api';
|
||||||
import { useMessage, NMenu, NPageHeader, NIcon } from 'naive-ui';
|
import { useMessage, NMenu, NPageHeader, NIcon } from 'naive-ui';
|
||||||
import { BareMetalServer02 } from '@vicons/carbon';
|
import { BareMetalServer02 } from '@vicons/carbon';
|
||||||
|
import { is_admin } from '@/api/admin';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
@ -69,6 +70,19 @@ const menuOptions: MenuOption[] = [
|
|||||||
key: 'login'
|
key: 'login'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (await is_admin(jwt.value ?? ''))
|
||||||
|
menuOptions.unshift({
|
||||||
|
label: () =>
|
||||||
|
h(
|
||||||
|
RouterLink,
|
||||||
|
{
|
||||||
|
to: '/admin'
|
||||||
|
},
|
||||||
|
{ default: () => 'Admin' }
|
||||||
|
),
|
||||||
|
key: 'admin'
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import type { Requests, Responses } from '@/dto';
|
import type { Requests, Responses } from '@/dto';
|
||||||
import { UserRole, get_token, post_token } from './base';
|
import { UserRole, get_token, post_token, isErrorResponse } from './base';
|
||||||
|
|
||||||
export const get_users = (token: string): Promise<Responses.GetUsers> =>
|
export const get_users = (token: string): Promise<Responses.GetUsers> =>
|
||||||
get_token('/api/admin/users', token);
|
get_token('/api/admin/users', token);
|
||||||
@ -53,3 +53,6 @@ export const disable_tfa = (
|
|||||||
},
|
},
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const is_admin = async (token: string): Promise<boolean> =>
|
||||||
|
!isErrorResponse(await get_token('/api/admin/is_admin', token));
|
||||||
|
Loading…
Reference in New Issue
Block a user