mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: move tfa check to a seperate route
This commit is contained in:
3 files changed
+15
-14
No files matched your search
@@ -119,6 +119,16 @@ class UserSudoHandler extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UserTFAHandler extends Handler {
|
||||||
|
@param('q', Types.String)
|
||||||
|
async get({ }, q: string) {
|
||||||
|
let udoc = await user.getByUname('system', q);
|
||||||
|
udoc ||= await user.getByEmail('system', q);
|
||||||
|
if (!udoc) this.response.body = { tfa: false, authn: false };
|
||||||
|
else this.response.body = { tfa: udoc.tfa, authn: udoc.authn };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class UserWebauthnHandler extends Handler {
|
class UserWebauthnHandler extends Handler {
|
||||||
noCheckPermView = true;
|
noCheckPermView = true;
|
||||||
|
|
||||||
@@ -500,6 +510,7 @@ export async function apply(ctx: Context) {
|
|||||||
ctx.Route('user_login', '/login', UserLoginHandler);
|
ctx.Route('user_login', '/login', UserLoginHandler);
|
||||||
ctx.Route('user_oauth', '/oauth/:type', OauthHandler);
|
ctx.Route('user_oauth', '/oauth/:type', OauthHandler);
|
||||||
ctx.Route('user_sudo', '/user/sudo', UserSudoHandler, PRIV.PRIV_USER_PROFILE);
|
ctx.Route('user_sudo', '/user/sudo', UserSudoHandler, PRIV.PRIV_USER_PROFILE);
|
||||||
|
ctx.Route('user_tfa', '/user/tfa', UserTFAHandler);
|
||||||
ctx.Route('user_webauthn', '/user/webauthn', UserWebauthnHandler);
|
ctx.Route('user_webauthn', '/user/webauthn', UserWebauthnHandler);
|
||||||
ctx.Route('user_oauth_callback', '/oauth/:type/callback', OauthCallbackHandler);
|
ctx.Route('user_oauth_callback', '/oauth/:type/callback', OauthCallbackHandler);
|
||||||
ctx.Route('user_register', '/register', UserRegisterHandler, PRIV.PRIV_REGISTER_USER);
|
ctx.Route('user_register', '/register', UserRegisterHandler, PRIV.PRIV_REGISTER_USER);
|
||||||
@@ -523,8 +534,6 @@ export async function apply(ctx: Context) {
|
|||||||
['regat', 'Date!'],
|
['regat', 'Date!'],
|
||||||
['priv', 'Int!', 'User Privilege'],
|
['priv', 'Int!', 'User Privilege'],
|
||||||
['avatarUrl', 'String'],
|
['avatarUrl', 'String'],
|
||||||
['tfa', 'Boolean!'],
|
|
||||||
['authn', 'Boolean!'],
|
|
||||||
['displayName', 'String @if(perm: "PERM_VIEW_DISPLAYNAME")'],
|
['displayName', 'String @if(perm: "PERM_VIEW_DISPLAYNAME")'],
|
||||||
['rpInfo', 'JSONObject'],
|
['rpInfo', 'JSONObject'],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ const applyAuthDirective = (s) => mapSchema(s, {
|
|||||||
|
|
||||||
class ApiHandler extends Handler {
|
class ApiHandler extends Handler {
|
||||||
category = '#api';
|
category = '#api';
|
||||||
noCheckPermView = true;
|
// FIXME: adding PERM_VIEW check will break omnibar search
|
||||||
|
|
||||||
query(q: string, variables: any) {
|
query(q: string, variables: any) {
|
||||||
return graphql({
|
return graphql({
|
||||||
|
|||||||
@@ -74,19 +74,11 @@ export default new AutoloadPage('user_verify', () => {
|
|||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const form = ev.currentTarget.form;
|
const form = ev.currentTarget.form;
|
||||||
const uname = $(form).find('[name="uname"]').val() as string;
|
const uname = $(form).find('[name="uname"]').val() as string;
|
||||||
const info = await api(gql`
|
if (!uname) {
|
||||||
uname: user(uname:${uname}){
|
form.elements.namedItem('uname')?.focus();
|
||||||
tfa authn
|
|
||||||
}
|
|
||||||
mail: user(mail:${uname}){
|
|
||||||
tfa authn
|
|
||||||
}
|
|
||||||
`, ['data']);
|
|
||||||
if (!info.uname && !info.mail) {
|
|
||||||
Notification.error(i18n('User not found.'));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { authn, tfa } = info.uname || info.mail;
|
const { authn, tfa } = await request.get('/user/tfa', { q: uname });
|
||||||
if (authn || tfa) {
|
if (authn || tfa) {
|
||||||
const handleKeyDown = (event) => {
|
const handleKeyDown = (event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
|
|||||||
Reference in new issue
Block a user