@steedos/accounts 3.0.0-beta.9 → 3.0.0-beta.90
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/core/index.js +66 -26
- package/lib/core/index.js.map +1 -1
- package/lib/rest-express/endpoints/logout.js +79 -72
- package/lib/rest-express/endpoints/logout.js.map +1 -1
- package/lib/rest-express/endpoints/password/change-password.js +94 -89
- package/lib/rest-express/endpoints/password/change-password.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/get-tenant.js +62 -39
- package/lib/rest-express/endpoints/steedos/get-tenant.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/settings.js +119 -88
- package/lib/rest-express/endpoints/steedos/settings.js.map +1 -1
- package/lib/rest-express/user-loader.js +82 -67
- package/lib/rest-express/user-loader.js.map +1 -1
- package/package.json +5 -5
- package/src/core/index.ts +201 -141
- package/src/rest-express/endpoints/logout.ts +74 -72
- package/src/rest-express/endpoints/password/change-password.ts +92 -81
- package/src/rest-express/endpoints/steedos/get-tenant.ts +56 -38
- package/src/rest-express/endpoints/steedos/settings.ts +117 -88
- package/src/rest-express/user-loader.ts +68 -58
|
@@ -3,101 +3,112 @@
|
|
|
3
3
|
* @Date: 2022-05-19 11:38:30
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
5
|
* @LastEditTime: 2023-09-18 17:58:22
|
|
6
|
-
* @Description:
|
|
6
|
+
* @Description:
|
|
7
7
|
*/
|
|
8
|
-
import * as express from
|
|
9
|
-
import { AccountsServer } from
|
|
10
|
-
import { sendError } from
|
|
11
|
-
import { getSteedosConfig, getObject } from
|
|
12
|
-
import { hashPassword } from
|
|
8
|
+
import * as express from "express";
|
|
9
|
+
import { AccountsServer } from "../../../server";
|
|
10
|
+
import { sendError } from "../../utils/send-error";
|
|
11
|
+
import { getSteedosConfig, getObject } from "@steedos/objectql";
|
|
12
|
+
import { hashPassword } from "../../../password/utils";
|
|
13
13
|
|
|
14
|
-
import * as requestIp from
|
|
15
|
-
import { getUserAgent } from
|
|
14
|
+
import * as requestIp from "request-ip";
|
|
15
|
+
import { getUserAgent } from "../../utils/get-user-agent";
|
|
16
16
|
import isMobile from "ismobilejs";
|
|
17
|
-
import { db } from
|
|
17
|
+
import { db } from "../../../db";
|
|
18
18
|
|
|
19
19
|
const config = getSteedosConfig();
|
|
20
20
|
declare var Creator;
|
|
21
21
|
|
|
22
|
-
export const changePassword =
|
|
23
|
-
|
|
24
|
-
res: express.Response
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const { oldPassword, newPassword } = req.body;
|
|
22
|
+
export const changePassword =
|
|
23
|
+
(accountsServer: AccountsServer) =>
|
|
24
|
+
async (req: express.Request, res: express.Response) => {
|
|
25
|
+
try {
|
|
26
|
+
if (!(req as any).userId) {
|
|
27
|
+
res.status(401);
|
|
28
|
+
res.json({ message: "Unauthorized" });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// oldPassword 、newPassword 已经是 sha256之后的
|
|
32
|
+
const { oldPassword, newPassword } = req.body;
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
// let passworPolicy = ((config as any).password || {}).policy
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const password: any = accountsServer.getServices().password;
|
|
36
|
+
// if(passworPolicy){
|
|
37
|
+
// if(!(new RegExp(passworPolicy)).test(newPassword || '')){
|
|
38
|
+
// sendError(res, new Error((config as any).password.policyError));
|
|
39
|
+
// return;
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const password: any = accountsServer.getServices().password;
|
|
44
|
+
|
|
45
|
+
await password.changePassword(
|
|
46
|
+
(req as any).userId,
|
|
47
|
+
oldPassword,
|
|
48
|
+
newPassword,
|
|
49
|
+
);
|
|
50
|
+
password.db.collection.updateOne(
|
|
51
|
+
{ _id: (req as any).userId },
|
|
52
|
+
{ $set: { password_expired: false } },
|
|
53
|
+
);
|
|
54
|
+
try {
|
|
55
|
+
await db.updateMany(
|
|
56
|
+
"space_users",
|
|
57
|
+
[["user", "=", (req as any).userId]],
|
|
58
|
+
{ password_expired: false },
|
|
59
|
+
);
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const userAgent = getUserAgent(req);
|
|
62
|
+
const ip = requestIp.getClientIp(req);
|
|
63
|
+
let is_phone = false;
|
|
64
|
+
let is_tablet = false;
|
|
65
|
+
if (userAgent) {
|
|
66
|
+
try {
|
|
67
|
+
const { phone, tablet } = isMobile(userAgent);
|
|
68
|
+
is_phone = phone;
|
|
69
|
+
is_tablet = tablet;
|
|
70
|
+
} catch (Exception) {
|
|
71
|
+
console.log(`Exception`, Exception);
|
|
72
|
+
}
|
|
64
73
|
}
|
|
65
|
-
}
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
const userSpaces = await db.find("space_users", {
|
|
76
|
+
filters: [
|
|
77
|
+
["user", "=", (req as any).userId],
|
|
78
|
+
["user_accepted", "=", true],
|
|
79
|
+
],
|
|
80
|
+
fields: ["space"],
|
|
81
|
+
});
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
if (userSpaces && userSpaces.length > 0) {
|
|
84
|
+
for (let userSpace of userSpaces) {
|
|
85
|
+
const userId = (req as any).userId;
|
|
86
|
+
await getObject("operation_logs").insert({
|
|
87
|
+
name: "修改密码",
|
|
88
|
+
type: "change_password",
|
|
89
|
+
remote_user: userId,
|
|
90
|
+
remote_addr: ip,
|
|
91
|
+
http_user_agent: userAgent,
|
|
92
|
+
is_mobile: is_phone,
|
|
93
|
+
is_tablet,
|
|
94
|
+
object: "users",
|
|
95
|
+
status: "success",
|
|
96
|
+
create: new Date(),
|
|
97
|
+
create_by: userId,
|
|
98
|
+
modified_by: userId,
|
|
99
|
+
space: userSpace.space,
|
|
100
|
+
related_to: {
|
|
101
|
+
o: "users",
|
|
102
|
+
ids: [userId],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
94
106
|
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.log("error", error);
|
|
95
109
|
}
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
res.json({ userId: (req as any).userId, password_expired: false });
|
|
111
|
+
} catch (err) {
|
|
112
|
+
sendError(res, err);
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
} catch (err) {
|
|
101
|
-
sendError(res, err);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
114
|
+
};
|
|
@@ -1,44 +1,62 @@
|
|
|
1
|
-
import * as express from
|
|
2
|
-
import { AccountsServer } from
|
|
3
|
-
import { sendError } from
|
|
4
|
-
import { getSteedosConfig } from
|
|
5
|
-
import { db } from
|
|
6
|
-
import {getSteedosService } from
|
|
1
|
+
import * as express from "express";
|
|
2
|
+
import { AccountsServer } from "../../../server";
|
|
3
|
+
import { sendError } from "../../utils/send-error";
|
|
4
|
+
import { getSteedosConfig } from "@steedos/objectql";
|
|
5
|
+
import { db } from "../../../db";
|
|
6
|
+
import { getSteedosService } from "../../../core";
|
|
7
7
|
|
|
8
|
-
export const getTenant =
|
|
9
|
-
|
|
10
|
-
res: express.Response
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export const getTenant =
|
|
9
|
+
(accountsServer: AccountsServer) =>
|
|
10
|
+
async (req: express.Request, res: express.Response) => {
|
|
11
|
+
try {
|
|
12
|
+
const spaceId = req.params.id;
|
|
13
|
+
if (!spaceId) throw new Error("accounts.tenant_id_required");
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const spaceDoc = await db.findOne("spaces", spaceId, {
|
|
16
|
+
fields: [
|
|
17
|
+
"name",
|
|
18
|
+
"avatar",
|
|
19
|
+
"avatar_dark",
|
|
20
|
+
"background",
|
|
21
|
+
"enable_register",
|
|
22
|
+
"account_logo",
|
|
23
|
+
],
|
|
23
24
|
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let steedosService = getSteedosService();
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
spaceDoc.
|
|
26
|
+
if (!spaceDoc) {
|
|
27
|
+
return res.send({
|
|
28
|
+
exists: false,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let steedosService = getSteedosService();
|
|
33
|
+
|
|
34
|
+
if (steedosService) {
|
|
35
|
+
if (spaceDoc.account_logo) {
|
|
36
|
+
spaceDoc.logo_url =
|
|
37
|
+
steedosService +
|
|
38
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
39
|
+
spaceDoc.account_logo;
|
|
40
|
+
} else if (spaceDoc.avatar_dark) {
|
|
41
|
+
spaceDoc.logo_url =
|
|
42
|
+
steedosService +
|
|
43
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
44
|
+
spaceDoc.avatar_dark;
|
|
45
|
+
} else if (spaceDoc.avatar) {
|
|
46
|
+
spaceDoc.logo_url =
|
|
47
|
+
steedosService +
|
|
48
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
49
|
+
spaceDoc.avatar;
|
|
50
|
+
}
|
|
51
|
+
if (spaceDoc.background) {
|
|
52
|
+
spaceDoc.background_url =
|
|
53
|
+
steedosService +
|
|
54
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
55
|
+
spaceDoc.background;
|
|
56
|
+
}
|
|
38
57
|
}
|
|
58
|
+
res.json(spaceDoc);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
sendError(res, err);
|
|
39
61
|
}
|
|
40
|
-
|
|
41
|
-
} catch (err) {
|
|
42
|
-
sendError(res, err);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
62
|
+
};
|
|
@@ -3,110 +3,139 @@
|
|
|
3
3
|
* @Date: 2022-03-28 09:35:34
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
5
|
* @LastEditTime: 2025-02-21 14:33:10
|
|
6
|
-
* @Description:
|
|
6
|
+
* @Description:
|
|
7
7
|
*/
|
|
8
|
-
import * as express from
|
|
9
|
-
import * as _ from
|
|
10
|
-
import { AccountsServer } from
|
|
11
|
-
import { getSteedosConfig, getSteedosSchema } from
|
|
12
|
-
import { db } from
|
|
13
|
-
import { canSendEmail, canSendSMS, getSteedosService } from
|
|
14
|
-
const validator = require(
|
|
15
|
-
const util = require(
|
|
16
|
-
const clone = require(
|
|
8
|
+
import * as express from "express";
|
|
9
|
+
import * as _ from "lodash";
|
|
10
|
+
import { AccountsServer } from "../../../server";
|
|
11
|
+
import { getSteedosConfig, getSteedosSchema } from "@steedos/objectql";
|
|
12
|
+
import { db } from "../../../db";
|
|
13
|
+
import { canSendEmail, canSendSMS, getSteedosService } from "../../../core";
|
|
14
|
+
const validator = require("validator");
|
|
15
|
+
const util = require("@steedos/utils");
|
|
16
|
+
const clone = require("clone");
|
|
17
17
|
|
|
18
18
|
const config = getSteedosConfig();
|
|
19
19
|
|
|
20
|
-
export const getSettings =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
20
|
+
export const getSettings =
|
|
21
|
+
(accountsServer: AccountsServer) =>
|
|
22
|
+
async (req: express.Request, res: express.Response) => {
|
|
23
|
+
let tenant: any = {
|
|
24
|
+
name: "Steedos",
|
|
25
|
+
logo_url: undefined,
|
|
26
|
+
background_url: undefined,
|
|
27
|
+
enable_create_tenant: true,
|
|
28
|
+
enable_register: true,
|
|
29
|
+
enable_forget_password: true,
|
|
30
|
+
enable_password_login: true,
|
|
31
|
+
enable_mobile_code_login: false,
|
|
32
|
+
enable_email_code_login: false,
|
|
33
|
+
enable_bind_mobile: false,
|
|
34
|
+
enable_bind_email: false,
|
|
35
|
+
enable_saas: validator.toBoolean(
|
|
36
|
+
process.env.STEEDOS_TENANT_ENABLE_SAAS || "false",
|
|
37
|
+
true,
|
|
38
|
+
),
|
|
39
|
+
enable_open_geetest: validator.toBoolean(
|
|
40
|
+
process.env.STEEDOS_CAPTCHA_GEETEST_ENABLED || "false",
|
|
41
|
+
),
|
|
42
|
+
page_login: process.env.STEEDOS_TENANT_PAGE_LOGIN,
|
|
43
|
+
page_logout: process.env.STEEDOS_TENANT_PAGE_LOGOUT,
|
|
44
|
+
};
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
if (config.tenant) {
|
|
47
|
+
_.assignIn(tenant, config.tenant);
|
|
48
|
+
}
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
if (!tenant._id) {
|
|
51
|
+
tenant._id = process.env.STEEDOS_TENANT_ID;
|
|
52
|
+
}
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
const platform = (global as any).Steedos.settings.public?.platform || {};
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
if (tenant._id) {
|
|
57
|
+
let spaceDoc = await db.findOne("spaces", tenant._id, {
|
|
58
|
+
fields: [
|
|
59
|
+
"name",
|
|
60
|
+
"avatar",
|
|
61
|
+
"avatar_dark",
|
|
62
|
+
"background",
|
|
63
|
+
"enable_register",
|
|
64
|
+
"account_logo",
|
|
65
|
+
"favicon",
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
let steedosService = getSteedosService();
|
|
69
|
+
if (steedosService && spaceDoc) {
|
|
57
70
|
_.assignIn(tenant, spaceDoc);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
if (spaceDoc.account_logo) {
|
|
72
|
+
tenant.logo_url =
|
|
73
|
+
steedosService +
|
|
74
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
75
|
+
spaceDoc.account_logo;
|
|
76
|
+
} else if (spaceDoc.avatar_dark) {
|
|
77
|
+
tenant.logo_url =
|
|
78
|
+
steedosService +
|
|
79
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
80
|
+
spaceDoc.avatar_dark;
|
|
81
|
+
} else if (spaceDoc.avatar) {
|
|
82
|
+
tenant.logo_url =
|
|
83
|
+
steedosService +
|
|
84
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
85
|
+
spaceDoc.avatar;
|
|
86
|
+
}
|
|
87
|
+
if (spaceDoc.background) {
|
|
88
|
+
tenant.background_url =
|
|
89
|
+
steedosService +
|
|
90
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
91
|
+
spaceDoc.background;
|
|
92
|
+
}
|
|
93
|
+
if (platform?.is_oem && spaceDoc.favicon) {
|
|
94
|
+
tenant.favicon_url =
|
|
95
|
+
steedosService +
|
|
96
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
97
|
+
spaceDoc.favicon;
|
|
98
|
+
}
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let already_mail_service = canSendEmail();
|
|
75
|
-
let already_sms_service = true || canSendSMS();
|
|
76
101
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const serverInitInfo = {
|
|
80
|
-
|
|
81
|
-
};
|
|
102
|
+
let already_mail_service = canSendEmail();
|
|
103
|
+
let already_sms_service = true || canSendSMS();
|
|
82
104
|
|
|
83
|
-
|
|
105
|
+
//allowInit
|
|
106
|
+
const broker = getSteedosSchema().broker;
|
|
107
|
+
const serverInitInfo = {};
|
|
84
108
|
|
|
85
|
-
|
|
86
|
-
delete _tenant['accessTokenExpiresIn']
|
|
87
|
-
delete _tenant['refreshTokenExpiresIn']
|
|
109
|
+
const _tenant = clone(tenant);
|
|
88
110
|
|
|
89
|
-
|
|
90
|
-
delete _tenant
|
|
91
|
-
|
|
111
|
+
delete _tenant["tokenSecret"];
|
|
112
|
+
delete _tenant["accessTokenExpiresIn"];
|
|
113
|
+
delete _tenant["refreshTokenExpiresIn"];
|
|
92
114
|
|
|
115
|
+
if (tenant.enable_saas) {
|
|
116
|
+
delete _tenant._id;
|
|
117
|
+
}
|
|
93
118
|
|
|
94
|
-
|
|
119
|
+
let settings = {};
|
|
95
120
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
121
|
+
if (tenant._id) {
|
|
122
|
+
settings = await util.getSettings(tenant._id, true);
|
|
123
|
+
}
|
|
99
124
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
res.json({
|
|
126
|
+
tenant: _tenant,
|
|
127
|
+
password: config.password
|
|
128
|
+
? config.password
|
|
129
|
+
: config.public?.password
|
|
130
|
+
? config.public?.password
|
|
131
|
+
: {},
|
|
132
|
+
root_url: process.env.ROOT_URL,
|
|
133
|
+
already_mail_service: already_mail_service,
|
|
134
|
+
already_sms_service: already_sms_service,
|
|
135
|
+
serverInitInfo: serverInitInfo,
|
|
136
|
+
redirect_url_whitelist: process.env.REDIRECT_URL_WHITELIST,
|
|
137
|
+
platform: platform,
|
|
138
|
+
public: (global as any).Steedos.settings.public || {},
|
|
139
|
+
settings: settings,
|
|
140
|
+
});
|
|
141
|
+
};
|