@nocobase/plugin-users 0.5.0-alpha.18 → 0.5.0-alpha.22
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/lib/actions/users.d.ts.map +1 -1
- package/lib/actions/users.js +3 -4
- package/lib/actions/users.js.map +1 -1
- package/lib/collections/users.d.ts.map +1 -1
- package/lib/collections/users.js +12 -0
- package/lib/collections/users.js.map +1 -1
- package/lib/fields/CreatedBy.d.ts.map +1 -1
- package/lib/fields/CreatedBy.js.map +1 -1
- package/lib/fields/UpdatedBy.d.ts.map +1 -1
- package/lib/fields/UpdatedBy.js.map +1 -1
- package/lib/fields/utils.d.ts +1 -1
- package/lib/fields/utils.d.ts.map +1 -1
- package/lib/fields/utils.js.map +1 -1
- package/lib/server.d.ts.map +1 -1
- package/lib/server.js +2 -2
- package/lib/server.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["actions/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAIlD,wBAAsB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,
|
|
1
|
+
{"version":3,"sources":["actions/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAIlD,wBAAsB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,iBAQnD;AAED,wBAAsB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,iBA0BnD;AAED,wBAAsB,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,iBAGpD;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,iBActD;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,iBAoB1D;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,iBAoB3D;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,iBAajE;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,iBAQ3D","file":"users.d.ts","sourcesContent":["import { Context, Next } from '@nocobase/actions';\nimport { PASSWORD } from '@nocobase/database';\nimport cryptoRandomString from 'crypto-random-string';\n\nexport async function check(ctx: Context, next: Next) {\n if (ctx.state.currentUser) {\n const user = ctx.state.currentUser.toJSON();\n ctx.body = user;\n await next();\n } else {\n ctx.throw(401, 'Unauthorized');\n }\n}\n\nexport async function login(ctx: Context, next: Next) {\n const { uniqueField = 'email', values } = ctx.action.params;\n console.log('login.values', values);\n if (!values[uniqueField]) {\n ctx.throw(401, '请填写邮箱账号');\n }\n const User = ctx.db.getModel('users');\n const user = await User.scope('withPassword').findOne({\n where: {\n [uniqueField]: values[uniqueField],\n },\n });\n if (!user) {\n ctx.throw(401, '邮箱账号未注册');\n }\n const isValid = await PASSWORD.verify(values.password, user.password);\n if (!isValid) {\n ctx.throw(401, '密码错误,请您重新输入');\n }\n if (!user.token) {\n user.token = cryptoRandomString({ length: 20 });\n await user.save();\n }\n ctx.body = user.toJSON();\n delete ctx.body.password;\n await next();\n}\n\nexport async function logout(ctx: Context, next: Next) {\n ctx.body = {};\n await next();\n}\n\nexport async function register(ctx: Context, next: Next) {\n const User = ctx.db.getModel('users');\n const { values } = ctx.action.params;\n try {\n const user = await User.create(values);\n ctx.body = user;\n } catch (error) {\n if (error.errors) {\n ctx.throw(401, error.errors.map((data) => data.message).join(', '));\n } else {\n ctx.throw(401, '注册失败');\n }\n }\n await next();\n}\n\nexport async function lostpassword(ctx: Context, next: Next) {\n const {\n values: { email },\n } = ctx.action.params;\n if (!email) {\n ctx.throw(401, '请填写邮箱账号');\n }\n const User = ctx.db.getModel('users');\n const user = await User.findOne({\n where: {\n email,\n },\n });\n if (!user) {\n ctx.throw(401, '邮箱账号未注册');\n }\n user.reset_token = cryptoRandomString({ length: 20 });\n await user.save();\n ctx.body = user;\n await next();\n}\n\nexport async function resetpassword(ctx: Context, next: Next) {\n const {\n values: { email, password, reset_token },\n } = ctx.action.params;\n const User = ctx.db.getModel('users');\n const user = await User.findOne({\n where: {\n email,\n reset_token,\n },\n });\n if (!user) {\n ctx.throw(401, 'Unauthorized');\n }\n user.token = null;\n user.reset_token = null;\n user.password = password;\n await user.save();\n ctx.body = user;\n await next();\n}\n\nexport async function getUserByResetToken(ctx: Context, next: Next) {\n const { token } = ctx.action.params;\n const User = ctx.db.getModel('users');\n const user = await User.findOne({\n where: {\n reset_token: token,\n },\n });\n if (!user) {\n ctx.throw(401, 'Unauthorized');\n }\n ctx.body = user;\n await next();\n}\n\nexport async function updateProfile(ctx: Context, next: Next) {\n const { values } = ctx.action.params;\n if (!ctx.state.currentUser) {\n ctx.throw(401, 'Unauthorized');\n }\n await ctx.state.currentUser.update(values);\n ctx.body = ctx.state.currentUser;\n await next();\n}\n"]}
|
package/lib/actions/users.js
CHANGED
|
@@ -63,7 +63,6 @@ function check(ctx, next) {
|
|
|
63
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
64
|
if (ctx.state.currentUser) {
|
|
65
65
|
const user = ctx.state.currentUser.toJSON();
|
|
66
|
-
delete user.password;
|
|
67
66
|
ctx.body = user;
|
|
68
67
|
yield next();
|
|
69
68
|
} else {
|
|
@@ -87,7 +86,7 @@ function login(ctx, next) {
|
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
const User = ctx.db.getModel('users');
|
|
90
|
-
const user = yield User.findOne({
|
|
89
|
+
const user = yield User.scope('withPassword').findOne({
|
|
91
90
|
where: {
|
|
92
91
|
[uniqueField]: values[uniqueField]
|
|
93
92
|
}
|
|
@@ -110,7 +109,8 @@ function login(ctx, next) {
|
|
|
110
109
|
yield user.save();
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
ctx.body = user;
|
|
112
|
+
ctx.body = user.toJSON();
|
|
113
|
+
delete ctx.body.password;
|
|
114
114
|
yield next();
|
|
115
115
|
});
|
|
116
116
|
}
|
|
@@ -136,7 +136,6 @@ function register(ctx, next) {
|
|
|
136
136
|
ctx.body = user;
|
|
137
137
|
} catch (error) {
|
|
138
138
|
if (error.errors) {
|
|
139
|
-
console.log(error.errors.map(data => data.message));
|
|
140
139
|
ctx.throw(401, error.errors.map(data => data.message).join(', '));
|
|
141
140
|
} else {
|
|
142
141
|
ctx.throw(401, '注册失败');
|
package/lib/actions/users.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["actions/users.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,iDAA8C;AAC9C,gFAAsD;AAEtD,SAAsB,KAAK,CAAC,GAAY,EAAE,IAAU;;QAClD,IAAI,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE;YACzB,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YAC5C,
|
|
1
|
+
{"version":3,"sources":["actions/users.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,iDAA8C;AAC9C,gFAAsD;AAEtD,SAAsB,KAAK,CAAC,GAAY,EAAE,IAAU;;QAClD,IAAI,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE;YACzB,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YAC5C,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,MAAM,IAAI,EAAE,CAAC;SACd;aAAM;YACL,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;SAChC;IACH,CAAC;CAAA;AARD,sBAQC;AAED,SAAsB,KAAK,CAAC,GAAY,EAAE,IAAU;;QAClD,MAAM,EAA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,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC9B,KAAK,EAAE;gBACL,WAAW,EAAE,KAAK;aACnB;SACF,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,EAAE;YACT,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;SAChC;QACD,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QAChB,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA;AAbD,kDAaC;AAED,SAAsB,aAAa,CAAC,GAAY,EAAE,IAAU;;QAC1D,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;QACrC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE;YAC1B,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;SAChC;QACD,MAAM,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC;QACjC,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA;AARD,sCAQC","file":"users.js","sourcesContent":["import { Context, Next } from '@nocobase/actions';\nimport { PASSWORD } from '@nocobase/database';\nimport cryptoRandomString from 'crypto-random-string';\n\nexport async function check(ctx: Context, next: Next) {\n if (ctx.state.currentUser) {\n const user = ctx.state.currentUser.toJSON();\n ctx.body = user;\n await next();\n } else {\n ctx.throw(401, 'Unauthorized');\n }\n}\n\nexport async function login(ctx: Context, next: Next) {\n const { uniqueField = 'email', values } = ctx.action.params;\n console.log('login.values', values);\n if (!values[uniqueField]) {\n ctx.throw(401, '请填写邮箱账号');\n }\n const User = ctx.db.getModel('users');\n const user = await User.scope('withPassword').findOne({\n where: {\n [uniqueField]: values[uniqueField],\n },\n });\n if (!user) {\n ctx.throw(401, '邮箱账号未注册');\n }\n const isValid = await PASSWORD.verify(values.password, user.password);\n if (!isValid) {\n ctx.throw(401, '密码错误,请您重新输入');\n }\n if (!user.token) {\n user.token = cryptoRandomString({ length: 20 });\n await user.save();\n }\n ctx.body = user.toJSON();\n delete ctx.body.password;\n await next();\n}\n\nexport async function logout(ctx: Context, next: Next) {\n ctx.body = {};\n await next();\n}\n\nexport async function register(ctx: Context, next: Next) {\n const User = ctx.db.getModel('users');\n const { values } = ctx.action.params;\n try {\n const user = await User.create(values);\n ctx.body = user;\n } catch (error) {\n if (error.errors) {\n ctx.throw(401, error.errors.map((data) => data.message).join(', '));\n } else {\n ctx.throw(401, '注册失败');\n }\n }\n await next();\n}\n\nexport async function lostpassword(ctx: Context, next: Next) {\n const {\n values: { email },\n } = ctx.action.params;\n if (!email) {\n ctx.throw(401, '请填写邮箱账号');\n }\n const User = ctx.db.getModel('users');\n const user = await User.findOne({\n where: {\n email,\n },\n });\n if (!user) {\n ctx.throw(401, '邮箱账号未注册');\n }\n user.reset_token = cryptoRandomString({ length: 20 });\n await user.save();\n ctx.body = user;\n await next();\n}\n\nexport async function resetpassword(ctx: Context, next: Next) {\n const {\n values: { email, password, reset_token },\n } = ctx.action.params;\n const User = ctx.db.getModel('users');\n const user = await User.findOne({\n where: {\n email,\n reset_token,\n },\n });\n if (!user) {\n ctx.throw(401, 'Unauthorized');\n }\n user.token = null;\n user.reset_token = null;\n user.password = password;\n await user.save();\n ctx.body = user;\n await next();\n}\n\nexport async function getUserByResetToken(ctx: Context, next: Next) {\n const { token } = ctx.action.params;\n const User = ctx.db.getModel('users');\n const user = await User.findOne({\n where: {\n reset_token: token,\n },\n });\n if (!user) {\n ctx.throw(401, 'Unauthorized');\n }\n ctx.body = user;\n await next();\n}\n\nexport async function updateProfile(ctx: Context, next: Next) {\n const { values } = ctx.action.params;\n if (!ctx.state.currentUser) {\n ctx.throw(401, 'Unauthorized');\n }\n await ctx.state.currentUser.update(values);\n ctx.body = ctx.state.currentUser;\n await next();\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["collections/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;;AAElD,
|
|
1
|
+
{"version":3,"sources":["collections/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;;AAElD,wBAsEkB","file":"users.d.ts","sourcesContent":["import { TableOptions } from '@nocobase/database';\n\nexport default {\n name: 'users',\n title: '用户',\n // developerMode: true,\n // internal: true,\n createdBy: false,\n updatedBy: false,\n privilege: 'undelete',\n scopes: {\n withPassword: {\n attributes: { include: ['password'] },\n },\n },\n defaultScope: {\n attributes: { exclude: ['password'] },\n },\n fields: [\n {\n interface: 'string',\n type: 'string',\n name: 'nickname',\n uiSchema: {\n type: 'string',\n title: '昵称',\n 'x-component': 'Input',\n },\n },\n {\n interface: 'email',\n type: 'string',\n name: 'email',\n unique: true,\n privilege: 'undelete',\n uiSchema: {\n type: 'string',\n title: '邮箱',\n 'x-component': 'Input',\n require: true,\n },\n },\n {\n interface: 'password',\n type: 'password',\n name: 'password',\n privilege: 'undelete',\n uiSchema: {\n type: 'string',\n title: '密码',\n 'x-component': 'Password',\n },\n },\n {\n interface: 'password',\n type: 'string',\n name: 'token',\n unique: true,\n hidden: true,\n privilege: 'undelete',\n state: 0,\n },\n {\n interface: 'password',\n type: 'string',\n name: 'reset_token',\n unique: true,\n hidden: true,\n privilege: 'undelete',\n state: 0,\n },\n ],\n} as TableOptions;\n"]}
|
package/lib/collections/users.js
CHANGED
|
@@ -21,6 +21,18 @@ exports.default = {
|
|
|
21
21
|
createdBy: false,
|
|
22
22
|
updatedBy: false,
|
|
23
23
|
privilege: 'undelete',
|
|
24
|
+
scopes: {
|
|
25
|
+
withPassword: {
|
|
26
|
+
attributes: {
|
|
27
|
+
include: ['password']
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
defaultScope: {
|
|
32
|
+
attributes: {
|
|
33
|
+
exclude: ['password']
|
|
34
|
+
}
|
|
35
|
+
},
|
|
24
36
|
fields: [{
|
|
25
37
|
interface: 'string',
|
|
26
38
|
type: 'string',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["collections/users.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,IAAI;IAGX,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,IAAI;gBACX,aAAa,EAAE,OAAO;aACvB;SACF;QACD;YACE,SAAS,EAAE,OAAO;YAClB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,UAAU;YACrB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,IAAI;gBACX,aAAa,EAAE,OAAO;gBACtB,OAAO,EAAE,IAAI;aACd;SACF;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,UAAU;YAChB,SAAS,EAAE,UAAU;YACrB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,IAAI;gBACX,aAAa,EAAE,UAAU;aAC1B;SACF;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,UAAU;YACrB,KAAK,EAAE,CAAC;SACT;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,UAAU;YACrB,KAAK,EAAE,CAAC;SACT;KACF;CACc,CAAC","file":"users.js","sourcesContent":["import { TableOptions } from '@nocobase/database';\n\nexport default {\n name: 'users',\n title: '用户',\n // developerMode: true,\n // internal: true,\n createdBy: false,\n updatedBy: false,\n privilege: 'undelete',\n fields: [\n {\n interface: 'string',\n type: 'string',\n name: 'nickname',\n uiSchema: {\n type: 'string',\n title: '昵称',\n 'x-component': 'Input',\n },\n },\n {\n interface: 'email',\n type: 'string',\n name: 'email',\n unique: true,\n privilege: 'undelete',\n uiSchema: {\n type: 'string',\n title: '邮箱',\n 'x-component': 'Input',\n require: true,\n },\n },\n {\n interface: 'password',\n type: 'password',\n name: 'password',\n privilege: 'undelete',\n uiSchema: {\n type: 'string',\n title: '密码',\n 'x-component': 'Password',\n },\n },\n {\n interface: 'password',\n type: 'string',\n name: 'token',\n unique: true,\n hidden: true,\n privilege: 'undelete',\n state: 0,\n },\n {\n interface: 'password',\n type: 'string',\n name: 'reset_token',\n unique: true,\n hidden: true,\n privilege: 'undelete',\n state: 0,\n },\n ],\n} as TableOptions;\n"]}
|
|
1
|
+
{"version":3,"sources":["collections/users.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,IAAI;IAGX,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE;QACN,YAAY,EAAE;YACZ,UAAU,EAAE,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE;SACtC;KACF;IACD,YAAY,EAAE;QACZ,UAAU,EAAE,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE;KACtC;IACD,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,IAAI;gBACX,aAAa,EAAE,OAAO;aACvB;SACF;QACD;YACE,SAAS,EAAE,OAAO;YAClB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,UAAU;YACrB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,IAAI;gBACX,aAAa,EAAE,OAAO;gBACtB,OAAO,EAAE,IAAI;aACd;SACF;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,UAAU;YAChB,SAAS,EAAE,UAAU;YACrB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,IAAI;gBACX,aAAa,EAAE,UAAU;aAC1B;SACF;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,UAAU;YACrB,KAAK,EAAE,CAAC;SACT;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,UAAU;YACrB,KAAK,EAAE,CAAC;SACT;KACF;CACc,CAAC","file":"users.js","sourcesContent":["import { TableOptions } from '@nocobase/database';\n\nexport default {\n name: 'users',\n title: '用户',\n // developerMode: true,\n // internal: true,\n createdBy: false,\n updatedBy: false,\n privilege: 'undelete',\n scopes: {\n withPassword: {\n attributes: { include: ['password'] },\n },\n },\n defaultScope: {\n attributes: { exclude: ['password'] },\n },\n fields: [\n {\n interface: 'string',\n type: 'string',\n name: 'nickname',\n uiSchema: {\n type: 'string',\n title: '昵称',\n 'x-component': 'Input',\n },\n },\n {\n interface: 'email',\n type: 'string',\n name: 'email',\n unique: true,\n privilege: 'undelete',\n uiSchema: {\n type: 'string',\n title: '邮箱',\n 'x-component': 'Input',\n require: true,\n },\n },\n {\n interface: 'password',\n type: 'password',\n name: 'password',\n privilege: 'undelete',\n uiSchema: {\n type: 'string',\n title: '密码',\n 'x-component': 'Password',\n },\n },\n {\n interface: 'password',\n type: 'string',\n name: 'token',\n unique: true,\n hidden: true,\n privilege: 'undelete',\n state: 0,\n },\n {\n interface: 'password',\n type: 'string',\n name: 'reset_token',\n unique: true,\n hidden: true,\n privilege: 'undelete',\n state: 0,\n },\n ],\n} as TableOptions;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/CreatedBy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG/E,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACtE,IAAI,EAAE,WAAW,GAAG,WAAW,
|
|
1
|
+
{"version":3,"sources":["fields/CreatedBy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG/E,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACtE,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;CACjC;AAED,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,SAAS;IAC9C,MAAM,CAAC,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,KAAA,EAAE,EAAE,OAAO,EAAE;;KAAA;gBAMpD,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY;IAelE,WAAW,IAAI,QAAQ;CAG/B","file":"CreatedBy.d.ts","sourcesContent":["import { BelongsToOptions, BELONGSTO, FieldContext } from '@nocobase/database';\nimport { setUserValue } from './utils';\n\nexport interface CreatedByOptions extends Omit<BelongsToOptions, 'type'> {\n type: 'createdBy' | 'createdby';\n}\n\nexport default class CreatedBy extends BELONGSTO {\n static beforeBulkCreateHook(this: CreatedBy, models, { context }) {\n models.forEach((model) => {\n setUserValue.call(this, model, { context });\n });\n }\n\n constructor({ type, ...options }: CreatedByOptions, context: FieldContext) {\n super({ ...options, type: 'belongsTo' } as BelongsToOptions, context);\n // const Model = context.sourceTable.getModel();\n // TODO(feature): 可考虑策略模式,以在需要时对外提供接口\n // Model.addHook('beforeCreate', setUserValue.bind(this));\n // Model.addHook('beforeBulkCreate', CreatedBy.beforeBulkCreateHook.bind(this));\n const { sourceTable, database } = context;\n const name = sourceTable.getName();\n database.on(`${name}.beforeCreate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkCreate`,\n CreatedBy.beforeBulkCreateHook.bind(this),\n );\n }\n\n public getDataType(): Function {\n return BELONGSTO;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/CreatedBy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAA+E;AAC/E,mCAAuC;AAMvC,MAAqB,SAAU,SAAQ,oBAAS;
|
|
1
|
+
{"version":3,"sources":["fields/CreatedBy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAA+E;AAC/E,mCAAuC;AAMvC,MAAqB,SAAU,SAAQ,oBAAS;IAC9C,MAAM,CAAC,oBAAoB,CAAkB,MAAM,EAAE,EAAE,OAAO,EAAE;QAC9D,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,oBAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,YAAY,EAAsC,EAAE,OAAqB;YAA7D,EAAE,IAAI,OAAgC,EAA3B,OAAO,cAAlB,QAAoB,CAAF;QAC5B,KAAK,CAAC,gCAAK,OAAO,KAAE,IAAI,EAAE,WAAW,GAAsB,EAAE,OAAO,CAAC,CAAC;QAKtE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QAC1C,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC;QACnC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,oBAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,QAAQ,CAAC,EAAE,CACT,GAAG,IAAI,mBAAmB,EAC1B,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1C,CAAC;IACJ,CAAC;IAEM,WAAW;QAChB,OAAO,oBAAS,CAAC;IACnB,CAAC;CACF;AAzBD,4BAyBC","file":"CreatedBy.js","sourcesContent":["import { BelongsToOptions, BELONGSTO, FieldContext } from '@nocobase/database';\nimport { setUserValue } from './utils';\n\nexport interface CreatedByOptions extends Omit<BelongsToOptions, 'type'> {\n type: 'createdBy' | 'createdby';\n}\n\nexport default class CreatedBy extends BELONGSTO {\n static beforeBulkCreateHook(this: CreatedBy, models, { context }) {\n models.forEach((model) => {\n setUserValue.call(this, model, { context });\n });\n }\n\n constructor({ type, ...options }: CreatedByOptions, context: FieldContext) {\n super({ ...options, type: 'belongsTo' } as BelongsToOptions, context);\n // const Model = context.sourceTable.getModel();\n // TODO(feature): 可考虑策略模式,以在需要时对外提供接口\n // Model.addHook('beforeCreate', setUserValue.bind(this));\n // Model.addHook('beforeBulkCreate', CreatedBy.beforeBulkCreateHook.bind(this));\n const { sourceTable, database } = context;\n const name = sourceTable.getName();\n database.on(`${name}.beforeCreate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkCreate`,\n CreatedBy.beforeBulkCreateHook.bind(this),\n );\n }\n\n public getDataType(): Function {\n return BELONGSTO;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/UpdatedBy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG/E,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACtE,IAAI,EAAE,WAAW,GAAG,WAAW,
|
|
1
|
+
{"version":3,"sources":["fields/UpdatedBy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG/E,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACtE,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;CACjC;AAED,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,SAAS;IAC9C,MAAM,CAAC,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,KAAA,EAAE,EAAE,OAAO,EAAE;;KAAA;IAMhE,MAAM,CAAC,oBAAoB,CACzB,IAAI,EAAE,SAAS,EACf,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE;;;;KAAA;gBAerB,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY;IAsBlE,WAAW,IAAI,QAAQ;CAG/B","file":"UpdatedBy.d.ts","sourcesContent":["import { BelongsToOptions, BELONGSTO, FieldContext } from '@nocobase/database';\nimport { setUserValue } from './utils';\n\nexport interface UpdatedByOptions extends Omit<BelongsToOptions, 'type'> {\n type: 'updatedBy' | 'updatedby';\n}\n\nexport default class UpdatedBy extends BELONGSTO {\n static beforeBulkCreateHook(this: UpdatedBy, models, { context }) {\n models.forEach((model) => {\n setUserValue.call(this, model, { context });\n });\n }\n\n static beforeBulkUpdateHook(\n this: UpdatedBy,\n { attributes, fields, context },\n ) {\n if (!context) {\n return;\n }\n const { currentUser } = context.state;\n if (!currentUser) {\n return;\n }\n fields.push(this.options.foreignKey);\n attributes[this.options.foreignKey] = currentUser.get(\n this.options.targetKey,\n );\n }\n\n constructor({ type, ...options }: UpdatedByOptions, context: FieldContext) {\n super({ ...options, type: 'belongsTo' } as BelongsToOptions, context);\n // const Model = context.sourceTable.getModel();\n // // TODO(feature): 可考虑策略模式,以在需要时对外提供接口\n // Model.addHook('beforeCreate', setUserValue.bind(this));\n // Model.addHook('beforeBulkCreate', UpdatedBy.beforeBulkCreateHook.bind(this));\n // Model.addHook('beforeUpdate', setUserValue.bind(this));\n // Model.addHook('beforeBulkUpdate', UpdatedBy.beforeBulkUpdateHook.bind(this));\n const { sourceTable, database } = context;\n const name = sourceTable.getName();\n database.on(`${name}.beforeCreate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkCreate`,\n UpdatedBy.beforeBulkCreateHook.bind(this),\n );\n database.on(`${name}.beforeUpdate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkUpdate`,\n UpdatedBy.beforeBulkUpdateHook.bind(this),\n );\n }\n\n public getDataType(): Function {\n return BELONGSTO;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/UpdatedBy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAA+E;AAC/E,mCAAuC;AAMvC,MAAqB,SAAU,SAAQ,oBAAS;
|
|
1
|
+
{"version":3,"sources":["fields/UpdatedBy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAA+E;AAC/E,mCAAuC;AAMvC,MAAqB,SAAU,SAAQ,oBAAS;IAC9C,MAAM,CAAC,oBAAoB,CAAkB,MAAM,EAAE,EAAE,OAAO,EAAE;QAC9D,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,oBAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,oBA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F;AAjDD,4BAiDC","file":"UpdatedBy.js","sourcesContent":["import { BelongsToOptions, BELONGSTO, FieldContext } from '@nocobase/database';\nimport { setUserValue } from './utils';\n\nexport interface UpdatedByOptions extends Omit<BelongsToOptions, 'type'> {\n type: 'updatedBy' | 'updatedby';\n}\n\nexport default class UpdatedBy extends BELONGSTO {\n static beforeBulkCreateHook(this: UpdatedBy, models, { context }) {\n models.forEach((model) => {\n setUserValue.call(this, model, { context });\n });\n }\n\n static beforeBulkUpdateHook(\n this: UpdatedBy,\n { attributes, fields, context },\n ) {\n if (!context) {\n return;\n }\n const { currentUser } = context.state;\n if (!currentUser) {\n return;\n }\n fields.push(this.options.foreignKey);\n attributes[this.options.foreignKey] = currentUser.get(\n this.options.targetKey,\n );\n }\n\n constructor({ type, ...options }: UpdatedByOptions, context: FieldContext) {\n super({ ...options, type: 'belongsTo' } as BelongsToOptions, context);\n // const Model = context.sourceTable.getModel();\n // // TODO(feature): 可考虑策略模式,以在需要时对外提供接口\n // Model.addHook('beforeCreate', setUserValue.bind(this));\n // Model.addHook('beforeBulkCreate', UpdatedBy.beforeBulkCreateHook.bind(this));\n // Model.addHook('beforeUpdate', setUserValue.bind(this));\n // Model.addHook('beforeBulkUpdate', UpdatedBy.beforeBulkUpdateHook.bind(this));\n const { sourceTable, database } = context;\n const name = sourceTable.getName();\n database.on(`${name}.beforeCreate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkCreate`,\n UpdatedBy.beforeBulkCreateHook.bind(this),\n );\n database.on(`${name}.beforeUpdate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkUpdate`,\n UpdatedBy.beforeBulkUpdateHook.bind(this),\n );\n }\n\n public getDataType(): Function {\n return BELONGSTO;\n }\n}\n"]}
|
package/lib/fields/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC;AAEzC,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,KAAA,EAAE,EAAE,OAAO,EAAE;;CAAA,QAoB3E","file":"utils.d.ts","sourcesContent":["import { CreatedBy, UpdatedBy } from
|
|
1
|
+
{"version":3,"sources":["fields/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC;AAEzC,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,KAAA,EAAE,EAAE,OAAO,EAAE;;CAAA,QAoB3E","file":"utils.d.ts","sourcesContent":["import { CreatedBy, UpdatedBy } from '.';\n\nexport function setUserValue(this: CreatedBy | UpdatedBy, model, { context }) {\n const { foreignKey } = this.options;\n // 已有外键数据(只在创建时生效)\n if (model.getDataValue(foreignKey)) {\n if (model.isNewRecord) {\n return;\n }\n const changed = model.changed();\n if (Array.isArray(changed) && changed.find((key) => key === foreignKey)) {\n return;\n }\n }\n if (!context) {\n return;\n }\n const { currentUser } = context.state;\n if (!currentUser) {\n return;\n }\n model.set(foreignKey, currentUser.get(this.options.targetKey));\n}\n"]}
|
package/lib/fields/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/utils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,YAAY,CAA8B,KAAK,EAAE,EAAE,OAAO,EAAE;IAC1E,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;IAEpC,IAAI,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;QAClC,IAAI,KAAK,CAAC,WAAW,EAAE;YACrB,OAAO;SACR;QACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,
|
|
1
|
+
{"version":3,"sources":["fields/utils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,YAAY,CAA8B,KAAK,EAAE,EAAE,OAAO,EAAE;IAC1E,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;IAEpC,IAAI,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;QAClC,IAAI,KAAK,CAAC,WAAW,EAAE;YACrB,OAAO;SACR;QACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,UAAU,CAAC,EAAE;YACvE,OAAO;SACR;KACF;IACD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO;KACR;IACD,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IACtC,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO;KACR;IACD,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AACjE,CAAC;AApBD,oCAoBC","file":"utils.js","sourcesContent":["import { CreatedBy, UpdatedBy } from '.';\n\nexport function setUserValue(this: CreatedBy | UpdatedBy, model, { context }) {\n const { foreignKey } = this.options;\n // 已有外键数据(只在创建时生效)\n if (model.getDataValue(foreignKey)) {\n if (model.isNewRecord) {\n return;\n }\n const changed = model.changed();\n if (Array.isArray(changed) && changed.find((key) => key === foreignKey)) {\n return;\n }\n }\n if (!context) {\n return;\n }\n const { currentUser } = context.state;\n if (!currentUser) {\n return;\n }\n model.set(foreignKey, currentUser.get(this.options.targetKey));\n}\n"]}
|
package/lib/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;;AAEjD,wBA6CmB","file":"server.d.ts","sourcesContent":["import path from 'path';\nimport { registerFields, Table } from '@nocobase/database';\nimport * as fields from './fields';\nimport * as usersActions from './actions/users';\nimport * as middlewares from './middlewares';\nimport { PluginOptions } from '@nocobase/server';\n\nexport default {\n name: 'users',\n async load() {\n const database = this.app.db;\n const resourcer = this.app.resourcer;\n\n registerFields(fields);\n\n this.app.on('db.init', async () => {\n const User = database.getModel('users');\n await User.create({\n nickname: '超级管理员',\n email: process.env.ADMIN_EMAIL,\n password: process.env.ADMIN_PASSWORD,\n });\n });\n\n database.on('afterTableInit', (table: Table) => {\n let { createdBy, updatedBy } = table.getOptions();\n if (createdBy !== false) {\n table.addField({\n type: 'createdBy',\n name: typeof createdBy === 'string' ? createdBy : 'createdBy',\n target: 'users',\n });\n }\n if (updatedBy !== false) {\n table.addField({\n type: 'updatedBy',\n name: typeof updatedBy === 'string' ? updatedBy : 'updatedBy',\n target: 'users',\n });\n }\n });\n\n database.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n\n for (const [key, action] of Object.entries(usersActions)) {\n resourcer.registerActionHandler(`users:${key}`, action);\n }\n\n resourcer.use(middlewares.parseToken({}));\n },\n} as PluginOptions;\n"]}
|
|
1
|
+
{"version":3,"sources":["server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;;AAEjD,wBA6CmB","file":"server.d.ts","sourcesContent":["import path from 'path';\nimport { registerFields, Table } from '@nocobase/database';\nimport * as fields from './fields';\nimport * as usersActions from './actions/users';\nimport * as middlewares from './middlewares';\nimport { PluginOptions } from '@nocobase/server';\n\nexport default {\n name: 'users',\n async load() {\n const database = this.app.db;\n const resourcer = this.app.resourcer;\n\n registerFields(fields);\n\n this.app.on('db.init', async () => {\n const User = database.getModel('users');\n await User.create({\n nickname: '超级管理员',\n email: process.env.ADMIN_EMAIL || 'admin@nocobase.com',\n password: process.env.ADMIN_PASSWORD || 'admin',\n });\n });\n\n database.on('afterTableInit', (table: Table) => {\n let { createdBy, updatedBy } = table.getOptions();\n if (createdBy !== false) {\n table.addField({\n type: 'createdBy',\n name: typeof createdBy === 'string' ? createdBy : 'createdBy',\n target: 'users',\n });\n }\n if (updatedBy !== false) {\n table.addField({\n type: 'updatedBy',\n name: typeof updatedBy === 'string' ? updatedBy : 'updatedBy',\n target: 'users',\n });\n }\n });\n\n database.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n\n for (const [key, action] of Object.entries(usersActions)) {\n resourcer.registerActionHandler(`users:${key}`, action);\n }\n\n resourcer.use(middlewares.parseToken({}));\n },\n} as PluginOptions;\n"]}
|
package/lib/server.js
CHANGED
|
@@ -120,8 +120,8 @@ exports.default = {
|
|
|
120
120
|
const User = database.getModel('users');
|
|
121
121
|
yield User.create({
|
|
122
122
|
nickname: '超级管理员',
|
|
123
|
-
email: process.env.ADMIN_EMAIL,
|
|
124
|
-
password: process.env.ADMIN_PASSWORD
|
|
123
|
+
email: process.env.ADMIN_EMAIL || 'admin@nocobase.com',
|
|
124
|
+
password: process.env.ADMIN_PASSWORD || 'admin'
|
|
125
125
|
});
|
|
126
126
|
}));
|
|
127
127
|
database.on('afterTableInit', table => {
|
package/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,iDAA2D;AAC3D,iDAAmC;AACnC,8DAAgD;AAChD,2DAA6C;AAG7C,kBAAe;IACb,IAAI,EAAE,OAAO;IACP,IAAI;;YACR,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;YAErC,yBAAc,CAAC,MAAM,CAAC,CAAC;YAEvB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAS,EAAE;gB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AS,CAAC,CAAC,CAAC,WAAW;wBAC7D,MAAM,EAAE,OAAO;qBAChB,CAAC,CAAC;iBACJ;gBACD,IAAI,SAAS,KAAK,KAAK,EAAE;oBACvB,KAAK,CAAC,QAAQ,CAAC;wBACb,IAAI,EAAE,WAAW;wBACjB,IAAI,EAAE,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;wBAC7D,MAAM,EAAE,OAAO;qBAChB,CAAC,CAAC;iBACJ;YACH,CAAC,CAAC,CAAC;YAEH,QAAQ,CAAC,MAAM,CAAC;gBACd,SAAS,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC;aAClD,CAAC,CAAC;YAEH,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;gBACxD,SAAS,CAAC,qBAAqB,CAAC,SAAS,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;aACzD;YAED,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5C,CAAC;KAAA;CACe,CAAC","file":"server.js","sourcesContent":["import path from 'path';\nimport { registerFields, Table } from '@nocobase/database';\nimport * as fields from './fields';\nimport * as usersActions from './actions/users';\nimport * as middlewares from './middlewares';\nimport { PluginOptions } from '@nocobase/server';\n\nexport default {\n name: 'users',\n async load() {\n const database = this.app.db;\n const resourcer = this.app.resourcer;\n\n registerFields(fields);\n\n this.app.on('db.init', async () => {\n const User = database.getModel('users');\n await User.create({\n nickname: '超级管理员',\n email: process.env.ADMIN_EMAIL || 'admin@nocobase.com',\n password: process.env.ADMIN_PASSWORD || 'admin',\n });\n });\n\n database.on('afterTableInit', (table: Table) => {\n let { createdBy, updatedBy } = table.getOptions();\n if (createdBy !== false) {\n table.addField({\n type: 'createdBy',\n name: typeof createdBy === 'string' ? createdBy : 'createdBy',\n target: 'users',\n });\n }\n if (updatedBy !== false) {\n table.addField({\n type: 'updatedBy',\n name: typeof updatedBy === 'string' ? updatedBy : 'updatedBy',\n target: 'users',\n });\n }\n });\n\n database.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n\n for (const [key, action] of Object.entries(usersActions)) {\n resourcer.registerActionHandler(`users:${key}`, action);\n }\n\n resourcer.use(middlewares.parseToken({}));\n },\n} as PluginOptions;\n"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-users",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.22",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@nocobase/server": "^0.5.0-alpha.
|
|
7
|
+
"@nocobase/server": "^0.5.0-alpha.22",
|
|
8
8
|
"crypto-random-string": "^3.3.0"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@nocobase/test": "^0.5.0-alpha.
|
|
11
|
+
"@nocobase/test": "^0.5.0-alpha.22"
|
|
12
12
|
},
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "22534716700c4ade1727b6e04543725c5e4f14f2"
|
|
14
14
|
}
|