@adminforth/login-captcha 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.log CHANGED
@@ -7,5 +7,5 @@ custom/
7
7
  custom/CaptchaWidget.vue
8
8
  custom/tsconfig.json
9
9
 
10
- sent 1,753 bytes received 58 bytes 3,622.00 bytes/sec
11
- total size is 1,536 speedup is 0.85
10
+ sent 1,863 bytes received 58 bytes 3,842.00 bytes/sec
11
+ total size is 1,646 speedup is 0.86
@@ -1,7 +1,7 @@
1
1
  <template>
2
-
2
+ <div class="w-full flex justify-center items-center">
3
3
  <div :id="props.meta.containerId"></div>
4
-
4
+ </div>
5
5
  </template>
6
6
 
7
7
  <script setup lang="ts">
@@ -22,16 +22,16 @@ const props = defineProps<Props>();
22
22
 
23
23
  const token = ref(null);
24
24
  const emit = defineEmits(
25
- ["update:allowLoginClick"]
25
+ ["update:disableLoginButton"]
26
26
  )
27
27
 
28
28
  onMounted(() => {
29
29
  const fnName = props.meta.renderWidgetFunctionName;
30
-
30
+ emit("update:disableLoginButton", true);
31
31
  const renderFn = (window as any)[fnName];
32
32
  if (typeof renderFn === 'function') {
33
33
  renderFn(props.meta.containerId, props.meta.siteKey, (receivedToken: string) => {
34
- emit("update:allowLoginClick", true);
34
+ emit("update:disableLoginButton", false);
35
35
  token.value = receivedToken;
36
36
  setJWT(receivedToken);
37
37
  });
@@ -1,7 +1,7 @@
1
1
  <template>
2
-
2
+ <div class="w-full flex justify-center items-center">
3
3
  <div :id="props.meta.containerId"></div>
4
-
4
+ </div>
5
5
  </template>
6
6
 
7
7
  <script setup lang="ts">
@@ -22,16 +22,16 @@ const props = defineProps<Props>();
22
22
 
23
23
  const token = ref(null);
24
24
  const emit = defineEmits(
25
- ["update:allowLoginClick"]
25
+ ["update:disableLoginButton"]
26
26
  )
27
27
 
28
28
  onMounted(() => {
29
29
  const fnName = props.meta.renderWidgetFunctionName;
30
-
30
+ emit("update:disableLoginButton", true);
31
31
  const renderFn = (window as any)[fnName];
32
32
  if (typeof renderFn === 'function') {
33
33
  renderFn(props.meta.containerId, props.meta.siteKey, (receivedToken: string) => {
34
- emit("update:allowLoginClick", true);
34
+ emit("update:disableLoginButton", false);
35
35
  token.value = receivedToken;
36
36
  setJWT(receivedToken);
37
37
  });
package/dist/index.js CHANGED
@@ -46,39 +46,27 @@ export default class CaptchaPlugin extends AdminForthPlugin {
46
46
  });
47
47
  const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation;
48
48
  const beforeLoginConfirmationArray = Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation];
49
- beforeLoginConfirmationArray.push((_a) => __awaiter(this, [_a], void 0, function* ({ extra }) {
49
+ beforeLoginConfirmationArray.unshift((_a) => __awaiter(this, [_a], void 0, function* ({ extra }) {
50
50
  var _b;
51
+ const rejectResult = {
52
+ body: {
53
+ allowedLogin: false,
54
+ redirectTo: '/login',
55
+ },
56
+ ok: true
57
+ };
51
58
  if (!extra || !extra.cookies) {
52
- return {
53
- body: {
54
- allowedLogin: false,
55
- redirectTo: '/login',
56
- },
57
- ok: true
58
- };
59
+ return rejectResult;
59
60
  }
60
61
  const cookies = extra.cookies;
61
62
  const token = (_b = cookies.find((cookie) => cookie.key === `adminforth_${adapterName}_temporaryJWT`)) === null || _b === void 0 ? void 0 : _b.value;
62
63
  if (!token) {
63
- return {
64
- body: {
65
- allowedLogin: false,
66
- redirectTo: '/login',
67
- },
68
- ok: true
69
- };
64
+ return rejectResult;
70
65
  }
71
66
  const ip = this.adminforth.auth.getClientIp(extra.headers);
72
67
  const validationResult = yield this.options.captchaAdapter.validate(token, ip);
73
- console.log('Validation result:', validationResult);
74
68
  if (!validationResult || !validationResult.success) {
75
- return {
76
- body: {
77
- allowedLogin: false,
78
- redirectTo: '/login',
79
- },
80
- ok: true
81
- };
69
+ return rejectResult;
82
70
  }
83
71
  }));
84
72
  });
package/index.ts CHANGED
@@ -47,43 +47,31 @@ export default class CaptchaPlugin extends AdminForthPlugin {
47
47
 
48
48
  const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation;
49
49
  const beforeLoginConfirmationArray = Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation];
50
- beforeLoginConfirmationArray.push(
50
+ beforeLoginConfirmationArray.unshift(
51
51
  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
+
52
60
  if ( !extra || !extra.cookies ) {
53
- return {
54
- body:{
55
- allowedLogin: false,
56
- redirectTo: '/login',
57
- },
58
- ok: true
59
- }
61
+ return rejectResult;
60
62
  }
61
63
  const cookies = extra.cookies;
62
64
  const token = cookies.find(
63
65
  (cookie) => cookie.key === `adminforth_${adapterName}_temporaryJWT`
64
66
  )?.value;
65
67
  if ( !token ) {
66
- return {
67
- body:{
68
- allowedLogin: false,
69
- redirectTo: '/login',
70
- },
71
- ok: true
72
- }
68
+ return rejectResult;
73
69
  }
74
70
 
75
71
  const ip = this.adminforth.auth.getClientIp(extra.headers);
76
72
  const validationResult = await this.options.captchaAdapter.validate(token, ip);
77
- console.log('Validation result:', validationResult);
78
-
79
73
  if (!validationResult || !validationResult.success) {
80
- return {
81
- body:{
82
- allowedLogin: false,
83
- redirectTo: '/login',
84
- },
85
- ok: true
86
- }
74
+ return rejectResult;
87
75
  }
88
76
  }
89
77
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/login-captcha",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",