@nocobase/plugin-users 0.11.1-alpha.5 → 0.12.0-alpha.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.
- package/dist/client/index.js +11 -0
- package/{lib → dist}/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/locale/en-US.js +12 -0
- package/dist/locale/es-ES.js +12 -0
- package/dist/locale/fr-FR.js +12 -0
- package/dist/locale/ja-JP.js +8 -0
- package/dist/locale/pt-BR.js +12 -0
- package/dist/locale/zh-CN.js +12 -0
- package/dist/server/actions/users.js +152 -0
- package/dist/server/authenticators/index.js +23 -0
- package/dist/server/authenticators/password.js +31 -0
- package/dist/server/collections/users.js +91 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +18 -0
- package/dist/server/jwt-service.js +34 -0
- package/dist/server/locale/en-US.js +12 -0
- package/dist/server/locale/es-ES.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 +12 -0
- package/dist/server/middlewares/check.js +13 -0
- package/dist/server/middlewares/index.js +15 -0
- package/{src/server/middlewares/parseToken.ts → dist/server/middlewares/parseToken.js} +11 -12
- package/dist/server/migrations/20220818072639-add-users-phone.js +43 -0
- package/dist/server/server.js +249 -0
- package/package.json +17 -28
- package/lib/client/index.js +0 -22
- package/lib/index.js +0 -13
- package/lib/locale/en-US.js +0 -15
- package/lib/locale/es-ES.js +0 -15
- package/lib/locale/fr-FR.js +0 -15
- package/lib/locale/ja-JP.js +0 -11
- package/lib/locale/pt-BR.js +0 -15
- package/lib/locale/zh-CN.js +0 -15
- package/lib/server/actions/users.js +0 -253
- package/lib/server/authenticators/index.js +0 -44
- package/lib/server/authenticators/password.js +0 -49
- package/lib/server/collections/users.js +0 -90
- package/lib/server/index.d.ts +0 -2
- package/lib/server/index.js +0 -16
- package/lib/server/jwt-service.js +0 -42
- package/lib/server/locale/en-US.js +0 -15
- package/lib/server/locale/es-ES.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 -15
- package/lib/server/middlewares/check.js +0 -24
- package/lib/server/middlewares/index.js +0 -19
- package/lib/server/middlewares/parseToken.js +0 -75
- package/lib/server/migrations/20220818072639-add-users-phone.js +0 -57
- package/lib/server/server.js +0 -312
- package/src/client/index.ts +0 -7
- package/src/index.ts +0 -1
- package/src/locale/en-US.ts +0 -10
- package/src/locale/es-ES.ts +0 -8
- package/src/locale/fr-FR.ts +0 -11
- package/src/locale/ja-JP.ts +0 -4
- package/src/locale/pt-BR.ts +0 -10
- package/src/locale/zh-CN.ts +0 -8
- package/src/server/__tests__/actions.test.ts +0 -79
- package/src/server/__tests__/fields.test.ts +0 -90
- package/src/server/__tests__/utils.ts +0 -8
- package/src/server/actions/users.ts +0 -148
- package/src/server/authenticators/index.ts +0 -26
- package/src/server/authenticators/password.ts +0 -34
- package/src/server/collections/users.ts +0 -89
- package/src/server/index.ts +0 -3
- package/src/server/jwt-service.ts +0 -34
- package/src/server/locale/en-US.ts +0 -10
- package/src/server/locale/es-ES.ts +0 -8
- package/src/server/locale/fr-FR.ts +0 -11
- 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 -8
- package/src/server/middlewares/check.ts +0 -11
- package/src/server/middlewares/index.ts +0 -2
- package/src/server/migrations/20220818072639-add-users-phone.ts +0 -39
- package/src/server/server.ts +0 -253
- /package/{lib → dist}/client/index.d.ts +0 -0
- /package/{lib → dist}/locale/en-US.d.ts +0 -0
- /package/{lib → dist}/locale/es-ES.d.ts +0 -0
- /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
- /package/{lib → dist}/locale/ja-JP.d.ts +0 -0
- /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
- /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/actions/users.d.ts +0 -0
- /package/{lib → dist}/server/authenticators/index.d.ts +0 -0
- /package/{lib → dist}/server/authenticators/password.d.ts +0 -0
- /package/{lib → dist}/server/collections/users.d.ts +0 -0
- /package/{lib → dist}/server/jwt-service.d.ts +0 -0
- /package/{lib → dist}/server/locale/en-US.d.ts +0 -0
- /package/{lib → dist}/server/locale/es-ES.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/middlewares/check.d.ts +0 -0
- /package/{lib → dist}/server/middlewares/index.d.ts +0 -0
- /package/{lib → dist}/server/middlewares/parseToken.d.ts +0 -0
- /package/{lib → dist}/server/migrations/20220818072639-add-users-phone.d.ts +0 -0
- /package/{lib → dist}/server/server.d.ts +0 -0
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import Database from '@nocobase/database';
|
|
2
|
-
import PluginACL from '@nocobase/plugin-acl';
|
|
3
|
-
import UsersPlugin from '@nocobase/plugin-users';
|
|
4
|
-
import { mockServer, MockServer } from '@nocobase/test';
|
|
5
|
-
import { userPluginConfig } from './utils';
|
|
6
|
-
describe('createdBy/updatedBy', () => {
|
|
7
|
-
let api: MockServer;
|
|
8
|
-
let db: Database;
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
api = mockServer();
|
|
12
|
-
api.plugin(UsersPlugin, userPluginConfig);
|
|
13
|
-
api.plugin(PluginACL, { name: 'acl' });
|
|
14
|
-
await api.loadAndInstall({ clean: true });
|
|
15
|
-
db = api.db;
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(async () => {
|
|
19
|
-
await db.close();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('collection definition', () => {
|
|
23
|
-
it('case 1', async () => {
|
|
24
|
-
const Post = db.collection({
|
|
25
|
-
name: 'posts',
|
|
26
|
-
createdBy: true,
|
|
27
|
-
updatedBy: true,
|
|
28
|
-
});
|
|
29
|
-
expect(Post.hasField('createdBy')).toBeTruthy();
|
|
30
|
-
expect(Post.hasField('updatedBy')).toBeTruthy();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('case 2', async () => {
|
|
34
|
-
const Post = db.collection({
|
|
35
|
-
name: 'posts',
|
|
36
|
-
createdBy: true,
|
|
37
|
-
updatedBy: true,
|
|
38
|
-
});
|
|
39
|
-
await db.sync();
|
|
40
|
-
const currentUser = await db.getCollection('users').model.create();
|
|
41
|
-
await Post.repository.create({
|
|
42
|
-
context: {
|
|
43
|
-
state: {
|
|
44
|
-
currentUser,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
const p2 = await Post.repository.findOne({
|
|
49
|
-
appends: ['createdBy', 'updatedBy'],
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const data = p2.toJSON();
|
|
53
|
-
expect(data.createdBy.id).toBe(currentUser.get('id'));
|
|
54
|
-
expect(data.updatedBy.id).toBe(currentUser.get('id'));
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('case 3', async () => {
|
|
58
|
-
const Post = db.collection({
|
|
59
|
-
name: 'posts',
|
|
60
|
-
createdBy: true,
|
|
61
|
-
updatedBy: true,
|
|
62
|
-
});
|
|
63
|
-
await db.sync();
|
|
64
|
-
const user1 = await db.getCollection('users').model.create();
|
|
65
|
-
const user2 = await db.getCollection('users').model.create();
|
|
66
|
-
const p1 = await Post.repository.create({
|
|
67
|
-
context: {
|
|
68
|
-
state: {
|
|
69
|
-
currentUser: user1,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
await Post.repository.update({
|
|
74
|
-
values: {},
|
|
75
|
-
filterByTk: p1.id,
|
|
76
|
-
context: {
|
|
77
|
-
state: {
|
|
78
|
-
currentUser: user2,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
const p2 = await Post.repository.findOne({
|
|
83
|
-
appends: ['createdBy', 'updatedBy'],
|
|
84
|
-
});
|
|
85
|
-
const data = p2.toJSON();
|
|
86
|
-
expect(data.createdBy.id).toBe(user1.get('id'));
|
|
87
|
-
expect(data.updatedBy.id).toBe(user2.get('id'));
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { Context, Next } from '@nocobase/actions';
|
|
2
|
-
import { PasswordField } from '@nocobase/database';
|
|
3
|
-
import { branch } from '@nocobase/resourcer';
|
|
4
|
-
import crypto from 'crypto';
|
|
5
|
-
import { namespace } from '../';
|
|
6
|
-
|
|
7
|
-
export async function check(ctx: Context, next: Next) {
|
|
8
|
-
if (ctx.state.currentUser) {
|
|
9
|
-
const user = ctx.state.currentUser.toJSON();
|
|
10
|
-
ctx.body = user;
|
|
11
|
-
} else {
|
|
12
|
-
ctx.body = {};
|
|
13
|
-
}
|
|
14
|
-
await next();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function signin(ctx: Context, next: Next) {
|
|
18
|
-
const { authenticators, jwtService } = ctx.app.getPlugin('users');
|
|
19
|
-
const branches = {};
|
|
20
|
-
for (const [name, authenticator] of authenticators.getEntities()) {
|
|
21
|
-
branches[name] = authenticator;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return branch(branches, (context) => context.action.params.authenticator ?? 'password')(ctx, () => {
|
|
25
|
-
const user = ctx.state.currentUser.toJSON();
|
|
26
|
-
const token = jwtService.sign({ userId: user.id });
|
|
27
|
-
ctx.body = {
|
|
28
|
-
user,
|
|
29
|
-
token,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
return next();
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function signout(ctx: Context, next: Next) {
|
|
37
|
-
ctx.body = ctx.state.currentUser;
|
|
38
|
-
await next();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function signup(ctx: Context, next: Next) {
|
|
42
|
-
const User = ctx.db.getRepository('users');
|
|
43
|
-
const { values } = ctx.action.params;
|
|
44
|
-
const user = await User.create({ values });
|
|
45
|
-
ctx.body = user;
|
|
46
|
-
await next();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export async function lostpassword(ctx: Context, next: Next) {
|
|
50
|
-
const {
|
|
51
|
-
values: { email },
|
|
52
|
-
} = ctx.action.params;
|
|
53
|
-
if (!email) {
|
|
54
|
-
ctx.throw(400, { code: 'InvalidUserData', message: ctx.t('Please fill in your email address', { ns: namespace }) });
|
|
55
|
-
}
|
|
56
|
-
const User = ctx.db.getCollection('users');
|
|
57
|
-
const user = await User.model.findOne<any>({
|
|
58
|
-
where: {
|
|
59
|
-
email,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
if (!user) {
|
|
63
|
-
ctx.throw(404, {
|
|
64
|
-
code: 'InvalidUserData',
|
|
65
|
-
message: ctx.t('The email is incorrect, please re-enter', { ns: namespace }),
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
user.resetToken = crypto.randomBytes(20).toString('hex');
|
|
69
|
-
await user.save();
|
|
70
|
-
ctx.body = user;
|
|
71
|
-
await next();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export async function resetpassword(ctx: Context, next: Next) {
|
|
75
|
-
const {
|
|
76
|
-
values: { email, password, resetToken },
|
|
77
|
-
} = ctx.action.params;
|
|
78
|
-
const User = ctx.db.getCollection('users');
|
|
79
|
-
const user = await User.model.findOne<any>({
|
|
80
|
-
where: {
|
|
81
|
-
email,
|
|
82
|
-
resetToken,
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
if (!user) {
|
|
86
|
-
ctx.throw(404);
|
|
87
|
-
}
|
|
88
|
-
user.token = null;
|
|
89
|
-
user.resetToken = null;
|
|
90
|
-
user.password = password;
|
|
91
|
-
await user.save();
|
|
92
|
-
ctx.body = user;
|
|
93
|
-
await next();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export async function getUserByResetToken(ctx: Context, next: Next) {
|
|
97
|
-
const { token } = ctx.action.params;
|
|
98
|
-
const User = ctx.db.getCollection('users');
|
|
99
|
-
const user = await User.model.findOne({
|
|
100
|
-
where: {
|
|
101
|
-
resetToken: token,
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
if (!user) {
|
|
105
|
-
ctx.throw(401);
|
|
106
|
-
}
|
|
107
|
-
ctx.body = user;
|
|
108
|
-
await next();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export async function updateProfile(ctx: Context, next: Next) {
|
|
112
|
-
const { values } = ctx.action.params;
|
|
113
|
-
const { currentUser } = ctx.state;
|
|
114
|
-
if (!currentUser) {
|
|
115
|
-
ctx.throw(401);
|
|
116
|
-
}
|
|
117
|
-
const UserRepo = ctx.db.getRepository('users');
|
|
118
|
-
const result = await UserRepo.update({
|
|
119
|
-
filterByTk: currentUser.id,
|
|
120
|
-
values,
|
|
121
|
-
});
|
|
122
|
-
ctx.body = result;
|
|
123
|
-
await next();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export async function changePassword(ctx: Context, next: Next) {
|
|
127
|
-
const {
|
|
128
|
-
values: { oldPassword, newPassword },
|
|
129
|
-
} = ctx.action.params;
|
|
130
|
-
if (!ctx.state.currentUser) {
|
|
131
|
-
ctx.throw(401);
|
|
132
|
-
}
|
|
133
|
-
const User = ctx.db.getCollection('users');
|
|
134
|
-
const user = await User.model.findOne<any>({
|
|
135
|
-
where: {
|
|
136
|
-
email: ctx.state.currentUser.email,
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
const pwd = User.getField<PasswordField>('password');
|
|
140
|
-
const isValid = await pwd.verify(oldPassword, user.password);
|
|
141
|
-
if (!isValid) {
|
|
142
|
-
ctx.throw(401, ctx.t('The password is incorrect, please re-enter', { ns: namespace }));
|
|
143
|
-
}
|
|
144
|
-
user.password = newPassword;
|
|
145
|
-
user.save();
|
|
146
|
-
ctx.body = ctx.state.currentUser.toJSON();
|
|
147
|
-
await next();
|
|
148
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
import { requireModule } from '@nocobase/utils';
|
|
4
|
-
import { HandlerType } from '@nocobase/resourcer';
|
|
5
|
-
|
|
6
|
-
import Plugin from '..';
|
|
7
|
-
|
|
8
|
-
interface Authenticators {
|
|
9
|
-
[key: string]: HandlerType;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default function (plugin: Plugin, more: Authenticators = {}) {
|
|
13
|
-
const { authenticators } = plugin;
|
|
14
|
-
|
|
15
|
-
const natives = ['password'].reduce(
|
|
16
|
-
(result, key) =>
|
|
17
|
-
Object.assign(result, {
|
|
18
|
-
[key]: requireModule(path.isAbsolute(key) ? key : path.join(__dirname, key)) as HandlerType,
|
|
19
|
-
}),
|
|
20
|
-
{},
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
for (const [name, authenticator] of Object.entries(<Authenticators>{ ...more, ...natives })) {
|
|
24
|
-
authenticators.register(name, authenticator);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { PasswordField } from '@nocobase/database';
|
|
2
|
-
import { Context, Next } from '@nocobase/actions';
|
|
3
|
-
import { namespace } from '..';
|
|
4
|
-
|
|
5
|
-
export default async function (ctx: Context, next: Next) {
|
|
6
|
-
const { uniqueField = 'email', values } = ctx.action.params;
|
|
7
|
-
|
|
8
|
-
if (!values[uniqueField]) {
|
|
9
|
-
return ctx.throw(400, {
|
|
10
|
-
code: 'InvalidUserData',
|
|
11
|
-
message: ctx.t('Please fill in your email address', { ns: namespace }),
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
const User = ctx.db.getCollection('users');
|
|
15
|
-
const user = await User.model.findOne<any>({
|
|
16
|
-
where: {
|
|
17
|
-
[uniqueField]: values[uniqueField],
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
if (!user) {
|
|
22
|
-
return ctx.throw(404, ctx.t('The email is incorrect, please re-enter', { ns: namespace }));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const field = User.getField<PasswordField>('password');
|
|
26
|
-
const valid = await field.verify(values.password, user.password);
|
|
27
|
-
if (!valid) {
|
|
28
|
-
return ctx.throw(404, ctx.t('The password is incorrect, please re-enter', { ns: namespace }));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
ctx.state.currentUser = user;
|
|
32
|
-
|
|
33
|
-
return next();
|
|
34
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { CollectionOptions } from '@nocobase/database';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
namespace: 'users.users',
|
|
5
|
-
duplicator: {
|
|
6
|
-
dumpable: 'optional',
|
|
7
|
-
with: 'rolesUsers',
|
|
8
|
-
},
|
|
9
|
-
name: 'users',
|
|
10
|
-
title: '{{t("Users")}}',
|
|
11
|
-
sortable: 'sort',
|
|
12
|
-
model: 'UserModel',
|
|
13
|
-
createdBy: true,
|
|
14
|
-
updatedBy: true,
|
|
15
|
-
logging: true,
|
|
16
|
-
fields: [
|
|
17
|
-
{
|
|
18
|
-
name: 'id',
|
|
19
|
-
type: 'bigInt',
|
|
20
|
-
autoIncrement: true,
|
|
21
|
-
primaryKey: true,
|
|
22
|
-
allowNull: false,
|
|
23
|
-
uiSchema: { type: 'number', title: '{{t("ID")}}', 'x-component': 'InputNumber', 'x-read-pretty': true },
|
|
24
|
-
interface: 'id',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
interface: 'input',
|
|
28
|
-
type: 'string',
|
|
29
|
-
name: 'nickname',
|
|
30
|
-
uiSchema: {
|
|
31
|
-
type: 'string',
|
|
32
|
-
title: '{{t("Nickname")}}',
|
|
33
|
-
'x-component': 'Input',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
interface: 'email',
|
|
38
|
-
type: 'string',
|
|
39
|
-
name: 'email',
|
|
40
|
-
unique: true,
|
|
41
|
-
uiSchema: {
|
|
42
|
-
type: 'string',
|
|
43
|
-
title: '{{t("Email")}}',
|
|
44
|
-
'x-component': 'Input',
|
|
45
|
-
'x-validator': 'email',
|
|
46
|
-
required: true,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
interface: 'phone',
|
|
51
|
-
type: 'string',
|
|
52
|
-
name: 'phone',
|
|
53
|
-
unique: true,
|
|
54
|
-
uiSchema: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
title: '{{t("Phone")}}',
|
|
57
|
-
'x-component': 'Input',
|
|
58
|
-
'x-validator': 'phone',
|
|
59
|
-
required: true,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
interface: 'password',
|
|
64
|
-
type: 'password',
|
|
65
|
-
name: 'password',
|
|
66
|
-
hidden: true,
|
|
67
|
-
uiSchema: {
|
|
68
|
-
type: 'string',
|
|
69
|
-
title: '{{t("Password")}}',
|
|
70
|
-
'x-component': 'Password',
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
type: 'string',
|
|
75
|
-
name: 'appLang',
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
type: 'string',
|
|
79
|
-
name: 'resetToken',
|
|
80
|
-
unique: true,
|
|
81
|
-
hidden: true,
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
type: 'json',
|
|
85
|
-
name: 'systemSettings',
|
|
86
|
-
defaultValue: {},
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
} as CollectionOptions;
|
package/src/server/index.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import jwt from 'jsonwebtoken';
|
|
2
|
-
|
|
3
|
-
export interface JwtOptions {
|
|
4
|
-
secret: string;
|
|
5
|
-
expiresIn?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class JwtService {
|
|
9
|
-
constructor(protected options: JwtOptions) {}
|
|
10
|
-
|
|
11
|
-
private expiresIn() {
|
|
12
|
-
return this.options.expiresIn || process.env.JWT_EXPIRES_IN || '7d';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
private secret() {
|
|
16
|
-
return this.options.secret || process.env.APP_KEY;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
sign(payload: any) {
|
|
20
|
-
return jwt.sign(payload, this.secret(), { expiresIn: this.expiresIn() });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
decode(token: string): Promise<any> {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
jwt.verify(token, this.secret(), (err: any, decoded: any) => {
|
|
26
|
-
if (err) {
|
|
27
|
-
return reject(err);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
resolve(decoded);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
'The email is incorrect, please re-enter': 'The email is incorrect, please re-enter',
|
|
3
|
-
'Please fill in your email address': 'Please fill in your email address',
|
|
4
|
-
'The password is incorrect, please re-enter': 'The password is incorrect, please re-enter',
|
|
5
|
-
'Not a valid cellphone number, please re-enter': 'Not a valid cellphone number, please re-enter',
|
|
6
|
-
'The phone number has been registered, please login directly':
|
|
7
|
-
'The phone number has been registered, please login directly',
|
|
8
|
-
'The phone number is not registered, please register first':
|
|
9
|
-
'The phone number is not registered, please register first',
|
|
10
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
"The email is incorrect, please re-enter": "El correo electrónico es incorrecto, por favor vuelva a introducirlo",
|
|
3
|
-
"Please fill in your email address": "Por favor, introduzca su dirección de correo electrónico",
|
|
4
|
-
"The password is incorrect, please re-enter": "La contraseña es incorrecta, por favor, vuelva a introducirla",
|
|
5
|
-
"Not a valid cellphone number, please re-enter": "No es un número de móvil válido, por favor, vuelva a introducirlo",
|
|
6
|
-
"The phone number has been registered, please login directly": "El número de teléfono ha sido registrado, por favor, inicie sesión directamente",
|
|
7
|
-
"The phone number is not registered, please register first": "El número de teléfono no está registrado, por favor regístrese primero"
|
|
8
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
'The email is incorrect, please re-enter': "L'adresse e-mail est incorrecte, veuillez la saisir à nouveau",
|
|
3
|
-
'Please fill in your email address': 'Veuillez remplir votre adresse e-mail',
|
|
4
|
-
'The password is incorrect, please re-enter': 'Le mot de passe est incorrect, veuillez le saisir à nouveau',
|
|
5
|
-
'Not a valid cellphone number, please re-enter':
|
|
6
|
-
'Numéro de téléphone portable invalide, veuillez le saisir à nouveau',
|
|
7
|
-
'The phone number has been registered, please login directly':
|
|
8
|
-
'Le numéro de téléphone a été enregistré, veuillez vous connecter directement',
|
|
9
|
-
'The phone number is not registered, please register first':
|
|
10
|
-
"Le numéro de téléphone n'est pas enregistré, veuillez vous inscrire d'abord",
|
|
11
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
'The email is incorrect, please re-enter': 'O e-mail está incorreto, por favor, digite novamente',
|
|
3
|
-
'Please fill in your email address': 'Por favor, preencha o seu endereço de e-mail',
|
|
4
|
-
'The password is incorrect, please re-enter': 'A senha está incorreta, por favor, digite novamente',
|
|
5
|
-
'Not a valid cellphone number, please re-enter': 'Número de celular inválido, por favor, digite novamente',
|
|
6
|
-
'The phone number has been registered, please login directly':
|
|
7
|
-
'O número de celular já está registrado, por favor, faça login diretamente',
|
|
8
|
-
'The phone number is not registered, please register first':
|
|
9
|
-
'O número de celular não está registrado, por favor, registre-se primeiro',
|
|
10
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
'The email is incorrect, please re-enter': '邮箱有误,请重新输入',
|
|
3
|
-
'Please fill in your email address': '请填写邮箱',
|
|
4
|
-
'The password is incorrect, please re-enter': '密码有误,请重新输入',
|
|
5
|
-
'Not a valid cellphone number, please re-enter': '不是有效的手机号,请重新输入',
|
|
6
|
-
'The phone number has been registered, please login directly': '手机号已注册,请直接登录',
|
|
7
|
-
'The phone number is not registered, please register first': '手机号未注册,请先注册',
|
|
8
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// TODO(usage): 拦截用户的处理暂时作为一个中间件导出,应用需要的时候可以直接使用这个中间件
|
|
2
|
-
export function check(options) {
|
|
3
|
-
return async function check(ctx, next) {
|
|
4
|
-
const { currentUser } = ctx.state;
|
|
5
|
-
|
|
6
|
-
if (!currentUser) {
|
|
7
|
-
return ctx.throw(401, 'Unauthorized');
|
|
8
|
-
}
|
|
9
|
-
return next();
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Migration } from '@nocobase/server';
|
|
2
|
-
|
|
3
|
-
export default class AddUsersPhoneMigration extends Migration {
|
|
4
|
-
async up() {
|
|
5
|
-
const match = await this.app.version.satisfies('<=0.7.4-alpha.7');
|
|
6
|
-
if (!match) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const Field = this.context.db.getRepository('fields');
|
|
10
|
-
const existed = await Field.count({
|
|
11
|
-
filter: {
|
|
12
|
-
name: 'phone',
|
|
13
|
-
collectionName: 'users',
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
if (!existed) {
|
|
17
|
-
await Field.create({
|
|
18
|
-
values: {
|
|
19
|
-
name: 'phone',
|
|
20
|
-
collectionName: 'users',
|
|
21
|
-
type: 'string',
|
|
22
|
-
unique: true,
|
|
23
|
-
interface: 'phone',
|
|
24
|
-
uiSchema: {
|
|
25
|
-
type: 'string',
|
|
26
|
-
title: '{{t("Phone")}}',
|
|
27
|
-
'x-component': 'Input',
|
|
28
|
-
'x-validator': 'phone',
|
|
29
|
-
require: true,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
// NOTE: to trigger hook
|
|
33
|
-
context: {},
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async down() {}
|
|
39
|
-
}
|