@tachybase/module-auth 0.23.8
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/.turbo/turbo-build.log +14 -0
- package/README.md +117 -0
- package/client.d.ts +2 -0
- package/client.js +65 -0
- package/dist/client/AuthProvider.d.ts +2 -0
- package/dist/client/authenticator.d.ts +12 -0
- package/dist/client/basic/Options.d.ts +2 -0
- package/dist/client/basic/SignInForm.d.ts +9 -0
- package/dist/client/basic/SignUpForm.d.ts +13 -0
- package/dist/client/basic/index.d.ts +3 -0
- package/dist/client/bind/AuthenticatorBind.d.ts +2 -0
- package/dist/client/bind/BindForm.d.ts +5 -0
- package/dist/client/bind/schemas/authenticators.d.ts +2 -0
- package/dist/client/index.d.ts +30 -0
- package/dist/client/index.js +22 -0
- package/dist/client/locale/index.d.ts +2 -0
- package/dist/client/pages/AuthLayout.d.ts +2 -0
- package/dist/client/pages/SignInPage.d.ts +13 -0
- package/dist/client/pages/SignUpPage.d.ts +20 -0
- package/dist/client/pages/index.d.ts +3 -0
- package/dist/client/settings/Authenticator.d.ts +2 -0
- package/dist/client/settings/Options.d.ts +4 -0
- package/dist/client/settings/authType.d.ts +15 -0
- package/dist/client/settings/schemas/authenticators.d.ts +3 -0
- package/dist/externalVersion.js +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -0
- package/dist/locale/en-US.json +31 -0
- package/dist/locale/ko_KR.json +26 -0
- package/dist/locale/zh-CN.json +31 -0
- package/dist/node_modules/cron/LICENSE +8 -0
- package/dist/node_modules/cron/dist/constants.d.ts +74 -0
- package/dist/node_modules/cron/dist/constants.js +78 -0
- package/dist/node_modules/cron/dist/errors.d.ts +5 -0
- package/dist/node_modules/cron/dist/errors.js +13 -0
- package/dist/node_modules/cron/dist/index.d.ts +6 -0
- package/dist/node_modules/cron/dist/index.js +1 -0
- package/dist/node_modules/cron/dist/job.d.ts +30 -0
- package/dist/node_modules/cron/dist/job.js +222 -0
- package/dist/node_modules/cron/dist/time.d.ts +33 -0
- package/dist/node_modules/cron/dist/time.js +444 -0
- package/dist/node_modules/cron/dist/types/cron.types.d.ts +50 -0
- package/dist/node_modules/cron/dist/types/cron.types.js +3 -0
- package/dist/node_modules/cron/dist/types/utils.d.ts +3 -0
- package/dist/node_modules/cron/dist/types/utils.js +3 -0
- package/dist/node_modules/cron/dist/utils.d.ts +2 -0
- package/dist/node_modules/cron/dist/utils.js +8 -0
- package/dist/node_modules/cron/package.json +1 -0
- package/dist/preset.d.ts +3 -0
- package/dist/preset.js +34 -0
- package/dist/server/actions/auth.d.ts +8 -0
- package/dist/server/actions/auth.js +40 -0
- package/dist/server/actions/authenticators.d.ts +10 -0
- package/dist/server/actions/authenticators.js +153 -0
- package/dist/server/basic-auth.d.ts +10 -0
- package/dist/server/basic-auth.js +176 -0
- package/dist/server/collections/authenticators.d.ts +5 -0
- package/dist/server/collections/authenticators.js +117 -0
- package/dist/server/collections/token-blacklist.d.ts +2 -0
- package/dist/server/collections/token-blacklist.js +42 -0
- package/dist/server/collections/users-authenticators.d.ts +6 -0
- package/dist/server/collections/users-authenticators.js +85 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +42 -0
- package/dist/server/locale/en-US.d.ts +9 -0
- package/dist/server/locale/en-US.js +30 -0
- package/dist/server/locale/fr-FR.d.ts +9 -0
- package/dist/server/locale/fr-FR.js +30 -0
- package/dist/server/locale/index.d.ts +3 -0
- package/dist/server/locale/index.js +43 -0
- package/dist/server/locale/ja-JP.d.ts +5 -0
- package/dist/server/locale/ja-JP.js +26 -0
- package/dist/server/locale/pt-BR.d.ts +9 -0
- package/dist/server/locale/pt-BR.js +30 -0
- package/dist/server/locale/zh-CN.d.ts +11 -0
- package/dist/server/locale/zh-CN.js +32 -0
- package/dist/server/migrations/20230506152253-basic-authenticator.d.ts +6 -0
- package/dist/server/migrations/20230506152253-basic-authenticator.js +44 -0
- package/dist/server/migrations/20230607174500-update-basic.d.ts +6 -0
- package/dist/server/migrations/20230607174500-update-basic.js +47 -0
- package/dist/server/migrations/20231218132032-fix-allow-signup.d.ts +6 -0
- package/dist/server/migrations/20231218132032-fix-allow-signup.js +55 -0
- package/dist/server/model/authenticator.d.ts +10 -0
- package/dist/server/model/authenticator.js +81 -0
- package/dist/server/plugin.d.ts +11 -0
- package/dist/server/plugin.js +132 -0
- package/dist/server/storer.d.ts +16 -0
- package/dist/server/storer.js +69 -0
- package/dist/server/token-blacklist.d.ts +17 -0
- package/dist/server/token-blacklist.js +86 -0
- package/dist/swagger/index.d.ts +754 -0
- package/dist/swagger/index.js +787 -0
- package/package.json +34 -0
- package/server.d.ts +2 -0
- package/server.js +65 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SpawnOptions } from 'child_process';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
import { CONSTRAINTS, TIME_UNITS_MAP } from '../constants';
|
|
4
|
+
import { CronJob } from '../job';
|
|
5
|
+
import { IntRange } from './utils';
|
|
6
|
+
interface BaseCronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> {
|
|
7
|
+
cronTime: string | Date | DateTime;
|
|
8
|
+
onTick: CronCommand<C, WithOnComplete<OC>>;
|
|
9
|
+
onComplete?: OC;
|
|
10
|
+
start?: boolean | null;
|
|
11
|
+
context?: C;
|
|
12
|
+
runOnInit?: boolean | null;
|
|
13
|
+
unrefTimeout?: boolean | null;
|
|
14
|
+
waitForCompletion?: boolean | null;
|
|
15
|
+
}
|
|
16
|
+
export type CronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> = BaseCronJobParams<OC, C> & ({
|
|
17
|
+
timeZone?: string | null;
|
|
18
|
+
utcOffset?: never;
|
|
19
|
+
} | {
|
|
20
|
+
timeZone?: never;
|
|
21
|
+
utcOffset?: number | null;
|
|
22
|
+
});
|
|
23
|
+
export type CronContext<C> = C extends null ? CronJob : NonNullable<C>;
|
|
24
|
+
export type CronCallback<C, WithOnCompleteBool extends boolean = false> = (this: CronContext<C>, onComplete: WithOnCompleteBool extends true ? CronOnCompleteCallback : never) => void | Promise<void>;
|
|
25
|
+
export type CronOnCompleteCallback = () => void | Promise<void>;
|
|
26
|
+
export type CronSystemCommand = string | {
|
|
27
|
+
command: string;
|
|
28
|
+
args?: readonly string[] | null;
|
|
29
|
+
options?: SpawnOptions | null;
|
|
30
|
+
};
|
|
31
|
+
export type CronCommand<C, WithOnCompleteBool extends boolean = false> = CronCallback<C, WithOnCompleteBool> | CronSystemCommand;
|
|
32
|
+
export type CronOnCompleteCommand = CronOnCompleteCallback | CronSystemCommand;
|
|
33
|
+
export type WithOnComplete<OC> = OC extends null ? false : true;
|
|
34
|
+
export type TimeUnit = (typeof TIME_UNITS_MAP)[keyof typeof TIME_UNITS_MAP];
|
|
35
|
+
export type TimeUnitField<T extends TimeUnit> = Partial<Record<Ranges[T], boolean>>;
|
|
36
|
+
export interface Ranges {
|
|
37
|
+
second: SecondRange;
|
|
38
|
+
minute: MinuteRange;
|
|
39
|
+
hour: HourRange;
|
|
40
|
+
dayOfMonth: DayOfMonthRange;
|
|
41
|
+
month: MonthRange;
|
|
42
|
+
dayOfWeek: DayOfWeekRange;
|
|
43
|
+
}
|
|
44
|
+
export type SecondRange = IntRange<(typeof CONSTRAINTS)['second'][0], (typeof CONSTRAINTS)['second'][1]>;
|
|
45
|
+
export type MinuteRange = IntRange<(typeof CONSTRAINTS)['minute'][0], (typeof CONSTRAINTS)['minute'][1]>;
|
|
46
|
+
export type HourRange = IntRange<(typeof CONSTRAINTS)['hour'][0], (typeof CONSTRAINTS)['hour'][1]>;
|
|
47
|
+
export type DayOfMonthRange = IntRange<(typeof CONSTRAINTS)['dayOfMonth'][0], (typeof CONSTRAINTS)['dayOfMonth'][1]>;
|
|
48
|
+
export type MonthRange = IntRange<(typeof CONSTRAINTS)['month'][0], (typeof CONSTRAINTS)['month'][1]>;
|
|
49
|
+
export type DayOfWeekRange = IntRange<(typeof CONSTRAINTS)['dayOfWeek'][0], (typeof CONSTRAINTS)['dayOfWeek'][1]>;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F, false>>;
|
|
2
|
+
type Enumerate<N extends number, WithTail extends boolean = true, Acc extends number[] = []> = Acc['length'] extends N ? WithTail extends true ? [...Acc, Acc['length']][number] : Acc[number] : Enumerate<N, WithTail, [...Acc, Acc['length']]>;
|
|
3
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"cron","description":"Cron jobs for your node","version":"3.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc -b tsconfig.build.json","lint:eslint":"eslint src/ tests/","lint:prettier":"prettier ./**/*.{json,md,yml} --check","lint":"npm run lint:eslint && npm run lint:prettier","lint:fix":"npm run lint:eslint -- --fix && npm run lint:prettier -- --write","test":"jest --coverage","test:watch":"jest --watch --coverage","test:fuzz":"jest --testMatch='**/*.fuzz.ts' --coverage=false --testTimeout=120000","prepare":"husky"},"dependencies":{"@types/luxon":"~3.4.0","luxon":"~3.5.0"},"devDependencies":{"@commitlint/cli":"19.6.0","@eslint/js":"^9.14.0","@fast-check/jest":"2.0.3","@insurgent/commitlint-config":"20.0.0","@insurgent/conventional-changelog-preset":"10.0.0","@semantic-release/changelog":"6.0.3","@semantic-release/commit-analyzer":"13.0.0","@semantic-release/git":"10.0.1","@semantic-release/github":"11.0.1","@semantic-release/npm":"12.0.1","@semantic-release/release-notes-generator":"14.0.1","@types/jest":"29.5.14","@types/node":"20.17.9","@types/sinon":"17.0.3","chai":"4.5.0","eslint":"8.57.1","eslint-config-prettier":"9.1.0","eslint-plugin-jest":"27.9.0","eslint-plugin-prettier":"5.2.1","husky":"9.1.7","jest":"29.7.0","lint-staged":"15.2.10","prettier":"3.3.3","semantic-release":"24.2.0","sinon":"17.0.2","ts-jest":"29.2.5","typescript":"5.7.2","typescript-eslint":"^7.2.0"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Pierre Cavin <me@sherlox.io> (https://github.com/sheerlox)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"files":["dist/**/*.js","dist/**/*.d.ts","CHANGELOG.md","LICENSE","README.md"],"lint-staged":{"*.ts":"eslint src/ tests/ --fix","*.{json,md,yml}":"prettier ./**/*.{json,md,yml} --check --write"},"_lastModified":"2024-12-22T16:00:19.678Z"}
|
package/dist/preset.d.ts
ADDED
package/dist/preset.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name2 in all)
|
|
7
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var preset_exports = {};
|
|
19
|
+
__export(preset_exports, {
|
|
20
|
+
namespace: () => namespace,
|
|
21
|
+
presetAuthType: () => presetAuthType,
|
|
22
|
+
presetAuthenticator: () => presetAuthenticator
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(preset_exports);
|
|
25
|
+
var import_package = require("../package.json");
|
|
26
|
+
const presetAuthType = "Email/Password";
|
|
27
|
+
const presetAuthenticator = "basic";
|
|
28
|
+
const namespace = import_package.name;
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
namespace,
|
|
32
|
+
presetAuthType,
|
|
33
|
+
presetAuthenticator
|
|
34
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Context, Next } from '@tachybase/actions';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
lostPassword: (ctx: Context, next: Next) => Promise<void>;
|
|
4
|
+
resetPassword: (ctx: Context, next: Next) => Promise<void>;
|
|
5
|
+
getUserByResetToken: (ctx: Context, next: Next) => Promise<void>;
|
|
6
|
+
changePassword: (ctx: Context, next: Next) => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var auth_exports = {};
|
|
19
|
+
__export(auth_exports, {
|
|
20
|
+
default: () => auth_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(auth_exports);
|
|
23
|
+
var auth_default = {
|
|
24
|
+
lostPassword: async (ctx, next) => {
|
|
25
|
+
ctx.body = await ctx.auth.lostPassword();
|
|
26
|
+
await next();
|
|
27
|
+
},
|
|
28
|
+
resetPassword: async (ctx, next) => {
|
|
29
|
+
ctx.body = await ctx.auth.resetPassword();
|
|
30
|
+
await next();
|
|
31
|
+
},
|
|
32
|
+
getUserByResetToken: async (ctx, next) => {
|
|
33
|
+
ctx.body = await ctx.auth.getUserByResetToken();
|
|
34
|
+
await next();
|
|
35
|
+
},
|
|
36
|
+
changePassword: async (ctx, next) => {
|
|
37
|
+
ctx.body = await ctx.auth.changePassword();
|
|
38
|
+
await next();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context, Next } from '@tachybase/actions';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
listTypes: (ctx: Context, next: Next) => Promise<void>;
|
|
4
|
+
publicList: (ctx: Context, next: Next) => Promise<void>;
|
|
5
|
+
destroy: (ctx: Context, next: Next) => Promise<void>;
|
|
6
|
+
update: (ctx: Context, next: Next) => Promise<void>;
|
|
7
|
+
bindTypes: (ctx: Context, next: Next) => Promise<any>;
|
|
8
|
+
unbind: (ctx: Context, next: Next) => Promise<any>;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var authenticators_exports = {};
|
|
19
|
+
__export(authenticators_exports, {
|
|
20
|
+
default: () => authenticators_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(authenticators_exports);
|
|
23
|
+
var import_preset = require("../../preset");
|
|
24
|
+
async function checkCount(repository, id) {
|
|
25
|
+
const count = await repository.count({
|
|
26
|
+
filter: {
|
|
27
|
+
enabled: true,
|
|
28
|
+
id: {
|
|
29
|
+
$ne: id
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (count <= 0) {
|
|
34
|
+
throw new Error("Please keep and enable at least one authenticator");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
var authenticators_default = {
|
|
38
|
+
listTypes: async (ctx, next) => {
|
|
39
|
+
ctx.body = ctx.app.authManager.listTypes();
|
|
40
|
+
await next();
|
|
41
|
+
},
|
|
42
|
+
publicList: async (ctx, next) => {
|
|
43
|
+
const repo = ctx.db.getRepository("authenticators");
|
|
44
|
+
const authManager = ctx.app.authManager;
|
|
45
|
+
const authenticators = await repo.find({
|
|
46
|
+
fields: ["name", "authType", "title", "options", "sort"],
|
|
47
|
+
filter: {
|
|
48
|
+
enabled: true
|
|
49
|
+
},
|
|
50
|
+
sort: "sort"
|
|
51
|
+
});
|
|
52
|
+
ctx.body = authenticators.map((authenticator) => {
|
|
53
|
+
var _a;
|
|
54
|
+
const authType = authManager.getAuthConfig(authenticator.authType);
|
|
55
|
+
return {
|
|
56
|
+
name: authenticator.name,
|
|
57
|
+
authType: authenticator.authType,
|
|
58
|
+
authTypeTitle: (authType == null ? void 0 : authType.title) || "",
|
|
59
|
+
title: authenticator.title,
|
|
60
|
+
options: ((_a = authenticator.options) == null ? void 0 : _a.public) || {}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
await next();
|
|
64
|
+
},
|
|
65
|
+
destroy: async (ctx, next) => {
|
|
66
|
+
const repository = ctx.db.getRepository("authenticators");
|
|
67
|
+
const { filterByTk, filter } = ctx.action.params;
|
|
68
|
+
try {
|
|
69
|
+
await checkCount(repository, filterByTk);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
ctx.throw(400, ctx.t(err.message, { ns: import_preset.namespace }));
|
|
72
|
+
}
|
|
73
|
+
const instance = await repository.destroy({
|
|
74
|
+
filter,
|
|
75
|
+
filterByTk,
|
|
76
|
+
context: ctx
|
|
77
|
+
});
|
|
78
|
+
ctx.body = instance;
|
|
79
|
+
await next();
|
|
80
|
+
},
|
|
81
|
+
update: async (ctx, next) => {
|
|
82
|
+
const repository = ctx.db.getRepository("authenticators");
|
|
83
|
+
const { forceUpdate, filterByTk, values, whitelist, blacklist, filter, updateAssociationValues } = ctx.action.params;
|
|
84
|
+
if (!values.enabled) {
|
|
85
|
+
try {
|
|
86
|
+
await checkCount(repository, values.id);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
ctx.throw(400, ctx.t(err.message, { ns: import_preset.namespace }));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
ctx.body = await repository.update({
|
|
92
|
+
filterByTk,
|
|
93
|
+
values,
|
|
94
|
+
whitelist,
|
|
95
|
+
blacklist,
|
|
96
|
+
filter,
|
|
97
|
+
updateAssociationValues,
|
|
98
|
+
context: ctx,
|
|
99
|
+
forceUpdate
|
|
100
|
+
});
|
|
101
|
+
await next();
|
|
102
|
+
},
|
|
103
|
+
bindTypes: async (ctx, next) => {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
const userId = (_b = (_a = ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id;
|
|
106
|
+
if (!userId) {
|
|
107
|
+
ctx.throw(400, ctx.t("User not found", { ns: import_preset.namespace }));
|
|
108
|
+
}
|
|
109
|
+
const repository = ctx.db.getRepository("authenticators");
|
|
110
|
+
const list = await repository.find({
|
|
111
|
+
fields: ["name", "authType", "title", "description", "sort"],
|
|
112
|
+
filter: {
|
|
113
|
+
enabled: true,
|
|
114
|
+
"options.public.configBind": true
|
|
115
|
+
},
|
|
116
|
+
sort: "sort",
|
|
117
|
+
raw: true
|
|
118
|
+
});
|
|
119
|
+
if (!list.length) {
|
|
120
|
+
ctx.body = list;
|
|
121
|
+
return next();
|
|
122
|
+
}
|
|
123
|
+
const nameList = list.map((item) => item.name);
|
|
124
|
+
const thirdRepo = ctx.db.getRepository("usersAuthenticators");
|
|
125
|
+
const userInfo = await thirdRepo.find({
|
|
126
|
+
fields: ["authenticator", "nickname"],
|
|
127
|
+
filter: {
|
|
128
|
+
userId,
|
|
129
|
+
authenticator: {
|
|
130
|
+
$in: nameList
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
raw: true
|
|
134
|
+
});
|
|
135
|
+
for (const item of list) {
|
|
136
|
+
const userItem = userInfo.find((info) => info.authenticator === item.name);
|
|
137
|
+
item.bind = userItem ? true : false;
|
|
138
|
+
item.nickname = userItem ? userItem.nickname : "";
|
|
139
|
+
}
|
|
140
|
+
ctx.body = list;
|
|
141
|
+
await next();
|
|
142
|
+
},
|
|
143
|
+
unbind: async (ctx, next) => {
|
|
144
|
+
var _a, _b;
|
|
145
|
+
const userId = (_b = (_a = ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id;
|
|
146
|
+
const { authenticator } = ctx.action.params;
|
|
147
|
+
if (!userId) {
|
|
148
|
+
ctx.throw(400, ctx.t("User not found", { ns: import_preset.namespace }));
|
|
149
|
+
}
|
|
150
|
+
await ctx.db.getRepository("authenticators.users", authenticator).remove([userId]);
|
|
151
|
+
return next();
|
|
152
|
+
}
|
|
153
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthConfig, BaseAuth } from '@tachybase/auth';
|
|
2
|
+
export declare class BasicAuth extends BaseAuth {
|
|
3
|
+
constructor(config: AuthConfig);
|
|
4
|
+
validate(): Promise<any>;
|
|
5
|
+
signUp(): Promise<any>;
|
|
6
|
+
lostPassword(): Promise<any>;
|
|
7
|
+
resetPassword(): Promise<any>;
|
|
8
|
+
getUserByResetToken(): Promise<any>;
|
|
9
|
+
changePassword(): Promise<any>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var basic_auth_exports = {};
|
|
29
|
+
__export(basic_auth_exports, {
|
|
30
|
+
BasicAuth: () => BasicAuth
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(basic_auth_exports);
|
|
33
|
+
var import_crypto = __toESM(require("crypto"));
|
|
34
|
+
var import_auth = require("@tachybase/auth");
|
|
35
|
+
var import_preset = require("../preset");
|
|
36
|
+
class BasicAuth extends import_auth.BaseAuth {
|
|
37
|
+
constructor(config) {
|
|
38
|
+
const userCollection = config.ctx.db.getCollection("users");
|
|
39
|
+
super({ ...config, userCollection });
|
|
40
|
+
}
|
|
41
|
+
async validate() {
|
|
42
|
+
const ctx = this.ctx;
|
|
43
|
+
const {
|
|
44
|
+
values: {
|
|
45
|
+
account,
|
|
46
|
+
// Username or email
|
|
47
|
+
email,
|
|
48
|
+
// Old parameter, compatible with old api
|
|
49
|
+
password
|
|
50
|
+
}
|
|
51
|
+
} = ctx.action.params;
|
|
52
|
+
if (!account && !email) {
|
|
53
|
+
ctx.throw(400, ctx.t("Please enter your username or email", { ns: import_preset.namespace }));
|
|
54
|
+
}
|
|
55
|
+
const filter = email ? { email } : {
|
|
56
|
+
$or: [{ username: account }, { email: account }]
|
|
57
|
+
};
|
|
58
|
+
const user = await this.userRepository.findOne({
|
|
59
|
+
filter
|
|
60
|
+
});
|
|
61
|
+
if (!user) {
|
|
62
|
+
ctx.throw(401, ctx.t("The username or email is incorrect, please re-enter", { ns: import_preset.namespace }));
|
|
63
|
+
}
|
|
64
|
+
const field = this.userCollection.getField("password");
|
|
65
|
+
const valid = await field.verify(password, user.password);
|
|
66
|
+
if (!valid) {
|
|
67
|
+
ctx.throw(401, ctx.t("The password is incorrect, please re-enter", { ns: import_preset.namespace }));
|
|
68
|
+
}
|
|
69
|
+
return user;
|
|
70
|
+
}
|
|
71
|
+
async signUp() {
|
|
72
|
+
var _a;
|
|
73
|
+
const ctx = this.ctx;
|
|
74
|
+
const options = ((_a = this.authenticator.options) == null ? void 0 : _a.public) || {};
|
|
75
|
+
if (!options.allowSignUp) {
|
|
76
|
+
ctx.throw(403, ctx.t("Not allowed to sign up", { ns: import_preset.namespace }));
|
|
77
|
+
}
|
|
78
|
+
const User = ctx.db.getRepository("users");
|
|
79
|
+
const { values } = ctx.action.params;
|
|
80
|
+
const { username, password, confirm_password } = values;
|
|
81
|
+
if (!/^[^@.<>"'/]{2,16}$/.test(username)) {
|
|
82
|
+
ctx.throw(400, ctx.t("Please enter a valid username", { ns: import_preset.namespace }));
|
|
83
|
+
}
|
|
84
|
+
if (password !== confirm_password) {
|
|
85
|
+
ctx.throw(400, ctx.t("The password is inconsistent, please re-enter", { ns: import_preset.namespace }));
|
|
86
|
+
}
|
|
87
|
+
const user = await User.create({ values: { username, password } });
|
|
88
|
+
return user;
|
|
89
|
+
}
|
|
90
|
+
async lostPassword() {
|
|
91
|
+
const ctx = this.ctx;
|
|
92
|
+
const {
|
|
93
|
+
values: { email }
|
|
94
|
+
} = ctx.action.params;
|
|
95
|
+
if (!email) {
|
|
96
|
+
ctx.throw(400, ctx.t("Please fill in your email address", { ns: import_preset.namespace }));
|
|
97
|
+
}
|
|
98
|
+
const user = await this.userRepository.findOne({
|
|
99
|
+
where: {
|
|
100
|
+
email
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
if (!user) {
|
|
104
|
+
ctx.throw(401, ctx.t("The email is incorrect, please re-enter", { ns: import_preset.namespace }));
|
|
105
|
+
}
|
|
106
|
+
user.resetToken = import_crypto.default.randomBytes(20).toString("hex");
|
|
107
|
+
await user.save();
|
|
108
|
+
return user;
|
|
109
|
+
}
|
|
110
|
+
async resetPassword() {
|
|
111
|
+
const ctx = this.ctx;
|
|
112
|
+
const {
|
|
113
|
+
values: { email, password, resetToken }
|
|
114
|
+
} = ctx.action.params;
|
|
115
|
+
const user = await this.userRepository.findOne({
|
|
116
|
+
where: {
|
|
117
|
+
email,
|
|
118
|
+
resetToken
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (!user) {
|
|
122
|
+
ctx.throw(404);
|
|
123
|
+
}
|
|
124
|
+
user.token = null;
|
|
125
|
+
user.resetToken = null;
|
|
126
|
+
user.password = password;
|
|
127
|
+
await user.save();
|
|
128
|
+
return user;
|
|
129
|
+
}
|
|
130
|
+
async getUserByResetToken() {
|
|
131
|
+
const ctx = this.ctx;
|
|
132
|
+
const { token } = ctx.action.params;
|
|
133
|
+
const user = await this.userRepository.findOne({
|
|
134
|
+
where: {
|
|
135
|
+
resetToken: token
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (!user) {
|
|
139
|
+
ctx.throw(401);
|
|
140
|
+
}
|
|
141
|
+
return user;
|
|
142
|
+
}
|
|
143
|
+
async changePassword() {
|
|
144
|
+
const ctx = this.ctx;
|
|
145
|
+
const {
|
|
146
|
+
values: { oldPassword, newPassword }
|
|
147
|
+
} = ctx.action.params;
|
|
148
|
+
const currentUser = ctx.auth.user;
|
|
149
|
+
if (!currentUser) {
|
|
150
|
+
ctx.throw(401);
|
|
151
|
+
}
|
|
152
|
+
let key;
|
|
153
|
+
if (currentUser.username) {
|
|
154
|
+
key = "username";
|
|
155
|
+
} else {
|
|
156
|
+
key = "email";
|
|
157
|
+
}
|
|
158
|
+
const user = await this.userRepository.findOne({
|
|
159
|
+
where: {
|
|
160
|
+
[key]: currentUser[key]
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const pwd = this.userCollection.getField("password");
|
|
164
|
+
const isValid = await pwd.verify(oldPassword, user.password);
|
|
165
|
+
if (!isValid) {
|
|
166
|
+
ctx.throw(401, ctx.t("The password is incorrect, please re-enter", { ns: import_preset.namespace }));
|
|
167
|
+
}
|
|
168
|
+
user.password = newPassword;
|
|
169
|
+
await user.save();
|
|
170
|
+
return currentUser;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
174
|
+
0 && (module.exports = {
|
|
175
|
+
BasicAuth
|
|
176
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var authenticators_exports = {};
|
|
19
|
+
__export(authenticators_exports, {
|
|
20
|
+
default: () => authenticators_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(authenticators_exports);
|
|
23
|
+
var import_database = require("@tachybase/database");
|
|
24
|
+
var authenticators_default = (0, import_database.defineCollection)({
|
|
25
|
+
dumpRules: {
|
|
26
|
+
group: "third-party"
|
|
27
|
+
},
|
|
28
|
+
shared: true,
|
|
29
|
+
name: "authenticators",
|
|
30
|
+
sortable: true,
|
|
31
|
+
model: "AuthModel",
|
|
32
|
+
createdBy: true,
|
|
33
|
+
updatedBy: true,
|
|
34
|
+
logging: true,
|
|
35
|
+
fields: [
|
|
36
|
+
{
|
|
37
|
+
name: "id",
|
|
38
|
+
type: "bigInt",
|
|
39
|
+
autoIncrement: true,
|
|
40
|
+
primaryKey: true,
|
|
41
|
+
allowNull: false,
|
|
42
|
+
interface: "id"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
interface: "input",
|
|
46
|
+
type: "string",
|
|
47
|
+
name: "name",
|
|
48
|
+
allowNull: false,
|
|
49
|
+
unique: true,
|
|
50
|
+
uiSchema: {
|
|
51
|
+
type: "string",
|
|
52
|
+
title: '{{t("Name")}}',
|
|
53
|
+
"x-component": "Input",
|
|
54
|
+
required: true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
interface: "input",
|
|
59
|
+
type: "string",
|
|
60
|
+
name: "authType",
|
|
61
|
+
allowNull: false,
|
|
62
|
+
uiSchema: {
|
|
63
|
+
type: "string",
|
|
64
|
+
title: '{{t("Auth Type")}}',
|
|
65
|
+
"x-component": "Input",
|
|
66
|
+
required: true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
interface: "input",
|
|
71
|
+
type: "string",
|
|
72
|
+
name: "title",
|
|
73
|
+
uiSchema: {
|
|
74
|
+
type: "string",
|
|
75
|
+
title: '{{t("Title")}}',
|
|
76
|
+
"x-component": "Input"
|
|
77
|
+
},
|
|
78
|
+
translation: true
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
interface: "textarea",
|
|
82
|
+
type: "string",
|
|
83
|
+
name: "description",
|
|
84
|
+
allowNull: false,
|
|
85
|
+
defaultValue: "",
|
|
86
|
+
uiSchema: {
|
|
87
|
+
type: "string",
|
|
88
|
+
title: '{{t("Description")}}',
|
|
89
|
+
"x-component": "Input",
|
|
90
|
+
required: true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
type: "json",
|
|
95
|
+
name: "options",
|
|
96
|
+
allowNull: false,
|
|
97
|
+
defaultValue: {}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: "boolean",
|
|
101
|
+
name: "enabled",
|
|
102
|
+
defaultValue: false
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
interface: "m2m",
|
|
106
|
+
type: "belongsToMany",
|
|
107
|
+
name: "users",
|
|
108
|
+
target: "users",
|
|
109
|
+
foreignKey: "authenticator",
|
|
110
|
+
otherKey: "userId",
|
|
111
|
+
onDelete: "CASCADE",
|
|
112
|
+
sourceKey: "name",
|
|
113
|
+
targetKey: "id",
|
|
114
|
+
through: "usersAuthenticators"
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
});
|