adminforth 1.1.74 → 1.1.75

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.
Files changed (115) hide show
  1. package/auth.ts +14 -0
  2. package/dataConnectors/postgres.ts +1 -1
  3. package/dist/auth.js +7 -0
  4. package/dist/index.js +117 -65
  5. package/dist/modules/codeInjector.js +29 -15
  6. package/dist/plugins/AuditLogPlugin/index.js +2 -17
  7. package/dist/plugins/S3UploadPlugin/custom/s3uploader.vue +120 -0
  8. package/dist/plugins/S3UploadPlugin/index.js +103 -0
  9. package/dist/plugins/S3UploadPlugin/package-lock.json +431 -0
  10. package/dist/plugins/S3UploadPlugin/package.json +15 -0
  11. package/dist/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsConfirmation.vue +152 -0
  12. package/dist/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsSetup.vue +188 -0
  13. package/dist/plugins/TwoFactorsAuthPlugin/index.js +150 -0
  14. package/dist/plugins/TwoFactorsAuthPlugin/types.js +1 -0
  15. package/dist/spa/index.html +1 -1
  16. package/dist/spa/package-lock.json +111 -0
  17. package/dist/spa/package.json +1 -0
  18. package/dist/spa/src/App.vue +178 -133
  19. package/dist/spa/src/components/MenuLink.vue +3 -3
  20. package/dist/spa/src/components/ResourceForm.vue +96 -96
  21. package/dist/spa/src/components/ResourceListTable.vue +69 -84
  22. package/dist/spa/src/components/ValueRenderer.vue +2 -3
  23. package/dist/spa/src/composables/useStores.ts +24 -11
  24. package/dist/spa/src/main.ts +1 -1
  25. package/dist/spa/src/router/index.ts +0 -1
  26. package/dist/spa/src/utils.ts +1 -1
  27. package/dist/spa/src/views/CreateView.vue +1 -9
  28. package/dist/spa/src/views/EditView.vue +1 -9
  29. package/dist/spa/src/views/ListView.vue +12 -3
  30. package/dist/spa/src/views/LoginView.vue +6 -1
  31. package/dist/spa/src/views/ResourceParent.vue +1 -2
  32. package/dist/spa/src/views/ShowView.vue +6 -14
  33. package/dist/spa/tailwind.config.js +3 -1
  34. package/index.ts +94 -35
  35. package/modules/codeInjector.ts +38 -27
  36. package/package.json +2 -1
  37. package/plugins/AuditLogPlugin/index.ts +4 -20
  38. package/plugins/S3UploadPlugin/custom/s3uploader.vue +120 -0
  39. package/plugins/S3UploadPlugin/index.ts +112 -0
  40. package/plugins/S3UploadPlugin/package-lock.json +431 -0
  41. package/plugins/S3UploadPlugin/package.json +15 -0
  42. package/plugins/S3UploadPlugin/types.ts +76 -0
  43. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsConfirmation.vue +152 -0
  44. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsOtp.vue +0 -0
  45. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsSetup.vue +188 -0
  46. package/plugins/TwoFactorsAuthPlugin/index.ts +150 -0
  47. package/plugins/TwoFactorsAuthPlugin/types.ts +10 -0
  48. package/servers/express.ts +1 -0
  49. package/spa/src/App.vue +154 -121
  50. package/spa/src/components/ResourceForm.vue +91 -91
  51. package/spa/src/router/index.ts +0 -1
  52. package/spa/src/utils.ts +1 -1
  53. package/spa/src/views/CreateView.vue +0 -1
  54. package/spa/src/views/LoginView.vue +4 -1
  55. package/types/AdminForthConfig.ts +24 -3
  56. package/dist/plugins/AuditLog/index.js +0 -13
  57. package/dist/spa/spa/.eslintrc.cjs +0 -14
  58. package/dist/spa/spa/.vscode/extensions.json +0 -6
  59. package/dist/spa/spa/README.md +0 -39
  60. package/dist/spa/spa/env.d.ts +0 -1
  61. package/dist/spa/spa/index.html +0 -23
  62. package/dist/spa/spa/package-lock.json +0 -4470
  63. package/dist/spa/spa/package.json +0 -48
  64. package/dist/spa/spa/postcss.config.js +0 -6
  65. package/dist/spa/spa/public/assets/favicon.png +0 -0
  66. package/dist/spa/spa/src/App.vue +0 -283
  67. package/dist/spa/spa/src/assets/logo.svg +0 -19
  68. package/dist/spa/spa/src/components/AcceptModal.vue +0 -45
  69. package/dist/spa/spa/src/components/Breadcrumbs.vue +0 -40
  70. package/dist/spa/spa/src/components/BreadcrumbsWithButtons.vue +0 -26
  71. package/dist/spa/spa/src/components/CustomDatePicker.vue +0 -174
  72. package/dist/spa/spa/src/components/CustomDateRangePicker.vue +0 -218
  73. package/dist/spa/spa/src/components/CustomRangePicker.vue +0 -148
  74. package/dist/spa/spa/src/components/Dropdown.vue +0 -168
  75. package/dist/spa/spa/src/components/Filters.vue +0 -211
  76. package/dist/spa/spa/src/components/HelloWorld.vue +0 -17
  77. package/dist/spa/spa/src/components/MenuLink.vue +0 -24
  78. package/dist/spa/spa/src/components/ResourceForm.vue +0 -265
  79. package/dist/spa/spa/src/components/ResourceListTable.vue +0 -404
  80. package/dist/spa/spa/src/components/SingleSkeletLoader.vue +0 -13
  81. package/dist/spa/spa/src/components/Toast.vue +0 -66
  82. package/dist/spa/spa/src/components/ValueRenderer.vue +0 -59
  83. package/dist/spa/spa/src/components/icons/IconCalendar.vue +0 -5
  84. package/dist/spa/spa/src/components/icons/IconCommunity.vue +0 -7
  85. package/dist/spa/spa/src/components/icons/IconDocumentation.vue +0 -7
  86. package/dist/spa/spa/src/components/icons/IconEcosystem.vue +0 -7
  87. package/dist/spa/spa/src/components/icons/IconSupport.vue +0 -7
  88. package/dist/spa/spa/src/components/icons/IconTime.vue +0 -5
  89. package/dist/spa/spa/src/components/icons/IconTooling.vue +0 -19
  90. package/dist/spa/spa/src/composables/useFrontendApi.ts +0 -26
  91. package/dist/spa/spa/src/composables/useStores.ts +0 -126
  92. package/dist/spa/spa/src/index.scss +0 -26
  93. package/dist/spa/spa/src/main.ts +0 -18
  94. package/dist/spa/spa/src/router/index.ts +0 -64
  95. package/dist/spa/spa/src/spa_types/core.ts +0 -51
  96. package/dist/spa/spa/src/stores/core.ts +0 -144
  97. package/dist/spa/spa/src/stores/filters.ts +0 -22
  98. package/dist/spa/spa/src/stores/modal.ts +0 -48
  99. package/dist/spa/spa/src/stores/toast.ts +0 -15
  100. package/dist/spa/spa/src/stores/user.ts +0 -54
  101. package/dist/spa/spa/src/utils.ts +0 -101
  102. package/dist/spa/spa/src/views/CreateView.vue +0 -156
  103. package/dist/spa/spa/src/views/EditView.vue +0 -157
  104. package/dist/spa/spa/src/views/ListView.vue +0 -266
  105. package/dist/spa/spa/src/views/LoginView.vue +0 -136
  106. package/dist/spa/spa/src/views/ResourceParent.vue +0 -17
  107. package/dist/spa/spa/src/views/ShowView.vue +0 -180
  108. package/dist/spa/spa/tailwind.config.js +0 -17
  109. package/dist/spa/spa/tsconfig.app.json +0 -14
  110. package/dist/spa/spa/tsconfig.json +0 -11
  111. package/dist/spa/spa/tsconfig.node.json +0 -19
  112. package/dist/spa/spa/vite.config.ts +0 -49
  113. /package/dist/plugins/{AuditLog → S3UploadPlugin}/types.js +0 -0
  114. /package/dist/{spa/spa/src/assets/base.css → plugins/TwoFactorsAuthPlugin/custom/TwoFactorsOtp.vue} +0 -0
  115. /package/dist/spa/{spa/src → src}/components/SkeleteLoader.vue +0 -0
