Skip to content

Commit be0fcd8

Browse files
committed
fix: update emit events in CaptchaWidget and modify login confirmation logic
1 parent 416d807 commit be0fcd8

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

custom/CaptchaWidget.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
2-
2+
<div class="w-full flex justify-center items-center">
33
<div :id="props.meta.containerId"></div>
4-
4+
</div>
55
</template>
66

77
<script setup lang="ts">
@@ -22,16 +22,16 @@ const props = defineProps<Props>();
2222
2323
const token = ref(null);
2424
const emit = defineEmits(
25-
["update:allowLoginClick"]
25+
["update:disableLoginButton"]
2626
)
2727
2828
onMounted(() => {
2929
const fnName = props.meta.renderWidgetFunctionName;
30-
30+
emit("update:disableLoginButton", true);
3131
const renderFn = (window as any)[fnName];
3232
if (typeof renderFn === 'function') {
3333
renderFn(props.meta.containerId, props.meta.siteKey, (receivedToken: string) => {
34-
emit("update:allowLoginClick", true);
34+
emit("update:disableLoginButton", false);
3535
token.value = receivedToken;
3636
setJWT(receivedToken);
3737
});

index.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,31 @@ export default class CaptchaPlugin extends AdminForthPlugin {
4747

4848
const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation;
4949
const beforeLoginConfirmationArray = Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation];
50-
beforeLoginConfirmationArray.push(
50+
beforeLoginConfirmationArray.unshift(
5151
async({ extra }: { adminUser: AdminUser, response: IAdminForthHttpResponse, extra?: any} )=> {
52+
const rejectResult = {
53+
body:{
54+
allowedLogin: false,
55+
redirectTo: '/login',
56+
},
57+
ok: true
58+
};
59+
5260
if ( !extra || !extra.cookies ) {
53-
return {
54-
body:{
55-
allowedLogin: false,
56-
redirectTo: '/login',
57-
},
58-
ok: true
59-
}
61+
return rejectResult;
6062
}
6163
const cookies = extra.cookies;
6264
const token = cookies.find(
6365
(cookie) => cookie.key === `adminforth_${adapterName}_temporaryJWT`
6466
)?.value;
6567
if ( !token ) {
66-
return {
67-
body:{
68-
allowedLogin: false,
69-
redirectTo: '/login',
70-
},
71-
ok: true
72-
}
68+
return rejectResult;
7369
}
7470

7571
const ip = this.adminforth.auth.getClientIp(extra.headers);
7672
const validationResult = await this.options.captchaAdapter.validate(token, ip);
77-
console.log('Validation result:', validationResult);
78-
7973
if (!validationResult || !validationResult.success) {
80-
return {
81-
body:{
82-
allowedLogin: false,
83-
redirectTo: '/login',
84-
},
85-
ok: true
86-
}
74+
return rejectResult;
8775
}
8876
}
8977
);

0 commit comments

Comments
 (0)