@tachybase/module-auth 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,56 +1,63 @@
1
- {
2
- "Allow to sign in with": "允许使用以下方式登录",
3
- "Allow to sign up": "允许注册",
4
- "Are you sure to unbind this authenticator?": "确定要解绑该认证器吗?",
5
- "Auth Type": "认证类型",
6
- "Auth UID": "认证标识",
7
- "Authentication": "认证方式",
8
- "Authentication login bind": "认证登录绑定",
9
- "Authenticators": "认证器",
10
- "Bind": "绑定",
11
- "Days": "天",
12
- "Expired token refresh limit": "过期 Token 刷新时限",
13
- "Hours": "小时",
14
- "Minutes": "分钟",
15
- "No authentication methods available.": "没有可用的认证方式。",
16
- "Not a valid cellphone number, please re-enter": "不是有效的手机号,请重新输入",
17
- "Not allowed to sign up": "禁止注册",
18
- "Password is not allowed to be changed": "密码不允许修改",
19
- "Please enter a valid email": "请输入有效的邮箱",
20
- "Please enter a valid username": "请输入有效的用户名",
21
- "Please enter your username or email": "请输入用户名或邮箱",
22
- "Please keep and enable at least one authenticator": "请至少保留并启用一个认证器",
23
- "SMS": "短信",
24
- "Saved successfully!": "保存成功!",
25
- "Seconds": "",
26
- "Session validity period": "会话有效期",
27
- "Sign in via email": "邮箱登录",
28
- "Sign in via password": "密码登录",
29
- "Sign-in": "登录",
30
- "The authentication allows users to sign in via username or email.": "该认证方式支持用户通过用户名或邮箱登录。",
31
- "The maximum time limit allowed for refreshing a Token after it expires. After this time limit, the token cannot be automatically renewed, and the user needs to log in again.": "Token 过期后允许刷新的最大时限,超过此时限后,Token 无法自动更新,用户需重新登录。",
32
- "The maximum valid time for each user login. During the session validity, the Token will be automatically updated. After the timeout, the user is required to log in again.": "用户每次登录的最长有效时间,在会话有效期内,Token 会自动更新,超时后要求用户重新登录。",
33
- "The password is inconsistent, please re-enter": "密码不一致,请重新输入",
34
- "The password is incorrect, please re-enter": "密码有误,请重新输入",
35
- "The phone number has been registered, please login directly": "手机号已注册,请直接登录",
36
- "The phone number is not registered, please register first": "手机号未注册,请先注册",
37
- "The username or email is incorrect, please re-enter": "用户名或邮箱有误,请重新输入",
38
- "The validity period of each issued API Token. After the Token expires, if it is within the session validity period and has not exceeded the refresh limit, the server will automatically issue a new Token to maintain the user session, otherwise the user is required to log in again. (Each Token can only be refreshed once)": "每次签发的 API Token 的有效期。Token 过期后,如果处于会话有效期内,并且没有超过刷新时限,服务端将自动签发新 Token 以保持用户会话,否则要求用户重新登录。(每个 Token 只能被刷新一次)",
39
- "Token policy": "Token 策略",
40
- "Token validity period": "Token 有效期",
41
- "Token validity period must be less than session validity period!": "Token 有效期必须小于会话有效期!",
42
- "Unauthenticated. Please sign in to continue.": "未认证。请登录以继续。",
43
- "Unbind": "解绑",
44
- "User can bind or unbind the sign in type": "用户可以绑定或解绑登录方式",
45
- "User not found. Please sign in again to continue.": "用户不存在。请重新登录以继续。",
46
- "Username/Email": "用户名/邮箱",
47
- "WeChat": "微信",
48
- "Your account has been disabled, please contact administrator if you have any questions": "您的账户已被停用,如有疑问请联系管理员",
49
- "Your account has been locked due to multiple failed login attempts. Please try again later.": "您的账户因多次登录失败已被锁定,请稍后再试",
50
- "Your account is under review, please wait for administrator approval": "您的账户正在审核中,请等待管理员审核通过",
51
- "Your session has expired. Please sign in again.": "您的会话已过期,请重新登录。",
52
- "gitea": "Gitea 验证登录",
53
- "sms": "短信验证",
54
- "wechat": "微信登录",
55
- "work-wechat": "企业微信登录"
56
- }
1
+ {
2
+ "Allow to sign in with": "允许使用以下方式登录",
3
+ "Allow to sign up": "允许注册",
4
+ "Are you sure to unbind this authenticator?": "确定要解绑该认证器吗?",
5
+ "Auth Type": "认证类型",
6
+ "Auth UID": "认证标识",
7
+ "Authentication": "认证方式",
8
+ "Authentication login bind": "认证登录绑定",
9
+ "Authenticators": "认证器",
10
+ "Bind": "绑定",
11
+ "Days": "天",
12
+ "Expired token refresh limit": "过期 Token 刷新时限",
13
+ "Hours": "小时",
14
+ "Invalid status": "状态异常",
15
+ "Minutes": "分钟",
16
+ "No authentication methods available.": "没有可用的认证方式。",
17
+ "Not a valid cellphone number, please re-enter": "不是有效的手机号,请重新输入",
18
+ "Not allowed to sign up": "禁止注册",
19
+ "Password is not allowed to be changed": "密码不允许修改",
20
+ "Please enter a valid email": "请输入有效的邮箱",
21
+ "Please enter a valid username": "请输入有效的用户名",
22
+ "Please enter your username or email": "请输入用户名或邮箱",
23
+ "Please keep and enable at least one authenticator": "请至少保留并启用一个认证器",
24
+ "SMS": "短信",
25
+ "Saved successfully!": "保存成功!",
26
+ "Seconds": "",
27
+ "Session validity period": "会话有效期",
28
+ "Sign in via email": "邮箱登录",
29
+ "Sign in via password": "密码登录",
30
+ "Sign-in": "登录",
31
+ "Status expired, auto restored": "状态已过期,自动恢复",
32
+ "System error, please contact administrator": "系统错误,请联系管理员",
33
+ "The authentication allows users to sign in via username or email.": "该认证方式支持用户通过用户名或邮箱登录。",
34
+ "The maximum time limit allowed for refreshing a Token after it expires. After this time limit, the token cannot be automatically renewed, and the user needs to log in again.": "Token 过期后允许刷新的最大时限,超过此时限后,Token 无法自动更新,用户需重新登录。",
35
+ "The maximum valid time for each user login. During the session validity, the Token will be automatically updated. After the timeout, the user is required to log in again.": "用户每次登录的最长有效时间,在会话有效期内,Token 会自动更新,超时后要求用户重新登录。",
36
+ "The password is inconsistent, please re-enter": "密码不一致,请重新输入",
37
+ "The password is incorrect, please re-enter": "密码有误,请重新输入",
38
+ "The phone number has been registered, please login directly": "手机号已注册,请直接登录",
39
+ "The phone number is not registered, please register first": "手机号未注册,请先注册",
40
+ "The username or email is incorrect, please re-enter": "用户名或邮箱有误,请重新输入",
41
+ "The validity period of each issued API Token. After the Token expires, if it is within the session validity period and has not exceeded the refresh limit, the server will automatically issue a new Token to maintain the user session, otherwise the user is required to log in again. (Each Token can only be refreshed once)": "每次签发的 API Token 的有效期。Token 过期后,如果处于会话有效期内,并且没有超过刷新时限,服务端将自动签发新 Token 以保持用户会话,否则要求用户重新登录。(每个 Token 只能被刷新一次)",
42
+ "Token policy": "Token 策略",
43
+ "Token validity period": "Token 有效期",
44
+ "Token validity period must be less than session validity period!": "Token 有效期必须小于会话有效期!",
45
+ "Unauthenticated. Please sign in to continue.": "未认证。请登录以继续。",
46
+ "Unbind": "解绑",
47
+ "Unknown status": "未知状态",
48
+ "User can bind or unbind the sign in type": "用户可以绑定或解绑登录方式",
49
+ "User not found. Please sign in again to continue.": "用户不存在。请重新登录以继续。",
50
+ "User status does not allow login": "用户状态不允许登录",
51
+ "User status is invalid, please contact administrator": "用户状态异常,请联系管理员",
52
+ "Username/Email": "用户名/邮箱",
53
+ "WeChat": "微信",
54
+ "Your account has been disabled, please contact administrator if you have any questions": "您的账户已被停用,如有疑问请联系管理员",
55
+ "Your account has been locked due to multiple failed login attempts. Please try again later.": "您的账户因多次登录失败已被锁定,请稍后再试",
56
+ "Your account is under review, please wait for administrator approval": "您的账户正在审核中,请等待管理员审核通过",
57
+ "Your account status has changed. Please sign in again.": "您的账号状态已变更,请重新登录",
58
+ "Your session has expired. Please sign in again.": "您的会话已过期,请重新登录。",
59
+ "gitea": "Gitea 验证登录",
60
+ "sms": "短信验证",
61
+ "wechat": "微信登录",
62
+ "work-wechat": "企业微信登录"
63
+ }
@@ -1 +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":"2025-12-05T07:09:26.013Z"}
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":"2025-12-05T11:14:22.671Z"}
@@ -1 +1 @@
1
- {"name":"ms","version":"2.1.3","description":"Tiny millisecond conversion utility","repository":"vercel/ms","main":"./index","files":["index.js"],"scripts":{"precommit":"lint-staged","lint":"eslint lib/* bin/*","test":"mocha tests.js"},"eslintConfig":{"extends":"eslint:recommended","env":{"node":true,"es6":true}},"lint-staged":{"*.js":["npm run lint","prettier --single-quote --write","git add"]},"license":"MIT","devDependencies":{"eslint":"4.18.2","expect.js":"0.3.1","husky":"0.14.3","lint-staged":"5.0.0","mocha":"4.0.1","prettier":"2.0.5"},"_lastModified":"2025-12-05T07:09:26.116Z"}
1
+ {"name":"ms","version":"2.1.3","description":"Tiny millisecond conversion utility","repository":"vercel/ms","main":"./index","files":["index.js"],"scripts":{"precommit":"lint-staged","lint":"eslint lib/* bin/*","test":"mocha tests.js"},"eslintConfig":{"extends":"eslint:recommended","env":{"node":true,"es6":true}},"lint-staged":{"*.js":["npm run lint","prettier --single-quote --write","git add"]},"license":"MIT","devDependencies":{"eslint":"4.18.2","expect.js":"0.3.1","husky":"0.14.3","lint-staged":"5.0.0","mocha":"4.0.1","prettier":"2.0.5"},"_lastModified":"2025-12-05T11:14:22.773Z"}
@@ -36,7 +36,8 @@ var import_preset = require("../preset");
36
36
  class BasicAuth extends import_server.BaseAuth {
37
37
  constructor(config) {
38
38
  const userCollection = config.ctx.db.getCollection("users");
39
- super({ ...config, userCollection });
39
+ const userStatusCollection = config.ctx.db.getCollection("userStatuses");
40
+ super({ ...config, userCollection, userStatusCollection });
40
41
  }
41
42
  async validate() {
42
43
  const ctx = this.ctx;
@@ -6,13 +6,5 @@ declare const _default: {
6
6
  'The phone number has been registered, please login directly': string;
7
7
  'The phone number is not registered, please register first': string;
8
8
  'The username, email or password is incorrect, please re-enter': string;
9
- 'Invalid status': string;
10
- 'User status is invalid, please contact administrator': string;
11
- 'User status does not allow login': string;
12
- 'Your account is under review, please wait for administrator approval': string;
13
- 'Your account has been disabled, please contact administrator if you have any questions': string;
14
- 'Unknown status': string;
15
- 'System error, please contact administrator': string;
16
- 'Your account status has changed. Please sign in again.': string;
17
9
  };
18
10
  export default _default;
@@ -27,13 +27,5 @@ var en_US_default = {
27
27
  "Not a valid cellphone number, please re-enter": "Not a valid cellphone number, please re-enter",
28
28
  "The phone number has been registered, please login directly": "The phone number has been registered, please login directly",
29
29
  "The phone number is not registered, please register first": "The phone number is not registered, please register first",
30
- "The username, email or password is incorrect, please re-enter": "The username, email or password is incorrect, please re-enter",
31
- "Invalid status": "Invalid status",
32
- "User status is invalid, please contact administrator": "User status is invalid, please contact administrator",
33
- "User status does not allow login": "User status does not allow login",
34
- "Your account is under review, please wait for administrator approval": "Your account is under review, please wait for administrator approval",
35
- "Your account has been disabled, please contact administrator if you have any questions": "Your account has been disabled, please contact administrator if you have any questions",
36
- "Unknown status": "Unknown status",
37
- "System error, please contact administrator": "System error, please contact administrator",
38
- "Your account status has changed. Please sign in again.": "Your account status has changed. Please sign in again."
30
+ "The username, email or password is incorrect, please re-enter": "The username, email or password is incorrect, please re-enter"
39
31
  };
@@ -8,13 +8,5 @@ declare const _default: {
8
8
  'Please enter your username or email': string;
9
9
  'Please enter a valid username': string;
10
10
  'The username, email or password is incorrect, please re-enter': string;
11
- 'Invalid status': string;
12
- 'User status is invalid, please contact administrator': string;
13
- 'User status does not allow login': string;
14
- 'Your account is under review, please wait for administrator approval': string;
15
- 'Your account has been disabled, please contact administrator if you have any questions': string;
16
- 'Unknown status': string;
17
- 'System error, please contact administrator': string;
18
- 'Your account status has changed. Please sign in again.': string;
19
11
  };
20
12
  export default _default;
@@ -29,13 +29,5 @@ var zh_CN_default = {
29
29
  "Please keep and enable at least one authenticator": "\u8BF7\u81F3\u5C11\u4FDD\u7559\u5E76\u542F\u7528\u4E00\u4E2A\u8BA4\u8BC1\u5668",
30
30
  "Please enter your username or email": "\u8BF7\u8F93\u5165\u7528\u6237\u540D\u6216\u90AE\u7BB1",
31
31
  "Please enter a valid username": "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u7528\u6237\u540D",
32
- "The username, email or password is incorrect, please re-enter": "\u7528\u6237\u540D\u90AE\u7BB1\u6216\u8005\u5BC6\u7801\u6709\u8BEF,\u8BF7\u91CD\u65B0\u8F93\u5165",
33
- "Invalid status": "\u72B6\u6001\u5F02\u5E38",
34
- "User status is invalid, please contact administrator": "\u7528\u6237\u72B6\u6001\u5F02\u5E38\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",
35
- "User status does not allow login": "\u7528\u6237\u72B6\u6001\u4E0D\u5141\u8BB8\u767B\u5F55",
36
- "Your account is under review, please wait for administrator approval": "\u60A8\u7684\u8D26\u53F7\u6B63\u5728\u5BA1\u6838\u4E2D\uFF0C\u8BF7\u7B49\u5F85\u7BA1\u7406\u5458\u6279\u51C6",
37
- "Your account has been disabled, please contact administrator if you have any questions": "\u60A8\u7684\u8D26\u53F7\u5DF2\u88AB\u7981\u7528\uFF0C\u5982\u6709\u7591\u95EE\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",
38
- "Unknown status": "\u672A\u77E5\u72B6\u6001",
39
- "System error, please contact administrator": "\u7CFB\u7EDF\u9519\u8BEF\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",
40
- "Your account status has changed. Please sign in again.": "\u60A8\u7684\u8D26\u53F7\u72B6\u6001\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55"
32
+ "The username, email or password is incorrect, please re-enter": "\u7528\u6237\u540D\u90AE\u7BB1\u6216\u8005\u5BC6\u7801\u6709\u8BEF,\u8BF7\u91CD\u65B0\u8F93\u5165"
41
33
  };
@@ -46,23 +46,27 @@ var import_user_status = require("./user-status");
46
46
  class PluginAuthServer extends import_server.Plugin {
47
47
  afterAdd() {
48
48
  this.app.on("afterLoad", async () => {
49
- if (this.app.authManager.tokenController) {
50
- return;
51
- }
52
- const cache = await this.app.cacheManager.createCache({
53
- name: "auth-token-controller",
54
- prefix: "auth-token-controller"
55
- });
56
- const tokenController = new import_token_controller.TokenController({ cache, app: this.app, logger: this.app.logger });
57
- this.app.authManager.setTokenControlService(tokenController);
58
- const tokenPolicyRepo = this.app.db.getRepository(import_constants.tokenPolicyCollectionName);
59
- try {
60
- const res = await tokenPolicyRepo.findOne({ filterByTk: import_constants.tokenPolicyRecordKey });
61
- if (res) {
62
- this.app.authManager.tokenController.setConfig(res.config);
49
+ if (!this.app.authManager.tokenController) {
50
+ const cache = await this.app.cacheManager.createCache({
51
+ name: "auth-token-controller",
52
+ prefix: "auth-token-controller"
53
+ });
54
+ const tokenController = new import_token_controller.TokenController({ cache, app: this.app, logger: this.app.logger });
55
+ this.app.authManager.setTokenControlService(tokenController);
56
+ const tokenPolicyRepo = this.app.db.getRepository(import_constants.tokenPolicyCollectionName);
57
+ try {
58
+ const res = await tokenPolicyRepo.findOne({ filterByTk: import_constants.tokenPolicyRecordKey });
59
+ if (res) {
60
+ this.app.authManager.tokenController.setConfig(res.config);
61
+ }
62
+ } catch (error) {
63
+ this.app.logger.warn("access control config not exist, use default value");
63
64
  }
64
- } catch (error) {
65
- this.app.logger.warn("access control config not exist, use default value");
65
+ }
66
+ if (!this.app.authManager.userStatusService) {
67
+ this.app.authManager.setUserStatusService(
68
+ new import_user_status.UserStatusService({ cache: this.cache, app: this.app, logger: this.app.logger })
69
+ );
66
70
  }
67
71
  });
68
72
  }
@@ -72,10 +76,6 @@ class PluginAuthServer extends import_server.Plugin {
72
76
  this.app.db.registerModels({ AuthModel: import_authenticator.AuthModel });
73
77
  }
74
78
  async load() {
75
- this.userStatusService = new import_user_status.UserStatusService(this.app);
76
- this.app.userStatusService = this.userStatusService;
77
- this.userStatusService.injectLoginCheck();
78
- this.userStatusService.registerStatusChangeInterceptor();
79
79
  this.cache = await this.app.cacheManager.createCache({
80
80
  name: "auth",
81
81
  prefix: "auth",
@@ -1,106 +1,45 @@
1
- import { Application } from '@tego/server';
1
+ import { Application, Cache, Collection, SystemLogger, type IUserStatusService, type UserStatusCache, type UserStatusCheckResult } from '@tego/server';
2
2
  /**
3
- * 用户状态检查结果
3
+ * 基础用户状态服务实现
4
4
  */
5
- export interface UserStatusCheckResult {
6
- allowed: boolean;
7
- status: string;
8
- statusInfo?: {
9
- title: string;
10
- color: string;
11
- allowLogin: boolean;
12
- loginErrorMessage?: string;
13
- };
14
- errorMessage?: string;
15
- isExpired?: boolean;
16
- }
17
- /**
18
- * 修改用户状态的选项
19
- */
20
- export interface ChangeUserStatusOptions {
21
- expireAt?: Date;
22
- reason?: string;
23
- operationType: 'manual' | 'auto' | 'system';
24
- operatorId?: number;
25
- }
26
- /**
27
- * 状态注册配置
28
- */
29
- export interface StatusConfig {
30
- key: string;
31
- title: string;
32
- color?: string;
33
- allowLogin: boolean;
34
- loginErrorMessage?: string;
35
- packageName: string;
36
- description?: string;
37
- sort?: number;
38
- config?: Record<string, any>;
39
- }
40
- declare module '@tego/server' {
41
- interface BaseAuth {
42
- checkUserStatusInContext?(userId: number): Promise<UserStatusCheckResult>;
43
- }
44
- }
45
- /**
46
- * 用户状态管理服务
47
- * 负责用户状态的检查、变更、恢复等核心业务逻辑
48
- */
49
- export declare class UserStatusService {
50
- private db;
51
- private app;
52
- private cache;
53
- private logger;
54
- constructor(app: Application);
55
- /**
56
- * 获取用户状态缓存键
57
- */
58
- private getUserStatusCacheKey;
59
- /**
60
- * 从缓存获取用户状态
61
- */
62
- private getUserStatusFromCache;
63
- /**
64
- * 设置用户状态缓存
65
- */
66
- private setUserStatusCache;
67
- /**
68
- * 清除用户状态缓存
69
- */
70
- private clearUserStatusCache;
71
- /**
72
- * 检查用户状态是否允许登录
73
- * @param userId 用户ID
74
- * @returns 检查结果
75
- */
5
+ export declare class UserStatusService implements IUserStatusService {
6
+ protected cache: Cache;
7
+ protected app: Application;
8
+ protected logger: SystemLogger;
9
+ protected userCollection: Collection;
10
+ protected userStatusCollection: Collection;
11
+ protected userStatusHistoryCollection: Collection;
12
+ constructor({ cache, app, logger }: {
13
+ cache: Cache;
14
+ app: Application;
15
+ logger: SystemLogger;
16
+ });
17
+ get userRepository(): import("@tego/server").Repository<any, any>;
18
+ get userStatusRepository(): import("@tego/server").Repository<any, any>;
19
+ get userStatusHistoryRepository(): import("@tego/server").Repository<any, any>;
20
+ /**
21
+ * 翻译消息
22
+ */
23
+ private t;
76
24
  checkUserStatus(userId: number): Promise<UserStatusCheckResult>;
77
- /**
78
- * 记录状态变更历史(如果不存在相同记录)
79
- * @param params 状态变更参数
80
- */
81
- private recordStatusHistoryIfNotExists;
82
- /**
83
- * 恢复过期的用户状态
84
- * @param userId 用户ID
85
- */
25
+ setUserStatusCache(userId: number, data: UserStatusCache): Promise<void>;
26
+ getUserStatusFromCache(userId: number): Promise<UserStatusCache | null>;
27
+ getUserStatusCacheKey(userId: number): string;
86
28
  restoreUserStatus(userId: number): Promise<void>;
87
- /**
88
- * 注册新的用户状态(供插件使用)
89
- * @param config 状态配置
90
- */
91
- registerStatus(config: StatusConfig): Promise<void>;
92
- /**
93
- * 获取每个状态的用户数量统计
94
- */
95
- getStatusStatistics(): Promise<Record<string, number>>;
96
- /**
97
- * 注入登录检查
98
- */
99
- injectLoginCheck(): void;
29
+ clearUserStatusCache(userId: number): Promise<void>;
30
+ recordStatusHistoryIfNotExists(params: {
31
+ userId: number;
32
+ fromStatus: string;
33
+ toStatus: string;
34
+ reason: string | null;
35
+ expireAt: Date | null;
36
+ operationType: 'manual' | 'auto' | 'system';
37
+ createdBy: number | null;
38
+ transaction?: any;
39
+ }): Promise<void>;
100
40
  /**
101
41
  * 注册用户状态变更拦截器
102
42
  * 拦截 users:update 请求,自动记录状态变更历史
103
43
  */
104
- registerStatusChangeInterceptor(): void;
44
+ private registerStatusChangeInterceptor;
105
45
  }
106
- export default UserStatusService;