@@ -0,0 +1,152 @@
1
+ <template>
2
+ <div class="relative flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-800"
3
+ :style="coreStore.config?.loginBackgroundImage ? {
4
+ 'background-image': 'url(' + loadFile(coreStore.config?.loginBackgroundImage) + ')',
5
+ 'background-size': 'cover',
6
+ 'background-position': 'center',
7
+ 'background-blend-mode': 'darken'
8
+ }: {}"
9
+ >
10
+
11
+ <div id="authentication-modal" tabindex="-1" class=" overflow-y-auto overflow-x-hidden z-50 min-w-[00px] justify-center items-center md:inset-0 h-[calc(100%-1rem)] max-h-full">
12
+ <div class="relative p-4 w-full max-w-md max-h-full">
13
+ <!-- Modal content -->
14
+ <div class="relative bg-white rounded-lg shadow dark:bg-gray-700 dark:shadow-black text-gray-500" >
15
+ <div class="p-8 w-full max-w-md max-h-full" >
16
+ <div class="m-3" >Please enter your authenticator code </div>
17
+
18
+ <form class="max-w-sm mx-auto mt-6 flex flex-col items-center ">
19
+ <div class="flex mb-2 space-x-2 rtl:space-x-reverse ">
20
+ <div>
21
+ <label for="code-1" class="sr-only">First code</label>
22
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-next="code-2" id="code-1" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
23
+ </div>
24
+ <div>
25
+ <label for="code-2" class="sr-only">Second code</label>
26
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-1" data-focus-input-next="code-3" id="code-2" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
27
+ </div>
28
+ <div>
29
+ <label for="code-3" class="sr-only">Third code</label>
30
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-2" data-focus-input-next="code-4" id="code-3" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
31
+ </div>
32
+ <div>
33
+ <label for="code-4" class="sr-only">Fourth code</label>
34
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-3" data-focus-input-next="code-5" id="code-4" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
35
+ </div>
36
+ <div>
37
+ <label for="code-5" class="sr-only">Fifth code</label>
38
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-4" data-focus-input-next="code-6" id="code-5" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
39
+ </div>
40
+ <div>
41
+ <label for="code-6" class="sr-only">Sixth code</label>
42
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-5" id="code-6" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
43
+ </div>
44
+ </div>
45
+ <p id="helper-text-explanation" class="mt-2 text-sm text-gray-500 dark:text-gray-400"></p>
46
+ </form>
47
+ <button @click="()=>{router.push('./login')}" class="flex items-center justify-center gap-1 w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
48
+ >Cancel</button>
49
+ </div>
50
+ </div>
51
+ </div>
52
+ </div>
53
+
54
+ </div>
55
+
56
+
57
+ </template>
58
+
59
+
60
+ <script setup>
61
+
62
+ import { onMounted, ref, watchEffect,computed } from 'vue';
63
+ import { useCoreStore } from '@/stores/core';
64
+ import { useUserStore } from '@/stores/user';
65
+ import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
66
+ import { callAdminForthApi, loadFile } from '@/utils';
67
+ import { useRouter } from 'vue-router';
68
+ import { initFlowbite } from 'flowbite'
69
+ import { showErrorTost } from '@/composables/useFrontendApi';
70
+
71
+
72
+
73
+
74
+ const router = useRouter();
75
+ const inProgress = ref(false);
76
+
77
+ const coreStore = useCoreStore();
78
+ const user = useUserStore();
79
+
80
+ // use this simple function to automatically focus on the next input
81
+
82
+
83
+
84
+ const showPw = ref(false);
85
+
86
+ const error = ref(null);
87
+ const totp = ref({});
88
+ const totpJWT = ref(null);
89
+
90
+
91
+ function parseJwt(token) {
92
+ // Split the token into its parts
93
+ const base64Url = token.split('.')[1];
94
+
95
+ // Base64-decode the payload
96
+ const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
97
+ const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
98
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
99
+ }).join(''));
100
+
101
+ // Parse the JSON payload
102
+ return JSON.parse(jsonPayload);
103
+ }
104
+
105
+ onMounted(async () => {
106
+ coreStore.getPublicConfig()
107
+
108
+ function focusNextInput(el, prevId, nextId) {
109
+ if (el.value.length === 0) {
110
+ if (prevId) {
111
+ document.getElementById(prevId).focus();
112
+ }
113
+ } else {
114
+ if (nextId) {
115
+ document.getElementById(nextId).focus();
116
+ } else {
117
+ sendCode()
118
+ }
119
+ }
120
+ }
121
+
122
+ document.querySelectorAll('[data-focus-input-init]').forEach(function(element) {
123
+ element.addEventListener('keyup', function() {
124
+ const prevId = this.getAttribute('data-focus-input-prev');
125
+ const nextId = this.getAttribute('data-focus-input-next');
126
+ focusNextInput(this, prevId, nextId);
127
+ });
128
+ });
129
+
130
+
131
+
132
+ });
133
+
134
+ async function sendCode () {
135
+ inProgress.value = true;
136
+ const code = document.getElementById('code-1').value + document.getElementById('code-2').value + document.getElementById('code-3').value + document.getElementById('code-4').value + document.getElementById('code-5').value + document.getElementById('code-6').value;
137
+ const resp = await callAdminForthApi({
138
+ method: 'POST',
139
+ path: '/plugin/twofa/confirmSetup',
140
+ body: {
141
+ code: code,
142
+ secret: null,
143
+ }
144
+ })
145
+ if (resp.allowedLogin){
146
+ router.push('/');
147
+ } else {
148
+ showErrorTost('Invalid code');
149
+ }
150
+ }
151
+ </script>
152
+
@@ -0,0 +1,188 @@
1
+ <template>
2
+ <div class="relative flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-800"
3
+ :style="coreStore.config?.loginBackgroundImage ? {
4
+ 'background-image': 'url(' + loadFile(coreStore.config?.loginBackgroundImage) + ')',
5
+ 'background-size': 'cover',
6
+ 'background-position': 'center',
7
+ 'background-blend-mode': 'darken'
8
+ }: {}"
9
+ >
10
+
11
+ <div id="authentication-modal" tabindex="-1" class=" overflow-y-auto overflow-x-hidden z-50 min-w-[00px] justify-center items-center md:inset-0 h-[calc(100%-1rem)] max-h-full">
12
+ <div class="relative p-4 w-full max-w-md max-h-full">
13
+ <!-- Modal content -->
14
+ <div class="relative bg-white rounded-lg shadow dark:bg-gray-700 dark:shadow-black text-gray-500" >
15
+ <div class="p-8 w-full max-w-md max-h-full" >
16
+ <div class="m-3" >Scan this QR code with your authenticator app or open by <a class="text-blue-600" :href="totpUri">click</a></div>
17
+ <div class="flex justify-center m-3" >
18
+ <img :src="totpQrCode" alt="QR code" />
19
+ </div>
20
+ <div class="m-3 ">
21
+ <div class="m-1">Or copy this code to app manually:</div>
22
+ <div class="w-full max-w-[46rem]">
23
+ <div class="relative">
24
+ <label for="npm-install-copy-text" class="sr-only">Label</label>
25
+ <input id="npm-install-copy-text" type="text" class="col-span-10 bg-gray-50 border border-gray-300 text-gray-500 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full px-2.5 py-4 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500" :value="totp.newSecret" disabled readonly>
26
+ <button data-copy-to-clipboard-target="npm-install-copy-text" class="absolute end-2.5 top-1/2 -translate-y-1/2 text-gray-900 dark:text-gray-400 hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-600 dark:hover:bg-gray-700 rounded-lg py-2 px-2.5 inline-flex items-center justify-center bg-white border-gray-200 border">
27
+ <span id="default-message" class="inline-flex items-center">
28
+ <svg class="w-3 h-3 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 18 20">
29
+ <path d="M16 1h-3.278A1.992 1.992 0 0 0 11 0H7a1.993 1.993 0 0 0-1.722 1H2a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2Zm-3 14H5a1 1 0 0 1 0-2h8a1 1 0 0 1 0 2Zm0-4H5a1 1 0 0 1 0-2h8a1 1 0 1 1 0 2Zm0-5H5a1 1 0 0 1 0-2h2V2h4v2h2a1 1 0 1 1 0 2Z"/>
30
+ </svg>
31
+ <span class="text-xs font-semibold">Copy</span>
32
+ </span>
33
+ <span id="success-message" class="hidden inline-flex items-center">
34
+ <svg class="w-3 h-3 text-blue-700 dark:text-blue-500 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 12">
35
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5.917 5.724 10.5 15 1.5"/>
36
+ </svg>
37
+ <span class="text-xs font-semibold text-blue-700 dark:text-blue-500">Copied</span>
38
+ </span>
39
+ </button>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ <form class="max-w-sm mx-auto mt-6 flex flex-col items-center ">
44
+ <div class="flex mb-2 space-x-2 rtl:space-x-reverse ">
45
+ <div>
46
+ <label for="code-1" class="sr-only">First code</label>
47
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-next="code-2" id="code-1" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
48
+ </div>
49
+ <div>
50
+ <label for="code-2" class="sr-only">Second code</label>
51
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-1" data-focus-input-next="code-3" id="code-2" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
52
+ </div>
53
+ <div>
54
+ <label for="code-3" class="sr-only">Third code</label>
55
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-2" data-focus-input-next="code-4" id="code-3" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
56
+ </div>
57
+ <div>
58
+ <label for="code-4" class="sr-only">Fourth code</label>
59
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-3" data-focus-input-next="code-5" id="code-4" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
60
+ </div>
61
+ <div>
62
+ <label for="code-5" class="sr-only">Fifth code</label>
63
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-4" data-focus-input-next="code-6" id="code-5" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
64
+ </div>
65
+ <div>
66
+ <label for="code-6" class="sr-only">Sixth code</label>
67
+ <input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-5" id="code-6" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
68
+ </div>
69
+ </div>
70
+ <p id="helper-text-explanation" class="mt-2 text-sm text-gray-500 dark:text-gray-400"></p>
71
+ </form>
72
+ <button @click="()=>{router.push('./login')}" class="flex items-center justify-center gap-1 w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Cancel</button>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </div>
77
+
78
+ </div>
79
+
80
+
81
+ </template>
82
+
83
+
84
+ <script setup>
85
+
86
+ import { onMounted, ref, watchEffect,computed } from 'vue';
87
+ import { useCoreStore } from '@/stores/core';
88
+ import { useUserStore } from '@/stores/user';
89
+ import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
90
+ import { callAdminForthApi, loadFile } from '@/utils';
91
+ import { useRouter } from 'vue-router';
92
+ import { initFlowbite } from 'flowbite'
93
+ import { showErrorTost } from '@/composables/useFrontendApi';
94
+
95
+
96
+
97
+
98
+ const router = useRouter();
99
+ const inProgress = ref(false);
100
+
101
+ const coreStore = useCoreStore();
102
+ const user = useUserStore();
103
+
104
+ // use this simple function to automatically focus on the next input
105
+
106
+
107
+
108
+ const showPw = ref(false);
109
+
110
+ const error = ref(null);
111
+ const totp = ref({});
112
+ const totpJWT = ref(null);
113
+ const totpUri = computed(() => {
114
+ if (totp.value) {
115
+ return `otpauth://totp/${totp.value.issuer}:${totp.value.userName}?secret=${totp.value.newSecret}&issuer=${totp.value.issuer}`;
116
+ }});
117
+ const totpQrCode = computed(() => {
118
+ if (totpUri.value) {
119
+ return `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(totpUri.value)}`;
120
+ }});
121
+
122
+ function parseJwt(token) {
123
+ // Split the token into its parts
124
+ const base64Url = token.split('.')[1];
125
+
126
+ // Base64-decode the payload
127
+ const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
128
+ const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
129
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
130
+ }).join(''));
131
+
132
+ // Parse the JSON payload
133
+ return JSON.parse(jsonPayload);
134
+ }
135
+
136
+ onMounted(async () => {
137
+ coreStore.getPublicConfig()
138
+ const resp = await callAdminForthApi({
139
+ path: '/plugin/twofa/initSetup',
140
+ method: 'POST',});
141
+ if (resp && resp.totpJWT){
142
+ totpJWT.value = resp.totpJWT;
143
+ }
144
+ function focusNextInput(el, prevId, nextId) {
145
+ if (el.value.length === 0) {
146
+ if (prevId) {
147
+ document.getElementById(prevId).focus();
148
+ }
149
+ } else {
150
+ if (nextId) {
151
+ document.getElementById(nextId).focus();
152
+ } else {
153
+ sendCode()
154
+ }
155
+ }
156
+ }
157
+
158
+ document.querySelectorAll('[data-focus-input-init]').forEach(function(element) {
159
+ element.addEventListener('keyup', function() {
160
+ const prevId = this.getAttribute('data-focus-input-prev');
161
+ const nextId = this.getAttribute('data-focus-input-next');
162
+ focusNextInput(this, prevId, nextId);
163
+ });
164
+ });
165
+
166
+ totp.value=parseJwt(totpJWT.value);
167
+
168
+
169
+ });
170
+
171
+ async function sendCode () {
172
+ inProgress.value = true;
173
+ const code = document.getElementById('code-1').value + document.getElementById('code-2').value + document.getElementById('code-3').value + document.getElementById('code-4').value + document.getElementById('code-5').value + document.getElementById('code-6').value;
174
+ const resp = await callAdminForthApi({
175
+ method: 'POST',
176
+ path: '/plugin/twofa/confirmSetup',
177
+ body: {
178
+ code: code,
179
+ secret: totp.value.newSecret,
180
+ }
181
+ })
182
+ if (resp.allowedLogin){
183
+ router.push('/');
184
+ } else {
185
+ showErrorTost('Invalid code');
186
+ }
187
+ }
188
+ </script>
@@ -0,0 +1,150 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import AdminForthPlugin from "../base.js";
11
+ import twofactor from 'node-2fa';
12
+ import AdminForthAuth from "../../auth.js";
13
+ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
14
+ constructor(options) {
15
+ super(options, import.meta.url);
16
+ this.options = options;
17
+ }
18
+ modifyResourceConfig(adminforth, resourceConfig) {
19
+ super.modifyResourceConfig(adminforth, resourceConfig);
20
+ this.adminforth = adminforth;
21
+ this.adminForthAuth = new AdminForthAuth(adminforth);
22
+ const customPages = this.adminforth.config.customization.customPages;
23
+ customPages.push({
24
+ path: '/confirm2fa',
25
+ component: { file: this.componentPath('TwoFactorsConfirmation.vue'), meta: { customLayout: true } }
26
+ });
27
+ customPages.push({
28
+ path: '/setup2fa',
29
+ component: { file: this.componentPath('TwoFactorsSetup.vue'), meta: { title: 'Setup 2FA', customLayout: true } }
30
+ });
31
+ this.activate(resourceConfig, adminforth);
32
+ }
33
+ activate(resourceConfig, adminforth) {
34
+ if (!this.options.twoFaSecretFieldName) {
35
+ throw new Error('twoFaSecretFieldName is required');
36
+ }
37
+ if (typeof this.options.twoFaSecretFieldName !== 'string') {
38
+ throw new Error('twoFaSecretFieldName must be a string');
39
+ }
40
+ this.authResource = resourceConfig;
41
+ if (!this.authResource.columns.some((col) => col.name === this.options.twoFaSecretFieldName)) {
42
+ throw new Error(`Column ${this.options.twoFaSecretFieldName} not found in ${this.authResource.label}`);
43
+ }
44
+ const beforeLoginConfirmation = this.adminforth.config.auth;
45
+ if (!beforeLoginConfirmation.beforeLoginConfirmation) {
46
+ beforeLoginConfirmation.beforeLoginConfirmation = [];
47
+ }
48
+ beforeLoginConfirmation.beforeLoginConfirmation.push((_a) => __awaiter(this, [_a], void 0, function* ({ adminUser }) {
49
+ if (adminUser.isRoot) {
50
+ return { body: { loginAllowed: true }, ok: true };
51
+ }
52
+ const secret = adminUser.dbUser[this.options.twoFaSecretFieldName];
53
+ const userName = adminUser.dbUser[adminforth.config.auth.usernameField];
54
+ const brandName = adminforth.config.customization.brandName;
55
+ const authResource = adminforth.config.resources.find((res) => res.resourceId === adminforth.config.auth.resourceId);
56
+ const authPk = authResource.columns.find((col) => col.primaryKey).name;
57
+ const userPk = adminUser.dbUser[authPk];
58
+ let newSecret = null;
59
+ if (!secret) {
60
+ const tempSecret = twofactor.generateSecret({ name: brandName, account: userName });
61
+ newSecret = tempSecret.secret;
62
+ }
63
+ else {
64
+ return {
65
+ body: {
66
+ loginAllowed: false,
67
+ redirectTo: '/confirm2fa',
68
+ setCookie: [{
69
+ name: 'totpTemporaryJWT',
70
+ value: this.adminforth.auth.issueJWT({ userName, issuer: brandName, pk: userPk }, 'tempTotp'),
71
+ expiry: '1h',
72
+ httpOnly: true
73
+ },]
74
+ },
75
+ ok: true
76
+ };
77
+ }
78
+ const totpTemporaryJWT = this.adminforth.auth.issueJWT({ userName, newSecret, issuer: brandName, pk: userPk }, 'tempTotp');
79
+ return {
80
+ body: {
81
+ loginAllowed: false,
82
+ redirectTo: secret ? '/confirm2fa' : '/setup2fa',
83
+ setCookie: [{
84
+ name: 'totpTemporaryJWT',
85
+ value: totpTemporaryJWT,
86
+ expiry: '1h',
87
+ httpOnly: true
88
+ },]
89
+ },
90
+ ok: true
91
+ };
92
+ }));
93
+ }
94
+ setupEndpoints(server) {
95
+ server.endpoint({
96
+ method: 'POST',
97
+ path: `/plugin/twofa/initSetup`,
98
+ noAuth: true,
99
+ handler: (server) => __awaiter(this, void 0, void 0, function* () {
100
+ const toReturn = { totpJWT: null, status: 'ok', };
101
+ const totpTemporaryJWT = server.cookies['adminforth_totpTemporaryJWT'];
102
+ if (totpTemporaryJWT) {
103
+ toReturn.totpJWT = totpTemporaryJWT;
104
+ }
105
+ return toReturn;
106
+ })
107
+ });
108
+ server.endpoint({
109
+ method: 'POST',
110
+ path: `/plugin/twofa/confirmSetup`,
111
+ noAuth: true,
112
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies }) {
113
+ const totpTemporaryJWT = cookies['adminforth_totpTemporaryJWT'];
114
+ const decoded = yield this.adminforth.auth.verify(totpTemporaryJWT, 'tempTotp');
115
+ if (!decoded) {
116
+ return { status: 'error', message: 'Invalid token' };
117
+ }
118
+ if (decoded.newSecret) {
119
+ const verified = twofactor.verifyToken(decoded.newSecret, body.code);
120
+ if (verified) {
121
+ this.connectors = this.adminforth.connectors;
122
+ const connector = this.connectors[this.authResource.dataSource];
123
+ yield connector.updateRecord({ resource: this.authResource, recordId: decoded.pk, newValues: { [this.options.twoFaSecretFieldName]: decoded.newSecret } });
124
+ this.adminForthAuth.removeCustomCookie({ response, name: 'totpTemporaryJWT' });
125
+ this.adminForthAuth.setAuthCookie({ response, username: decoded.userName, pk: decoded.pk });
126
+ return { status: 'ok', allowedLogin: true };
127
+ }
128
+ else {
129
+ return { error: 'Wrong or expired OTP code' };
130
+ }
131
+ }
132
+ else {
133
+ // user already has secret, get it
134
+ this.connectors = this.adminforth.connectors;
135
+ const connector = this.connectors[this.authResource.dataSource];
136
+ const user = yield connector.getRecordByPrimaryKey(this.authResource, decoded.pk);
137
+ const verified = twofactor.verifyToken(user[this.options.twoFaSecretFieldName], body.code);
138
+ if (verified) {
139
+ this.adminForthAuth.removeCustomCookie({ response, name: 'totpTemporaryJWT' });
140
+ this.adminForthAuth.setAuthCookie({ response, username: decoded.userName, pk: decoded.pk });
141
+ return { status: 'ok', allowedLogin: true };
142
+ }
143
+ else {
144
+ return { error: 'Wrong or expired OTP code' };
145
+ }
146
+ }
147
+ })
148
+ });
149
+ }
150
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -17,7 +17,7 @@
17
17
 
