@nocobase/plugin-auth 0.11.1-alpha.4 → 0.12.0-alpha.1
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/client.d.ts +2 -2
- package/client.js +1 -1
- package/dist/client/index.js +729 -0
- package/dist/index.js +20 -0
- package/dist/locale/zh-CN.js +20 -0
- package/dist/node_modules/cron/LICENSE +8 -0
- package/dist/node_modules/cron/lib/cron.js +1 -0
- package/dist/node_modules/cron/lib/job.js +215 -0
- package/dist/node_modules/cron/lib/time.js +817 -0
- package/dist/node_modules/cron/package.json +1 -0
- package/{lib → dist}/preset.d.ts +1 -1
- package/dist/preset.js +11 -0
- package/dist/server/actions/auth.js +22 -0
- package/dist/server/actions/authenticators.js +83 -0
- package/{src/server/basic-auth.ts → dist/server/basic-auth.js} +41 -42
- package/dist/server/collections/authenticators.js +97 -0
- package/dist/server/collections/token-blacklist.js +21 -0
- package/dist/server/collections/users-authenticators.js +71 -0
- package/dist/server/index.js +21 -0
- package/dist/server/locale/en-US.js +12 -0
- package/dist/server/locale/fr-FR.js +12 -0
- package/dist/server/locale/index.js +26 -0
- package/dist/server/locale/ja-JP.js +8 -0
- package/dist/server/locale/pt-BR.js +12 -0
- package/dist/server/locale/zh-CN.js +13 -0
- package/dist/server/migrations/20230506152253-basic-authenticator.js +26 -0
- package/dist/server/migrations/20230607174500-update-basic.js +29 -0
- package/{src/server/model/authenticator.ts → dist/server/model/authenticator.js} +19 -19
- package/dist/server/plugin.js +93 -0
- package/dist/server/token-blacklist.js +62 -0
- package/package.json +17 -28
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/lib/client/AuthProvider.js +0 -56
- package/lib/client/basic/Options.js +0 -51
- package/lib/client/basic/SigninPage.js +0 -100
- package/lib/client/basic/SignupPage.js +0 -131
- package/lib/client/index.js +0 -27
- package/lib/client/locale/index.js +0 -19
- package/lib/client/settings/Authenticator.js +0 -159
- package/lib/client/settings/Options.js +0 -56
- package/lib/client/settings/authType.js +0 -27
- package/lib/client/settings/schemas/authenticators.js +0 -438
- package/lib/index.js +0 -20
- package/lib/locale/zh-CN.js +0 -23
- package/lib/preset.js +0 -12
- package/lib/server/actions/auth.js +0 -51
- package/lib/server/actions/authenticators.js +0 -131
- package/lib/server/basic-auth.js +0 -183
- package/lib/server/collections/authenticators.js +0 -94
- package/lib/server/collections/token-blacklist.js +0 -21
- package/lib/server/collections/users-authenticators.js +0 -75
- package/lib/server/index.js +0 -20
- package/lib/server/locale/en-US.js +0 -15
- package/lib/server/locale/fr-FR.js +0 -15
- package/lib/server/locale/index.js +0 -27
- package/lib/server/locale/ja-JP.js +0 -11
- package/lib/server/locale/pt-BR.js +0 -15
- package/lib/server/locale/zh-CN.js +0 -16
- package/lib/server/migrations/20230506152253-basic-authenticator.js +0 -40
- package/lib/server/migrations/20230607174500-update-basic.js +0 -43
- package/lib/server/model/authenticator.js +0 -72
- package/lib/server/plugin.js +0 -129
- package/lib/server/token-blacklist.js +0 -82
- package/src/client/AuthProvider.tsx +0 -41
- package/src/client/basic/Options.tsx +0 -31
- package/src/client/basic/SigninPage.tsx +0 -65
- package/src/client/basic/SignupPage.tsx +0 -91
- package/src/client/index.tsx +0 -10
- package/src/client/locale/index.ts +0 -7
- package/src/client/settings/Authenticator.tsx +0 -95
- package/src/client/settings/Options.tsx +0 -34
- package/src/client/settings/authType.ts +0 -18
- package/src/client/settings/schemas/authenticators.ts +0 -402
- package/src/index.ts +0 -1
- package/src/locale/zh-CN.ts +0 -17
- package/src/preset.ts +0 -4
- package/src/server/__tests__/actions.test.ts +0 -142
- package/src/server/__tests__/token-blacklist.test.ts +0 -73
- package/src/server/actions/auth.ts +0 -20
- package/src/server/actions/authenticators.ts +0 -85
- package/src/server/collections/.gitkeep +0 -0
- package/src/server/collections/authenticators.ts +0 -98
- package/src/server/collections/token-blacklist.ts +0 -19
- package/src/server/collections/users-authenticators.ts +0 -73
- package/src/server/index.ts +0 -2
- package/src/server/locale/en-US.ts +0 -10
- package/src/server/locale/fr-FR.ts +0 -10
- package/src/server/locale/index.ts +0 -3
- package/src/server/locale/ja-JP.ts +0 -4
- package/src/server/locale/pt-BR.ts +0 -10
- package/src/server/locale/zh-CN.ts +0 -9
- package/src/server/migrations/20230506152253-basic-authenticator.ts +0 -22
- package/src/server/migrations/20230607174500-update-basic.ts +0 -25
- package/src/server/plugin.ts +0 -92
- package/src/server/token-blacklist.ts +0 -66
- /package/{lib → dist}/client/AuthProvider.d.ts +0 -0
- /package/{lib → dist}/client/basic/Options.d.ts +0 -0
- /package/{lib → dist}/client/basic/SigninPage.d.ts +0 -0
- /package/{lib → dist}/client/basic/SignupPage.d.ts +0 -0
- /package/{lib → dist}/client/index.d.ts +0 -0
- /package/{lib → dist}/client/locale/index.d.ts +0 -0
- /package/{lib → dist}/client/settings/Authenticator.d.ts +0 -0
- /package/{lib → dist}/client/settings/Options.d.ts +0 -0
- /package/{lib → dist}/client/settings/authType.d.ts +0 -0
- /package/{lib → dist}/client/settings/schemas/authenticators.d.ts +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/actions/auth.d.ts +0 -0
- /package/{lib → dist}/server/actions/authenticators.d.ts +0 -0
- /package/{lib → dist}/server/basic-auth.d.ts +0 -0
- /package/{lib → dist}/server/collections/authenticators.d.ts +0 -0
- /package/{lib → dist}/server/collections/token-blacklist.d.ts +0 -0
- /package/{lib → dist}/server/collections/users-authenticators.d.ts +0 -0
- /package/{lib → dist}/server/index.d.ts +0 -0
- /package/{lib → dist}/server/locale/en-US.d.ts +0 -0
- /package/{lib → dist}/server/locale/fr-FR.d.ts +0 -0
- /package/{lib → dist}/server/locale/index.d.ts +0 -0
- /package/{lib → dist}/server/locale/ja-JP.d.ts +0 -0
- /package/{lib → dist}/server/locale/pt-BR.d.ts +0 -0
- /package/{lib → dist}/server/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/migrations/20230506152253-basic-authenticator.d.ts +0 -0
- /package/{lib → dist}/server/migrations/20230607174500-update-basic.d.ts +0 -0
- /package/{lib → dist}/server/model/authenticator.d.ts +0 -0
- /package/{lib → dist}/server/plugin.d.ts +0 -0
- /package/{lib → dist}/server/token-blacklist.d.ts +0 -0
package/lib/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "AuthModel", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _server.AuthModel;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "default", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _server.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _server = _interopRequireWildcard(require("./server"));
|
|
19
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/lib/locale/zh-CN.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
const locale = {
|
|
8
|
-
'Auth Type': '认证类型',
|
|
9
|
-
Authenticators: '认证器',
|
|
10
|
-
Authentication: '用户认证',
|
|
11
|
-
'Sign in via email': '邮箱登录',
|
|
12
|
-
'Not allowed to sign up': '禁止注册',
|
|
13
|
-
'Allow to sign up': '允许注册',
|
|
14
|
-
'The email is incorrect, please re-enter': '邮箱有误,请重新输入',
|
|
15
|
-
'Please fill in your email address': '请填写邮箱',
|
|
16
|
-
'The password is incorrect, please re-enter': '密码有误,请重新输入',
|
|
17
|
-
'Not a valid cellphone number, please re-enter': '不是有效的手机号,请重新输入',
|
|
18
|
-
'The phone number has been registered, please login directly': '手机号已注册,请直接登录',
|
|
19
|
-
'The phone number is not registered, please register first': '手机号未注册,请先注册',
|
|
20
|
-
'Please keep and enable at least one authenticator': '请至少保留并启用一个认证器'
|
|
21
|
-
};
|
|
22
|
-
var _default = locale;
|
|
23
|
-
exports.default = _default;
|
package/lib/preset.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.presetAuthenticator = exports.presetAuthType = exports.namespace = void 0;
|
|
7
|
-
const presetAuthType = 'Email/Password';
|
|
8
|
-
exports.presetAuthType = presetAuthType;
|
|
9
|
-
const presetAuthenticator = 'basic';
|
|
10
|
-
exports.presetAuthenticator = presetAuthenticator;
|
|
11
|
-
const namespace = require('../package.json').name;
|
|
12
|
-
exports.namespace = namespace;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
9
|
-
var _default = {
|
|
10
|
-
lostPassword: function () {
|
|
11
|
-
var _lostPassword = _asyncToGenerator(function* (ctx, next) {
|
|
12
|
-
ctx.body = yield ctx.auth.lostPassword();
|
|
13
|
-
yield next();
|
|
14
|
-
});
|
|
15
|
-
function lostPassword(_x, _x2) {
|
|
16
|
-
return _lostPassword.apply(this, arguments);
|
|
17
|
-
}
|
|
18
|
-
return lostPassword;
|
|
19
|
-
}(),
|
|
20
|
-
resetPassword: function () {
|
|
21
|
-
var _resetPassword = _asyncToGenerator(function* (ctx, next) {
|
|
22
|
-
ctx.body = yield ctx.auth.resetPassword();
|
|
23
|
-
yield next();
|
|
24
|
-
});
|
|
25
|
-
function resetPassword(_x3, _x4) {
|
|
26
|
-
return _resetPassword.apply(this, arguments);
|
|
27
|
-
}
|
|
28
|
-
return resetPassword;
|
|
29
|
-
}(),
|
|
30
|
-
getUserByResetToken: function () {
|
|
31
|
-
var _getUserByResetToken = _asyncToGenerator(function* (ctx, next) {
|
|
32
|
-
ctx.body = yield ctx.auth.getUserByResetToken();
|
|
33
|
-
yield next();
|
|
34
|
-
});
|
|
35
|
-
function getUserByResetToken(_x5, _x6) {
|
|
36
|
-
return _getUserByResetToken.apply(this, arguments);
|
|
37
|
-
}
|
|
38
|
-
return getUserByResetToken;
|
|
39
|
-
}(),
|
|
40
|
-
changePassword: function () {
|
|
41
|
-
var _changePassword = _asyncToGenerator(function* (ctx, next) {
|
|
42
|
-
ctx.body = yield ctx.auth.changePassword();
|
|
43
|
-
yield next();
|
|
44
|
-
});
|
|
45
|
-
function changePassword(_x7, _x8) {
|
|
46
|
-
return _changePassword.apply(this, arguments);
|
|
47
|
-
}
|
|
48
|
-
return changePassword;
|
|
49
|
-
}()
|
|
50
|
-
};
|
|
51
|
-
exports.default = _default;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _preset = require("../../preset");
|
|
8
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
9
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
-
function checkCount(_x, _x2) {
|
|
11
|
-
return _checkCount.apply(this, arguments);
|
|
12
|
-
}
|
|
13
|
-
function _checkCount() {
|
|
14
|
-
_checkCount = _asyncToGenerator(function* (repository, id) {
|
|
15
|
-
// TODO(yangqia): This is a temporary solution, may cause concurrency problem.
|
|
16
|
-
const count = yield repository.count({
|
|
17
|
-
filter: {
|
|
18
|
-
enabled: true,
|
|
19
|
-
id: {
|
|
20
|
-
$ne: id
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
if (count <= 0) {
|
|
25
|
-
throw new Error('Please keep and enable at least one authenticator');
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return _checkCount.apply(this, arguments);
|
|
29
|
-
}
|
|
30
|
-
var _default = {
|
|
31
|
-
listTypes: function () {
|
|
32
|
-
var _listTypes = _asyncToGenerator(function* (ctx, next) {
|
|
33
|
-
ctx.body = ctx.app.authManager.listTypes();
|
|
34
|
-
yield next();
|
|
35
|
-
});
|
|
36
|
-
function listTypes(_x3, _x4) {
|
|
37
|
-
return _listTypes.apply(this, arguments);
|
|
38
|
-
}
|
|
39
|
-
return listTypes;
|
|
40
|
-
}(),
|
|
41
|
-
publicList: function () {
|
|
42
|
-
var _publicList = _asyncToGenerator(function* (ctx, next) {
|
|
43
|
-
const repo = ctx.db.getRepository('authenticators');
|
|
44
|
-
const authenticators = yield repo.find({
|
|
45
|
-
fields: ['name', 'authType', 'title', 'options', 'sort'],
|
|
46
|
-
filter: {
|
|
47
|
-
enabled: true
|
|
48
|
-
},
|
|
49
|
-
sort: 'sort'
|
|
50
|
-
});
|
|
51
|
-
ctx.body = authenticators.map(authenticator => {
|
|
52
|
-
var _authenticator$option;
|
|
53
|
-
return {
|
|
54
|
-
name: authenticator.name,
|
|
55
|
-
authType: authenticator.authType,
|
|
56
|
-
title: authenticator.title,
|
|
57
|
-
options: ((_authenticator$option = authenticator.options) === null || _authenticator$option === void 0 ? void 0 : _authenticator$option.public) || {}
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
yield next();
|
|
61
|
-
});
|
|
62
|
-
function publicList(_x5, _x6) {
|
|
63
|
-
return _publicList.apply(this, arguments);
|
|
64
|
-
}
|
|
65
|
-
return publicList;
|
|
66
|
-
}(),
|
|
67
|
-
destroy: function () {
|
|
68
|
-
var _destroy = _asyncToGenerator(function* (ctx, next) {
|
|
69
|
-
const repository = ctx.db.getRepository('authenticators');
|
|
70
|
-
const _ctx$action$params = ctx.action.params,
|
|
71
|
-
filterByTk = _ctx$action$params.filterByTk,
|
|
72
|
-
filter = _ctx$action$params.filter;
|
|
73
|
-
try {
|
|
74
|
-
yield checkCount(repository, filterByTk);
|
|
75
|
-
} catch (err) {
|
|
76
|
-
ctx.throw(400, ctx.t(err.message, {
|
|
77
|
-
ns: _preset.namespace
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
const instance = yield repository.destroy({
|
|
81
|
-
filter,
|
|
82
|
-
filterByTk,
|
|
83
|
-
context: ctx
|
|
84
|
-
});
|
|
85
|
-
ctx.body = instance;
|
|
86
|
-
yield next();
|
|
87
|
-
});
|
|
88
|
-
function destroy(_x7, _x8) {
|
|
89
|
-
return _destroy.apply(this, arguments);
|
|
90
|
-
}
|
|
91
|
-
return destroy;
|
|
92
|
-
}(),
|
|
93
|
-
update: function () {
|
|
94
|
-
var _update = _asyncToGenerator(function* (ctx, next) {
|
|
95
|
-
const repository = ctx.db.getRepository('authenticators');
|
|
96
|
-
const _ctx$action$params2 = ctx.action.params,
|
|
97
|
-
forceUpdate = _ctx$action$params2.forceUpdate,
|
|
98
|
-
filterByTk = _ctx$action$params2.filterByTk,
|
|
99
|
-
values = _ctx$action$params2.values,
|
|
100
|
-
whitelist = _ctx$action$params2.whitelist,
|
|
101
|
-
blacklist = _ctx$action$params2.blacklist,
|
|
102
|
-
filter = _ctx$action$params2.filter,
|
|
103
|
-
updateAssociationValues = _ctx$action$params2.updateAssociationValues;
|
|
104
|
-
if (!values.enabled) {
|
|
105
|
-
try {
|
|
106
|
-
yield checkCount(repository, values.id);
|
|
107
|
-
} catch (err) {
|
|
108
|
-
ctx.throw(400, ctx.t(err.message, {
|
|
109
|
-
ns: _preset.namespace
|
|
110
|
-
}));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
ctx.body = yield repository.update({
|
|
114
|
-
filterByTk,
|
|
115
|
-
values,
|
|
116
|
-
whitelist,
|
|
117
|
-
blacklist,
|
|
118
|
-
filter,
|
|
119
|
-
updateAssociationValues,
|
|
120
|
-
context: ctx,
|
|
121
|
-
forceUpdate
|
|
122
|
-
});
|
|
123
|
-
yield next();
|
|
124
|
-
});
|
|
125
|
-
function update(_x9, _x10) {
|
|
126
|
-
return _update.apply(this, arguments);
|
|
127
|
-
}
|
|
128
|
-
return update;
|
|
129
|
-
}()
|
|
130
|
-
};
|
|
131
|
-
exports.default = _default;
|
package/lib/server/basic-auth.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.BasicAuth = void 0;
|
|
7
|
-
function _auth() {
|
|
8
|
-
const data = require("@nocobase/auth");
|
|
9
|
-
_auth = function _auth() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _crypto() {
|
|
15
|
-
const data = _interopRequireDefault(require("crypto"));
|
|
16
|
-
_crypto = function _crypto() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
var _preset = require("../preset");
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
24
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
25
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
26
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
27
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
28
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
29
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
30
|
-
class BasicAuth extends _auth().BaseAuth {
|
|
31
|
-
constructor(config) {
|
|
32
|
-
const userCollection = config.ctx.db.getCollection('users');
|
|
33
|
-
super(_objectSpread(_objectSpread({}, config), {}, {
|
|
34
|
-
userCollection
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
validate() {
|
|
38
|
-
var _this = this;
|
|
39
|
-
return _asyncToGenerator(function* () {
|
|
40
|
-
const ctx = _this.ctx;
|
|
41
|
-
const _ctx$action$params = ctx.action.params,
|
|
42
|
-
_ctx$action$params$un = _ctx$action$params.uniqueField,
|
|
43
|
-
uniqueField = _ctx$action$params$un === void 0 ? 'email' : _ctx$action$params$un,
|
|
44
|
-
values = _ctx$action$params.values;
|
|
45
|
-
if (!values[uniqueField]) {
|
|
46
|
-
ctx.throw(400, ctx.t('Please fill in your email address', {
|
|
47
|
-
ns: _preset.namespace
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
const user = yield _this.userRepository.findOne({
|
|
51
|
-
where: {
|
|
52
|
-
[uniqueField]: values[uniqueField]
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
if (!user) {
|
|
56
|
-
ctx.throw(401, ctx.t('The email is incorrect, please re-enter', {
|
|
57
|
-
ns: _preset.namespace
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
const field = _this.userCollection.getField('password');
|
|
61
|
-
const valid = yield field.verify(values.password, user.password);
|
|
62
|
-
if (!valid) {
|
|
63
|
-
ctx.throw(401, ctx.t('The password is incorrect, please re-enter', {
|
|
64
|
-
ns: _preset.namespace
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
return user;
|
|
68
|
-
})();
|
|
69
|
-
}
|
|
70
|
-
signUp() {
|
|
71
|
-
var _this2 = this;
|
|
72
|
-
return _asyncToGenerator(function* () {
|
|
73
|
-
var _this2$authenticator$;
|
|
74
|
-
const ctx = _this2.ctx;
|
|
75
|
-
const options = ((_this2$authenticator$ = _this2.authenticator.options) === null || _this2$authenticator$ === void 0 ? void 0 : _this2$authenticator$.public) || {};
|
|
76
|
-
if (!options.allowSignUp) {
|
|
77
|
-
ctx.throw(403, ctx.t('Not allowed to sign up', {
|
|
78
|
-
ns: _preset.namespace
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
const User = ctx.db.getRepository('users');
|
|
82
|
-
const values = ctx.action.params.values;
|
|
83
|
-
const user = yield User.create({
|
|
84
|
-
values
|
|
85
|
-
});
|
|
86
|
-
return user;
|
|
87
|
-
})();
|
|
88
|
-
}
|
|
89
|
-
lostPassword() {
|
|
90
|
-
var _this3 = this;
|
|
91
|
-
return _asyncToGenerator(function* () {
|
|
92
|
-
const ctx = _this3.ctx;
|
|
93
|
-
const email = ctx.action.params.values.email;
|
|
94
|
-
if (!email) {
|
|
95
|
-
ctx.throw(400, ctx.t('Please fill in your email address', {
|
|
96
|
-
ns: _preset.namespace
|
|
97
|
-
}));
|
|
98
|
-
}
|
|
99
|
-
const user = yield _this3.userRepository.findOne({
|
|
100
|
-
where: {
|
|
101
|
-
email
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
if (!user) {
|
|
105
|
-
ctx.throw(401, ctx.t('The email is incorrect, please re-enter', {
|
|
106
|
-
ns: _preset.namespace
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
user.resetToken = _crypto().default.randomBytes(20).toString('hex');
|
|
110
|
-
yield user.save();
|
|
111
|
-
return user;
|
|
112
|
-
})();
|
|
113
|
-
}
|
|
114
|
-
resetPassword() {
|
|
115
|
-
var _this4 = this;
|
|
116
|
-
return _asyncToGenerator(function* () {
|
|
117
|
-
const ctx = _this4.ctx;
|
|
118
|
-
const _ctx$action$params$va = ctx.action.params.values,
|
|
119
|
-
email = _ctx$action$params$va.email,
|
|
120
|
-
password = _ctx$action$params$va.password,
|
|
121
|
-
resetToken = _ctx$action$params$va.resetToken;
|
|
122
|
-
const user = yield _this4.userRepository.findOne({
|
|
123
|
-
where: {
|
|
124
|
-
email,
|
|
125
|
-
resetToken
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
if (!user) {
|
|
129
|
-
ctx.throw(404);
|
|
130
|
-
}
|
|
131
|
-
user.token = null;
|
|
132
|
-
user.resetToken = null;
|
|
133
|
-
user.password = password;
|
|
134
|
-
yield user.save();
|
|
135
|
-
return user;
|
|
136
|
-
})();
|
|
137
|
-
}
|
|
138
|
-
getUserByResetToken() {
|
|
139
|
-
var _this5 = this;
|
|
140
|
-
return _asyncToGenerator(function* () {
|
|
141
|
-
const ctx = _this5.ctx;
|
|
142
|
-
const token = ctx.action.params.token;
|
|
143
|
-
const user = yield _this5.userRepository.findOne({
|
|
144
|
-
where: {
|
|
145
|
-
resetToken: token
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
if (!user) {
|
|
149
|
-
ctx.throw(401);
|
|
150
|
-
}
|
|
151
|
-
return user;
|
|
152
|
-
})();
|
|
153
|
-
}
|
|
154
|
-
changePassword() {
|
|
155
|
-
var _this6 = this;
|
|
156
|
-
return _asyncToGenerator(function* () {
|
|
157
|
-
const ctx = _this6.ctx;
|
|
158
|
-
const _ctx$action$params$va2 = ctx.action.params.values,
|
|
159
|
-
oldPassword = _ctx$action$params$va2.oldPassword,
|
|
160
|
-
newPassword = _ctx$action$params$va2.newPassword;
|
|
161
|
-
const currentUser = ctx.auth.user;
|
|
162
|
-
if (!currentUser) {
|
|
163
|
-
ctx.throw(401);
|
|
164
|
-
}
|
|
165
|
-
const user = yield _this6.userRepository.findOne({
|
|
166
|
-
where: {
|
|
167
|
-
email: currentUser.email
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
const pwd = _this6.userCollection.getField('password');
|
|
171
|
-
const isValid = yield pwd.verify(oldPassword, user.password);
|
|
172
|
-
if (!isValid) {
|
|
173
|
-
ctx.throw(401, ctx.t('The password is incorrect, please re-enter', {
|
|
174
|
-
ns: _preset.namespace
|
|
175
|
-
}));
|
|
176
|
-
}
|
|
177
|
-
user.password = newPassword;
|
|
178
|
-
yield user.save();
|
|
179
|
-
return currentUser;
|
|
180
|
-
})();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
exports.BasicAuth = BasicAuth;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Collection for extended authentication methods,
|
|
9
|
-
*/
|
|
10
|
-
var _default = {
|
|
11
|
-
namespace: 'auth.auth',
|
|
12
|
-
duplicator: 'optional',
|
|
13
|
-
name: 'authenticators',
|
|
14
|
-
sortable: true,
|
|
15
|
-
title: '{{t("Authenticators")}}',
|
|
16
|
-
model: 'AuthModel',
|
|
17
|
-
createdBy: true,
|
|
18
|
-
updatedBy: true,
|
|
19
|
-
logging: true,
|
|
20
|
-
fields: [{
|
|
21
|
-
name: 'id',
|
|
22
|
-
type: 'bigInt',
|
|
23
|
-
autoIncrement: true,
|
|
24
|
-
primaryKey: true,
|
|
25
|
-
allowNull: false,
|
|
26
|
-
interface: 'id'
|
|
27
|
-
}, {
|
|
28
|
-
interface: 'input',
|
|
29
|
-
type: 'string',
|
|
30
|
-
name: 'name',
|
|
31
|
-
allowNull: false,
|
|
32
|
-
unique: true,
|
|
33
|
-
uiSchema: {
|
|
34
|
-
type: 'string',
|
|
35
|
-
title: '{{t("Name")}}',
|
|
36
|
-
'x-component': 'Input',
|
|
37
|
-
required: true
|
|
38
|
-
}
|
|
39
|
-
}, {
|
|
40
|
-
interface: 'input',
|
|
41
|
-
type: 'string',
|
|
42
|
-
name: 'authType',
|
|
43
|
-
allowNull: false,
|
|
44
|
-
uiSchema: {
|
|
45
|
-
type: 'string',
|
|
46
|
-
title: '{{t("Auth Type")}}',
|
|
47
|
-
'x-component': 'Input',
|
|
48
|
-
required: true
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
interface: 'input',
|
|
52
|
-
type: 'string',
|
|
53
|
-
name: 'title',
|
|
54
|
-
uiSchema: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
title: '{{t("Title")}}',
|
|
57
|
-
'x-component': 'Input'
|
|
58
|
-
},
|
|
59
|
-
translation: true
|
|
60
|
-
}, {
|
|
61
|
-
interface: 'textarea',
|
|
62
|
-
type: 'string',
|
|
63
|
-
name: 'description',
|
|
64
|
-
allowNull: false,
|
|
65
|
-
defaultValue: '',
|
|
66
|
-
uiSchema: {
|
|
67
|
-
type: 'string',
|
|
68
|
-
title: '{{t("Description")}}',
|
|
69
|
-
'x-component': 'Input',
|
|
70
|
-
required: true
|
|
71
|
-
}
|
|
72
|
-
}, {
|
|
73
|
-
type: 'json',
|
|
74
|
-
name: 'options',
|
|
75
|
-
allowNull: false,
|
|
76
|
-
defaultValue: {}
|
|
77
|
-
}, {
|
|
78
|
-
type: 'boolean',
|
|
79
|
-
name: 'enabled',
|
|
80
|
-
defaultValue: false
|
|
81
|
-
}, {
|
|
82
|
-
interface: 'm2m',
|
|
83
|
-
type: 'belongsToMany',
|
|
84
|
-
name: 'users',
|
|
85
|
-
target: 'users',
|
|
86
|
-
foreignKey: 'authenticator',
|
|
87
|
-
otherKey: 'userId',
|
|
88
|
-
onDelete: 'CASCADE',
|
|
89
|
-
sourceKey: 'name',
|
|
90
|
-
targetKey: 'id',
|
|
91
|
-
through: 'usersAuthenticators'
|
|
92
|
-
}]
|
|
93
|
-
};
|
|
94
|
-
exports.default = _default;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _default = {
|
|
8
|
-
namespace: 'auth.token-black',
|
|
9
|
-
duplicator: 'optional',
|
|
10
|
-
name: 'tokenBlacklist',
|
|
11
|
-
model: 'TokenBlacklistModel',
|
|
12
|
-
fields: [{
|
|
13
|
-
type: 'string',
|
|
14
|
-
name: 'token',
|
|
15
|
-
index: true
|
|
16
|
-
}, {
|
|
17
|
-
type: 'date',
|
|
18
|
-
name: 'expiration'
|
|
19
|
-
}]
|
|
20
|
-
};
|
|
21
|
-
exports.default = _default;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Collection for user information of extended authentication methods,
|
|
9
|
-
* such as saml, oicd, oauth, sms, etc.
|
|
10
|
-
*/
|
|
11
|
-
var _default = {
|
|
12
|
-
namespace: 'auth.auth',
|
|
13
|
-
duplicator: {
|
|
14
|
-
dumpable: 'optional',
|
|
15
|
-
/**
|
|
16
|
-
* When dump this collection, the users collection is required to be dumped.
|
|
17
|
-
*/
|
|
18
|
-
with: 'users'
|
|
19
|
-
},
|
|
20
|
-
name: 'usersAuthenticators',
|
|
21
|
-
title: '{{t("Users Authenticators")}}',
|
|
22
|
-
model: 'UserAuthModel',
|
|
23
|
-
createdBy: true,
|
|
24
|
-
updatedBy: true,
|
|
25
|
-
logging: true,
|
|
26
|
-
fields: [
|
|
27
|
-
/**
|
|
28
|
-
* uuid:
|
|
29
|
-
* Unique user id of the authentication method, such as wechat openid, phone number, etc.
|
|
30
|
-
*/
|
|
31
|
-
{
|
|
32
|
-
name: 'uuid',
|
|
33
|
-
interface: 'input',
|
|
34
|
-
type: 'string',
|
|
35
|
-
allowNull: false,
|
|
36
|
-
uiSchema: {
|
|
37
|
-
type: 'string',
|
|
38
|
-
title: '{{t("UUID")}}',
|
|
39
|
-
'x-component': 'Input',
|
|
40
|
-
required: true
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
interface: 'input',
|
|
44
|
-
type: 'string',
|
|
45
|
-
name: 'nickname',
|
|
46
|
-
allowNull: false,
|
|
47
|
-
defaultValue: '',
|
|
48
|
-
uiSchema: {
|
|
49
|
-
type: 'string',
|
|
50
|
-
title: '{{t("Nickname")}}',
|
|
51
|
-
'x-component': 'Input'
|
|
52
|
-
}
|
|
53
|
-
}, {
|
|
54
|
-
interface: 'attachment',
|
|
55
|
-
type: 'string',
|
|
56
|
-
name: 'avatar',
|
|
57
|
-
allowNull: false,
|
|
58
|
-
defaultValue: '',
|
|
59
|
-
uiSchema: {
|
|
60
|
-
type: 'string',
|
|
61
|
-
title: '{{t("Avatar")}}',
|
|
62
|
-
'x-component': 'Upload'
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
/**
|
|
66
|
-
* meta:
|
|
67
|
-
* Metadata, some other information of the authentication method.
|
|
68
|
-
*/
|
|
69
|
-
{
|
|
70
|
-
type: 'json',
|
|
71
|
-
name: 'meta',
|
|
72
|
-
defaultValue: {}
|
|
73
|
-
}]
|
|
74
|
-
};
|
|
75
|
-
exports.default = _default;
|
package/lib/server/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "AuthModel", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _authenticator.AuthModel;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "default", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _plugin.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
19
|
-
var _authenticator = require("./model/authenticator");
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _default = {
|
|
8
|
-
'The email is incorrect, please re-enter': 'The email is incorrect, please re-enter',
|
|
9
|
-
'Please fill in your email address': 'Please fill in your email address',
|
|
10
|
-
'The password is incorrect, please re-enter': 'The password is incorrect, please re-enter',
|
|
11
|
-
'Not a valid cellphone number, please re-enter': 'Not a valid cellphone number, please re-enter',
|
|
12
|
-
'The phone number has been registered, please login directly': 'The phone number has been registered, please login directly',
|
|
13
|
-
'The phone number is not registered, please register first': 'The phone number is not registered, please register first'
|
|
14
|
-
};
|
|
15
|
-
exports.default = _default;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _default = {
|
|
8
|
-
'The email is incorrect, please re-enter': 'L\'email est incorrect, veuillez le saisir à nouveau',
|
|
9
|
-
'Please fill in your email address': 'Veuillez remplir votre adresse e-mail',
|
|
10
|
-
'The password is incorrect, please re-enter': 'Le mot de passe est incorrect, veuillez le saisir à nouveau',
|
|
11
|
-
'Not a valid cellphone number, please re-enter': 'Numéro de téléphone portable non valide, veuillez le saisir à nouveau',
|
|
12
|
-
'The phone number has been registered, please login directly': 'Le numéro de téléphone a été enregistré, veuillez vous connecter directement',
|
|
13
|
-
'The phone number is not registered, please register first': 'Le numéro de téléphone n\'est pas enregistré, veuillez vous inscrire d\'abord'
|
|
14
|
-
};
|
|
15
|
-
exports.default = _default;
|