@nocobase/plugin-verification 1.7.0-beta.8 → 1.7.0
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/dist/client/83b24f85ae99a175.js +10 -0
- package/dist/client/937c9eccebc38607.js +10 -0
- package/dist/client/{providerTypes/index.d.ts → VerificationMenu.d.ts} +5 -4
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +1 -1
- package/dist/client/locale/index.d.ts +1 -1
- package/dist/client/otp-verification/VerificationCode.d.ts +16 -0
- package/dist/client/otp-verification/sms/AdminSettingsForm.d.ts +12 -0
- package/dist/client/otp-verification/sms/BindForm.d.ts +11 -0
- package/dist/client/otp-verification/sms/VerificationForm.d.ts +11 -0
- package/dist/client/otp-verification/sms/index.d.ts +26 -0
- package/dist/client/otp-verification/sms/provider-manager.d.ts +19 -0
- package/dist/client/{VerificationProviders.d.ts → otp-verification/sms/providers/AliyunSettings.d.ts} +1 -1
- package/dist/{server/actions/index.d.ts → client/otp-verification/sms/providers/TencentSettings.d.ts} +2 -3
- package/dist/client/schemas/verifiers.d.ts +66 -0
- package/dist/client/verification-manager/index.d.ts +32 -0
- package/dist/client/{ProviderOptions.d.ts → verifiers/VerifierSelect.d.ts} +1 -2
- package/dist/client/verifiers/Verifiers.d.ts +12 -0
- package/dist/client/verifiers/verification-types.d.ts +24 -0
- package/dist/collections/verificators.d.ts +50 -0
- package/dist/collections/verificators.js +70 -0
- package/dist/collections/verifiers.d.ts +50 -0
- package/dist/collections/verifiers.js +70 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +42 -0
- package/dist/externalVersion.js +14 -13
- package/dist/locale/en-US.json +18 -1
- package/dist/locale/zh-CN.json +20 -2
- package/dist/node_modules/@alicloud/dysmsapi20170525/dist/client.js +2 -2
- package/dist/node_modules/@alicloud/dysmsapi20170525/package.json +1 -1
- package/dist/node_modules/@alicloud/openapi-client/dist/client.js +2 -2
- package/dist/node_modules/@alicloud/openapi-client/package.json +1 -1
- package/dist/node_modules/@alicloud/tea-util/dist/client.js +1 -1
- package/dist/node_modules/@alicloud/tea-util/package.json +1 -1
- package/dist/node_modules/tencentcloud-sdk-nodejs/package.json +1 -1
- package/dist/node_modules/tencentcloud-sdk-nodejs/tencentcloud/index.js +2 -2
- package/dist/server/Plugin.d.ts +8 -16
- package/dist/server/Plugin.js +68 -71
- package/dist/server/actions/verifiers.d.ts +18 -0
- package/dist/server/actions/verifiers.js +175 -0
- package/dist/server/{actions/verifications.d.ts → collections/otp-records.d.ts} +2 -2
- package/dist/server/collections/otp-records.js +75 -0
- package/dist/server/collections/users-verificators.d.ts +10 -0
- package/dist/server/collections/users-verificators.js +58 -0
- package/dist/server/collections/users-verifiers.d.ts +14 -0
- package/dist/server/collections/users-verifiers.js +58 -0
- package/dist/server/collections/verificators.d.ts +10 -0
- package/dist/server/{actions/index.js → collections/verificators.js} +10 -19
- package/dist/server/collections/verifiers.d.ts +10 -0
- package/dist/server/{providers/index.js → collections/verifiers.js} +10 -15
- package/dist/server/constants.d.ts +0 -2
- package/dist/server/constants.js +2 -8
- package/dist/server/index.d.ts +5 -2
- package/dist/server/index.js +12 -5
- package/dist/server/migrations/20250111192640-providers2verificators.d.ts +14 -0
- package/dist/server/migrations/20250111192640-providers2verificators.js +97 -0
- package/dist/server/migrations/20250507220644-fix-verifier-typo.d.ts +14 -0
- package/dist/server/migrations/20250507220644-fix-verifier-typo.js +86 -0
- package/dist/server/otp-verification/index.d.ts +26 -0
- package/dist/server/otp-verification/index.js +152 -0
- package/dist/server/otp-verification/sms/index.d.ts +37 -0
- package/dist/server/otp-verification/sms/index.js +87 -0
- package/dist/server/{providers/Provider.d.ts → otp-verification/sms/providers/index.d.ts} +2 -4
- package/dist/server/{providers/Provider.js → otp-verification/sms/providers/index.js} +8 -10
- package/dist/server/{providers → otp-verification/sms/providers}/sms-aliyun.d.ts +3 -3
- package/dist/server/{providers → otp-verification/sms/providers}/sms-aliyun.js +4 -4
- package/dist/server/{providers → otp-verification/sms/providers}/sms-tencent.d.ts +3 -3
- package/dist/server/{providers → otp-verification/sms/providers}/sms-tencent.js +4 -4
- package/dist/server/otp-verification/sms/resource/sms-otp-providers.d.ts +16 -0
- package/dist/server/otp-verification/sms/resource/sms-otp-providers.js +41 -0
- package/dist/server/otp-verification/sms/resource/sms-otp.d.ts +18 -0
- package/dist/server/otp-verification/sms/resource/sms-otp.js +141 -0
- package/dist/server/verification-manager.d.ts +68 -0
- package/dist/server/verification-manager.js +223 -0
- package/dist/server/verification.d.ts +70 -0
- package/dist/server/verification.js +70 -0
- package/package.json +8 -6
- package/dist/client/7551e1f2e04bca2f.js +0 -10
- package/dist/client/providerTypes/sms-aliyun.d.ts +0 -66
- package/dist/client/providerTypes/sms-tencent.d.ts +0 -66
- package/dist/server/actions/verifications.js +0 -146
- package/dist/server/providers/index.d.ts +0 -15
|
@@ -34,19 +34,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
mod
|
|
35
35
|
));
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
var
|
|
38
|
-
__export(
|
|
39
|
-
default: () =>
|
|
37
|
+
var verifiers_exports = {};
|
|
38
|
+
__export(verifiers_exports, {
|
|
39
|
+
default: () => verifiers_default
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(verifiers_exports);
|
|
42
|
+
var import_database = require("@nocobase/database");
|
|
43
|
+
var import_verifiers = __toESM(require("../../collections/verifiers"));
|
|
44
|
+
var verifiers_default = (0, import_database.defineCollection)({
|
|
45
|
+
migrationRules: ["overwrite", "skip"],
|
|
46
|
+
...import_verifiers.default
|
|
40
47
|
});
|
|
41
|
-
module.exports = __toCommonJS(providers_exports);
|
|
42
|
-
var import_constants = require("../constants");
|
|
43
|
-
var import_sms_aliyun = __toESM(require("./sms-aliyun"));
|
|
44
|
-
var import_sms_tencent = __toESM(require("./sms-tencent"));
|
|
45
|
-
async function providers_default(plugin, more = {}) {
|
|
46
|
-
const { providers } = plugin;
|
|
47
|
-
providers.register(import_constants.PROVIDER_TYPE_SMS_ALIYUN, import_sms_aliyun.default);
|
|
48
|
-
providers.register(import_constants.PROVIDER_TYPE_SMS_TENCENT, import_sms_tencent.default);
|
|
49
|
-
for (const [name, provider] of Object.entries({ ...more })) {
|
|
50
|
-
providers.register(name, provider);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -6,7 +6,5 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
export declare const PROVIDER_TYPE_SMS_ALIYUN = "sms-aliyun";
|
|
10
|
-
export declare const PROVIDER_TYPE_SMS_TENCENT = "sms-tencent";
|
|
11
9
|
export declare const CODE_STATUS_UNUSED = 0;
|
|
12
10
|
export declare const CODE_STATUS_USED = 1;
|
package/dist/server/constants.js
CHANGED
|
@@ -27,19 +27,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var constants_exports = {};
|
|
28
28
|
__export(constants_exports, {
|
|
29
29
|
CODE_STATUS_UNUSED: () => CODE_STATUS_UNUSED,
|
|
30
|
-
CODE_STATUS_USED: () => CODE_STATUS_USED
|
|
31
|
-
PROVIDER_TYPE_SMS_ALIYUN: () => PROVIDER_TYPE_SMS_ALIYUN,
|
|
32
|
-
PROVIDER_TYPE_SMS_TENCENT: () => PROVIDER_TYPE_SMS_TENCENT
|
|
30
|
+
CODE_STATUS_USED: () => CODE_STATUS_USED
|
|
33
31
|
});
|
|
34
32
|
module.exports = __toCommonJS(constants_exports);
|
|
35
|
-
const PROVIDER_TYPE_SMS_ALIYUN = "sms-aliyun";
|
|
36
|
-
const PROVIDER_TYPE_SMS_TENCENT = "sms-tencent";
|
|
37
33
|
const CODE_STATUS_UNUSED = 0;
|
|
38
34
|
const CODE_STATUS_USED = 1;
|
|
39
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
36
|
0 && (module.exports = {
|
|
41
37
|
CODE_STATUS_UNUSED,
|
|
42
|
-
CODE_STATUS_USED
|
|
43
|
-
PROVIDER_TYPE_SMS_ALIYUN,
|
|
44
|
-
PROVIDER_TYPE_SMS_TENCENT
|
|
38
|
+
CODE_STATUS_USED
|
|
45
39
|
});
|
package/dist/server/index.d.ts
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
export {
|
|
9
|
+
export { default } from './Plugin';
|
|
10
10
|
export * from './constants';
|
|
11
|
-
export {
|
|
11
|
+
export { SMSOTPVerification } from './otp-verification/sms';
|
|
12
|
+
export { Verification } from './verification';
|
|
13
|
+
export { VerificationManager } from './verification-manager';
|
|
14
|
+
export { SMSProvider } from './otp-verification/sms/providers';
|
|
12
15
|
export declare const namespace: string;
|
package/dist/server/index.js
CHANGED
|
@@ -37,8 +37,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
37
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
38
|
var server_exports = {};
|
|
39
39
|
__export(server_exports, {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
SMSOTPVerification: () => import_sms.SMSOTPVerification,
|
|
41
|
+
SMSProvider: () => import_providers.SMSProvider,
|
|
42
|
+
Verification: () => import_verification.Verification,
|
|
43
|
+
VerificationManager: () => import_verification_manager.VerificationManager,
|
|
42
44
|
default: () => import_Plugin.default,
|
|
43
45
|
namespace: () => namespace
|
|
44
46
|
});
|
|
@@ -46,12 +48,17 @@ module.exports = __toCommonJS(server_exports);
|
|
|
46
48
|
var import_package = require("../../package.json");
|
|
47
49
|
var import_Plugin = __toESM(require("./Plugin"));
|
|
48
50
|
__reExport(server_exports, require("./constants"), module.exports);
|
|
49
|
-
var
|
|
51
|
+
var import_sms = require("./otp-verification/sms");
|
|
52
|
+
var import_verification = require("./verification");
|
|
53
|
+
var import_verification_manager = require("./verification-manager");
|
|
54
|
+
var import_providers = require("./otp-verification/sms/providers");
|
|
50
55
|
const namespace = import_package.name;
|
|
51
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
57
|
0 && (module.exports = {
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
SMSOTPVerification,
|
|
59
|
+
SMSProvider,
|
|
60
|
+
Verification,
|
|
61
|
+
VerificationManager,
|
|
55
62
|
namespace,
|
|
56
63
|
...require("./constants")
|
|
57
64
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Migration } from '@nocobase/server';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
on: string;
|
|
12
|
+
appVersion: string;
|
|
13
|
+
up(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var providers2verificators_exports = {};
|
|
28
|
+
__export(providers2verificators_exports, {
|
|
29
|
+
default: () => providers2verificators_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(providers2verificators_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
var import_utils = require("@nocobase/utils");
|
|
34
|
+
var import_constants = require("../../constants");
|
|
35
|
+
class providers2verificators_default extends import_server.Migration {
|
|
36
|
+
on = "afterLoad";
|
|
37
|
+
// 'beforeLoad' or 'afterLoad'
|
|
38
|
+
appVersion = "<1.7.0";
|
|
39
|
+
async up() {
|
|
40
|
+
const verificatorsRepo = this.db.getRepository("verificators");
|
|
41
|
+
if (await verificatorsRepo.count()) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const repo = this.db.getRepository("verifications_providers");
|
|
45
|
+
if (!repo) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const providers = await this.db.getRepository("verifications_providers").find();
|
|
49
|
+
if (!providers.length) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const verificators = [];
|
|
53
|
+
let defaultVerificator;
|
|
54
|
+
providers.forEach((provider) => {
|
|
55
|
+
const verificator = {
|
|
56
|
+
name: `v_${(0, import_utils.uid)()}`,
|
|
57
|
+
title: provider.title,
|
|
58
|
+
verificationType: import_constants.SMS_OTP_VERIFICATION_TYPE,
|
|
59
|
+
options: {
|
|
60
|
+
provider: provider.type,
|
|
61
|
+
settings: provider.options
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
verificators.push(verificator);
|
|
65
|
+
if (provider.default) {
|
|
66
|
+
defaultVerificator = verificator;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (!defaultVerificator) {
|
|
70
|
+
defaultVerificator = verificators[0];
|
|
71
|
+
}
|
|
72
|
+
const smsAuth = await this.db.getRepository("authenticators").find({
|
|
73
|
+
filter: {
|
|
74
|
+
authType: "SMS"
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
await this.db.sequelize.transaction(async (transaction) => {
|
|
78
|
+
var _a;
|
|
79
|
+
const verificatorModel = this.db.getModel("verificators");
|
|
80
|
+
await verificatorModel.bulkCreate(verificators, { transaction });
|
|
81
|
+
for (const item of smsAuth) {
|
|
82
|
+
await item.update(
|
|
83
|
+
{
|
|
84
|
+
options: {
|
|
85
|
+
...item.options,
|
|
86
|
+
public: {
|
|
87
|
+
...(_a = item.options) == null ? void 0 : _a.public,
|
|
88
|
+
verificator: defaultVerificator == null ? void 0 : defaultVerificator.name
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{ transaction }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Migration } from '@nocobase/server';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
on: string;
|
|
12
|
+
appVersion: string;
|
|
13
|
+
up(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var fix_verifier_typo_exports = {};
|
|
28
|
+
__export(fix_verifier_typo_exports, {
|
|
29
|
+
default: () => fix_verifier_typo_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(fix_verifier_typo_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
class fix_verifier_typo_default extends import_server.Migration {
|
|
34
|
+
on = "afterLoad";
|
|
35
|
+
// 'beforeLoad' or 'afterLoad'
|
|
36
|
+
appVersion = "<1.7.0";
|
|
37
|
+
async up() {
|
|
38
|
+
const oldRepo = await this.db.getRepository("verificators");
|
|
39
|
+
const newRepo = await this.db.getRepository("verifiers");
|
|
40
|
+
const oldThroughRepo = await this.db.getRepository("usersVerificators");
|
|
41
|
+
const newThroughRepo = await this.db.getRepository("usersVerifiers");
|
|
42
|
+
await this.db.sequelize.transaction(async (transaction) => {
|
|
43
|
+
if (await newRepo.count({ transaction })) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const oldRecords = await oldRepo.find({ transaction });
|
|
47
|
+
if (!oldRecords.length) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const newRecords = oldRecords.map((record) => ({
|
|
51
|
+
createdAt: record.createdAt,
|
|
52
|
+
updatedAt: record.updatedAt,
|
|
53
|
+
name: record.name,
|
|
54
|
+
title: record.title,
|
|
55
|
+
verificationType: record.verificationType,
|
|
56
|
+
description: record.description,
|
|
57
|
+
options: record.options
|
|
58
|
+
}));
|
|
59
|
+
const model = await this.db.getModel("verifiers");
|
|
60
|
+
await model.bulkCreate(newRecords, {
|
|
61
|
+
transaction
|
|
62
|
+
});
|
|
63
|
+
if (await newThroughRepo.count({ transaction })) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const oldThroughRecords = await oldThroughRepo.find({ transaction });
|
|
67
|
+
if (!oldThroughRecords.length) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const newThroughRecords = oldThroughRecords.map((record) => ({
|
|
71
|
+
createdAt: record.createdAt,
|
|
72
|
+
updatedAt: record.updatedAt,
|
|
73
|
+
userId: record.userId,
|
|
74
|
+
uuid: record.uuid,
|
|
75
|
+
meta: record.meta,
|
|
76
|
+
verifier: record.verificator,
|
|
77
|
+
createdById: record.createdById,
|
|
78
|
+
updatedById: record.updatedById
|
|
79
|
+
}));
|
|
80
|
+
const throughModel = await this.db.getModel("usersVerifiers");
|
|
81
|
+
await throughModel.bulkCreate(newThroughRecords, {
|
|
82
|
+
transaction
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Verification } from '../verification';
|
|
10
|
+
export declare class OTPVerification extends Verification {
|
|
11
|
+
expiresIn: number;
|
|
12
|
+
maxVerifyAttempts: number;
|
|
13
|
+
verify({ resource, action, boundInfo, verifyParams }: {
|
|
14
|
+
resource: any;
|
|
15
|
+
action: any;
|
|
16
|
+
boundInfo: any;
|
|
17
|
+
verifyParams: any;
|
|
18
|
+
}): Promise<any>;
|
|
19
|
+
bind(userId: number, resource?: string, action?: string): Promise<{
|
|
20
|
+
uuid: string;
|
|
21
|
+
meta?: any;
|
|
22
|
+
}>;
|
|
23
|
+
onActionComplete({ verifyResult }: {
|
|
24
|
+
verifyResult: any;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var otp_verification_exports = {};
|
|
38
|
+
__export(otp_verification_exports, {
|
|
39
|
+
OTPVerification: () => OTPVerification
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(otp_verification_exports);
|
|
42
|
+
var import_verification = require("../verification");
|
|
43
|
+
var import_constants = require("../constants");
|
|
44
|
+
var import_package = __toESM(require("../../../package.json"));
|
|
45
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
46
|
+
class OTPVerification extends import_verification.Verification {
|
|
47
|
+
expiresIn = 120;
|
|
48
|
+
maxVerifyAttempts = 5;
|
|
49
|
+
async verify({ resource, action, boundInfo, verifyParams }) {
|
|
50
|
+
const { uuid: receiver } = boundInfo;
|
|
51
|
+
const code = verifyParams.code;
|
|
52
|
+
if (!code) {
|
|
53
|
+
return this.ctx.throw(400, "Verification code is invalid");
|
|
54
|
+
}
|
|
55
|
+
const plugin = this.ctx.app.pm.get("verification");
|
|
56
|
+
const counter = plugin.smsOTPCounter;
|
|
57
|
+
const key = `${resource}:${action}:${receiver}`;
|
|
58
|
+
let attempts = 0;
|
|
59
|
+
try {
|
|
60
|
+
attempts = await counter.get(key);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
this.ctx.logger.error(e.message, {
|
|
63
|
+
module: "verification",
|
|
64
|
+
submodule: "sms-otp",
|
|
65
|
+
method: "verify",
|
|
66
|
+
receiver,
|
|
67
|
+
action: `${resource}:${action}`
|
|
68
|
+
});
|
|
69
|
+
this.ctx.throw(500, "Internal Server Error");
|
|
70
|
+
}
|
|
71
|
+
if (attempts > this.maxVerifyAttempts) {
|
|
72
|
+
this.ctx.throw(
|
|
73
|
+
429,
|
|
74
|
+
this.ctx.t("Too many failed attempts. Please request a new verification code.", { ns: import_package.default.name })
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const repo = this.ctx.db.getRepository("otpRecords");
|
|
78
|
+
const item = await repo.findOne({
|
|
79
|
+
filter: {
|
|
80
|
+
receiver,
|
|
81
|
+
action: `${resource}:${action}`,
|
|
82
|
+
code,
|
|
83
|
+
expiresAt: {
|
|
84
|
+
$dateAfter: /* @__PURE__ */ new Date()
|
|
85
|
+
},
|
|
86
|
+
status: import_constants.CODE_STATUS_UNUSED,
|
|
87
|
+
verifierName: this.verifier.name
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
if (!item) {
|
|
91
|
+
let attempts2 = 0;
|
|
92
|
+
try {
|
|
93
|
+
let ttl = this.expiresIn * 1e3;
|
|
94
|
+
const record = await repo.findOne({
|
|
95
|
+
filter: {
|
|
96
|
+
action: `${resource}:${action}`,
|
|
97
|
+
receiver,
|
|
98
|
+
status: import_constants.CODE_STATUS_UNUSED,
|
|
99
|
+
expiresAt: {
|
|
100
|
+
$dateAfter: /* @__PURE__ */ new Date()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (record) {
|
|
105
|
+
ttl = (0, import_dayjs.default)(record.get("expiresAt")).diff((0, import_dayjs.default)());
|
|
106
|
+
}
|
|
107
|
+
attempts2 = await counter.incr(key, ttl);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
this.ctx.logger.error(e.message, {
|
|
110
|
+
module: "verification",
|
|
111
|
+
submodule: "totp-authenticator",
|
|
112
|
+
method: "verify",
|
|
113
|
+
receiver,
|
|
114
|
+
action: `${resource}:${action}`
|
|
115
|
+
});
|
|
116
|
+
this.ctx.throw(500, "Internal Server Error");
|
|
117
|
+
}
|
|
118
|
+
if (attempts2 > this.maxVerifyAttempts) {
|
|
119
|
+
this.ctx.throw(
|
|
120
|
+
429,
|
|
121
|
+
this.ctx.t("Too many failed attempts. Please request a new verification code", { ns: import_package.default.name })
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return this.ctx.throw(400, {
|
|
125
|
+
code: "InvalidVerificationCode",
|
|
126
|
+
message: this.ctx.t("Verification code is invalid", { ns: import_package.default.name })
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
await counter.reset(key);
|
|
130
|
+
return { codeInfo: item };
|
|
131
|
+
}
|
|
132
|
+
async bind(userId, resource, action) {
|
|
133
|
+
const { uuid, code } = this.ctx.action.params.values || {};
|
|
134
|
+
await this.verify({
|
|
135
|
+
resource: resource || "verifiers",
|
|
136
|
+
action: action || "bind",
|
|
137
|
+
boundInfo: { uuid },
|
|
138
|
+
verifyParams: { code }
|
|
139
|
+
});
|
|
140
|
+
return { uuid };
|
|
141
|
+
}
|
|
142
|
+
async onActionComplete({ verifyResult }) {
|
|
143
|
+
const { codeInfo } = verifyResult;
|
|
144
|
+
await codeInfo.update({
|
|
145
|
+
status: import_constants.CODE_STATUS_USED
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
151
|
+
OTPVerification
|
|
152
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Registry } from '@nocobase/utils';
|
|
10
|
+
import { OTPVerification } from '..';
|
|
11
|
+
import { SMSProvider } from './providers';
|
|
12
|
+
type SMSProviderOptions = {
|
|
13
|
+
title: string;
|
|
14
|
+
provider: typeof SMSProvider;
|
|
15
|
+
};
|
|
16
|
+
export declare class SMSOTPProviderManager {
|
|
17
|
+
providers: Registry<SMSProviderOptions>;
|
|
18
|
+
registerProvider(type: string, options: SMSProviderOptions): void;
|
|
19
|
+
listProviders(): {
|
|
20
|
+
name: string;
|
|
21
|
+
title: string;
|
|
22
|
+
}[];
|
|
23
|
+
}
|
|
24
|
+
export declare class SMSOTPVerification extends OTPVerification {
|
|
25
|
+
getProvider(): Promise<SMSProvider>;
|
|
26
|
+
getPublicBoundInfo(userId: number): Promise<{
|
|
27
|
+
bound: boolean;
|
|
28
|
+
publicInfo?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
bound: boolean;
|
|
31
|
+
publicInfo: string;
|
|
32
|
+
}>;
|
|
33
|
+
validateBoundInfo({ uuid: phone }: {
|
|
34
|
+
uuid: any;
|
|
35
|
+
}): Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var sms_exports = {};
|
|
28
|
+
__export(sms_exports, {
|
|
29
|
+
SMSOTPProviderManager: () => SMSOTPProviderManager,
|
|
30
|
+
SMSOTPVerification: () => SMSOTPVerification
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(sms_exports);
|
|
33
|
+
var import_utils = require("@nocobase/utils");
|
|
34
|
+
var import__ = require("..");
|
|
35
|
+
class SMSOTPProviderManager {
|
|
36
|
+
providers = new import_utils.Registry();
|
|
37
|
+
registerProvider(type, options) {
|
|
38
|
+
this.providers.register(type, options);
|
|
39
|
+
}
|
|
40
|
+
listProviders() {
|
|
41
|
+
return Array.from(this.providers.getEntities()).map(([providerType, options]) => ({
|
|
42
|
+
name: providerType,
|
|
43
|
+
title: options.title
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class SMSOTPVerification extends import__.OTPVerification {
|
|
48
|
+
async getProvider() {
|
|
49
|
+
const { provider: providerType, settings } = this.options;
|
|
50
|
+
if (!providerType) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const plugin = this.ctx.app.pm.get("verification");
|
|
54
|
+
const providerOptions = plugin.smsOTPProviderManager.providers.get(providerType);
|
|
55
|
+
if (!providerOptions) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const Provider = providerOptions.provider;
|
|
59
|
+
if (!Provider) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const options = this.ctx.app.environment.renderJsonTemplate(settings);
|
|
63
|
+
return new Provider(options);
|
|
64
|
+
}
|
|
65
|
+
async getPublicBoundInfo(userId) {
|
|
66
|
+
const boundInfo = await this.getBoundInfo(userId);
|
|
67
|
+
if (!boundInfo) {
|
|
68
|
+
return { bound: false };
|
|
69
|
+
}
|
|
70
|
+
const { uuid: phone } = boundInfo;
|
|
71
|
+
return {
|
|
72
|
+
bound: true,
|
|
73
|
+
publicInfo: "*".repeat(phone.length - 4) + phone.slice(-4)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async validateBoundInfo({ uuid: phone }) {
|
|
77
|
+
if (!phone) {
|
|
78
|
+
throw new Error(this.ctx.t("Not a valid cellphone number, please re-enter"));
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
SMSOTPProviderManager,
|
|
86
|
+
SMSOTPVerification
|
|
87
|
+
});
|
|
@@ -6,11 +6,9 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
export declare class Provider {
|
|
11
|
-
protected plugin: Plugin;
|
|
9
|
+
export declare class SMSProvider {
|
|
12
10
|
protected options: any;
|
|
13
|
-
constructor(
|
|
11
|
+
constructor(options: any);
|
|
14
12
|
send(receiver: string, data: {
|
|
15
13
|
[key: string]: any;
|
|
16
14
|
}): Promise<any>;
|
|
@@ -24,21 +24,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
return to;
|
|
25
25
|
};
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
var
|
|
28
|
-
__export(
|
|
29
|
-
|
|
27
|
+
var providers_exports = {};
|
|
28
|
+
__export(providers_exports, {
|
|
29
|
+
SMSProvider: () => SMSProvider
|
|
30
30
|
});
|
|
31
|
-
module.exports = __toCommonJS(
|
|
32
|
-
class
|
|
33
|
-
constructor(
|
|
34
|
-
this.
|
|
35
|
-
this.options = plugin.app.environment.renderJsonTemplate(options);
|
|
31
|
+
module.exports = __toCommonJS(providers_exports);
|
|
32
|
+
class SMSProvider {
|
|
33
|
+
constructor(options) {
|
|
34
|
+
this.options = options;
|
|
36
35
|
}
|
|
37
|
-
options;
|
|
38
36
|
async send(receiver, data) {
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42
40
|
0 && (module.exports = {
|
|
43
|
-
|
|
41
|
+
SMSProvider
|
|
44
42
|
});
|