18
18
  </head>
19
19
  <body class=" ">
20
- <div id="app" class="min-h-screen bg-html-bg dark:bg-gray-800"></div>
20
+ <div id="app" class="min-h-screen bg-lightHtml dark:bg-darkHtml"></div>
21
21
  <script type="module" src="/src/main.ts"></script>
22
22
  </body>
23
23
  </html>
@@ -19,6 +19,7 @@
19
19
  "unhead": "^1.9.12",
20
20
  "uuid": "^10.0.0",
21
21
  "vue": "^3.4.21",
22
+ "vue-diff": "^1.2.4",
22
23
  "vue-router": "^4.3.0",
23
24
  "vue-slider-component": "^4.1.0-beta.7"
24
25
  },
@@ -1902,6 +1903,11 @@
1902
1903
  "integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==",
1903
1904
  "dev": true
1904
1905
  },
1906
+ "node_modules/diff-match-patch": {
1907
+ "version": "1.0.5",
1908
+ "resolved": "https://registry.npmjs.org/diff-match-patch/-/diff-match-patch-1.0.5.tgz",
1909
+ "integrity": "sha512-IayShXAgj/QMXgB0IWmKx+rOPuGMhqm5w6jvFxmVenXKIzRqTAAsbBPT3kWQeGANj3jGgvcvv4yK6SxqYmikgw=="
1910
+ },
1905
1911
  "node_modules/dir-glob": {
1906
1912
  "version": "3.0.1",
1907
1913
  "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@@ -2526,6 +2532,14 @@
2526
2532
  "he": "bin/he"
2527
2533
  }
2528
2534
  },
2535
+ "node_modules/highlight.js": {
2536
+ "version": "11.9.0",
2537
+ "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.9.0.tgz",
2538
+ "integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==",
2539
+ "engines": {
2540
+ "node": ">=12.0.0"
2541
+ }
2542
+ },
2529
2543
  "node_modules/hookable": {
2530
2544
  "version": "5.5.3",
2531
2545
  "resolved": "https://registry.npmjs.org/hookable/-/hookable-5.5.3.tgz",
@@ -4120,6 +4134,103 @@
4120
4134
  }
4121
4135
  }
4122
4136
  },
4137
+ "node_modules/vue-diff": {
4138
+ "version": "1.2.4",
4139
+ "resolved": "https://registry.npmjs.org/vue-diff/-/vue-diff-1.2.4.tgz",
4140
+ "integrity": "sha512-9z+0uPHigi/DdE3Zhdg1zR3VkiBaDN4czjWa/Zznvizn4znckVqz20p1KytaWq5NJtJ7UnkqRbuWsaCuC1ZHaA==",
4141
+ "dependencies": {
4142
+ "@vueuse/core": "^8.3.1",
4143
+ "diff-match-patch": "^1.0.5",
4144
+ "highlight.js": "^11.5.1"
4145
+ }
4146
+ },
4147
+ "node_modules/vue-diff/node_modules/@types/web-bluetooth": {
4148
+ "version": "0.0.14",
4149
+ "resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.14.tgz",
4150
+ "integrity": "sha512-5d2RhCard1nQUC3aHcq/gHzWYO6K0WJmAbjO7mQJgCQKtZpgXxv1rOM6O/dBDhDYYVutk1sciOgNSe+5YyfM8A=="
4151
+ },
4152
+ "node_modules/vue-diff/node_modules/@vueuse/core": {
4153
+ "version": "8.9.4",
4154
+ "resolved": "https://registry.npmjs.org/@vueuse/core/-/core-8.9.4.tgz",
4155
+ "integrity": "sha512-B/Mdj9TK1peFyWaPof+Zf/mP9XuGAngaJZBwPaXBvU3aCTZlx3ltlrFFFyMV4iGBwsjSCeUCgZrtkEj9dS2Y3Q==",
4156
+ "dependencies": {
4157
+ "@types/web-bluetooth": "^0.0.14",
4158
+ "@vueuse/metadata": "8.9.4",
4159
+ "@vueuse/shared": "8.9.4",
4160
+ "vue-demi": "*"
4161
+ },
4162
+ "funding": {
4163
+ "url": "https://github.com/sponsors/antfu"
4164
+ },
4165
+ "peerDependencies": {
4166
+ "@vue/composition-api": "^1.1.0",
4167
+ "vue": "^2.6.0 || ^3.2.0"
4168
+ },
4169
+ "peerDependenciesMeta": {
4170
+ "@vue/composition-api": {
4171
+ "optional": true
4172
+ },
4173
+ "vue": {
4174
+ "optional": true
4175
+ }
4176
+ }
4177
+ },
4178
+ "node_modules/vue-diff/node_modules/@vueuse/metadata": {
4179
+ "version": "8.9.4",
4180
+ "resolved": "https://registry.npmjs.org/@vueuse/metadata/-/metadata-8.9.4.tgz",
4181
+ "integrity": "sha512-IwSfzH80bnJMzqhaapqJl9JRIiyQU0zsRGEgnxN6jhq7992cPUJIRfV+JHRIZXjYqbwt07E1gTEp0R0zPJ1aqw==",
4182
+ "funding": {
4183
+ "url": "https://github.com/sponsors/antfu"
4184
+ }
4185
+ },
4186
+ "node_modules/vue-diff/node_modules/@vueuse/shared": {
4187
+ "version": "8.9.4",
4188
+ "resolved": "https://registry.npmjs.org/@vueuse/shared/-/shared-8.9.4.tgz",
4189
+ "integrity": "sha512-wt+T30c4K6dGRMVqPddexEVLa28YwxW5OFIPmzUHICjphfAuBFTTdDoyqREZNDOFJZ44ARH1WWQNCUK8koJ+Ag==",
4190
+ "dependencies": {
4191
+ "vue-demi": "*"
4192
+ },
4193
+ "funding": {
4194
+ "url": "https://github.com/sponsors/antfu"
4195
+ },
4196
+ "peerDependencies": {
4197
+ "@vue/composition-api": "^1.1.0",
4198
+ "vue": "^2.6.0 || ^3.2.0"
4199
+ },
4200
+ "peerDependenciesMeta": {
4201
+ "@vue/composition-api": {
4202
+ "optional": true
4203
+ },
4204
+ "vue": {
4205
+ "optional": true
4206
+ }
4207
+ }
4208
+ },
4209
+ "node_modules/vue-diff/node_modules/vue-demi": {
4210
+ "version": "0.14.8",
4211
+ "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.8.tgz",
4212
+ "integrity": "sha512-Uuqnk9YE9SsWeReYqK2alDI5YzciATE0r2SkA6iMAtuXvNTMNACJLJEXNXaEy94ECuBe4Sk6RzRU80kjdbIo1Q==",
4213
+ "hasInstallScript": true,
4214
+ "bin": {
4215
+ "vue-demi-fix": "bin/vue-demi-fix.js",
4216
+ "vue-demi-switch": "bin/vue-demi-switch.js"
4217
+ },
4218
+ "engines": {
4219
+ "node": ">=12"
4220
+ },
4221
+ "funding": {
4222
+ "url": "https://github.com/sponsors/antfu"
4223
+ },
4224
+ "peerDependencies": {
4225
+ "@vue/composition-api": "^1.0.0-rc.1",
4226
+ "vue": "^3.0.0-0 || ^2.6.0"
4227
+ },
4228
+ "peerDependenciesMeta": {
4229
+ "@vue/composition-api": {
4230
+ "optional": true
4231
+ }
4232
+ }
4233
+ },
4123
4234
  "node_modules/vue-eslint-parser": {
4124
4235
  "version": "9.4.2",
4125
4236
  "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-9.4.2.tgz",
@@ -23,6 +23,7 @@
23
23
  "unhead": "^1.9.12",
24
24
  "uuid": "^10.0.0",
25
25
  "vue": "^3.4.21",
26
+ "vue-diff": "^1.2.4",
26
27
  "vue-router": "^4.3.0",
27
28
  "vue-slider-component": "^4.1.0-beta.7"
28
29
  },