@steedos/accounts 3.0.0-beta.36 → 3.0.0-beta.37
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/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/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
|
@@ -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
|
+
};
|
|
@@ -1,71 +1,81 @@
|
|
|
1
|
-
import * as express from
|
|
2
|
-
import { get, isEmpty, map } from
|
|
3
|
-
import { AccountsServer } from
|
|
4
|
-
import { db } from
|
|
5
|
-
import { getSteedosConfig } from
|
|
6
|
-
import { getSteedosService } from
|
|
1
|
+
import * as express from "express";
|
|
2
|
+
import { get, isEmpty, map } from "lodash";
|
|
3
|
+
import { AccountsServer } from "../server";
|
|
4
|
+
import { db } from "../db";
|
|
5
|
+
import { getSteedosConfig } from "@steedos/objectql";
|
|
6
|
+
import { getSteedosService } from "../core";
|
|
7
7
|
const config = getSteedosConfig();
|
|
8
8
|
|
|
9
|
-
export const userLoader =
|
|
10
|
-
|
|
11
|
-
res: express.Response,
|
|
12
|
-
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
get(req.headers, 'Authorization') ||
|
|
17
|
-
get(req.headers, 'authorization');
|
|
9
|
+
export const userLoader =
|
|
10
|
+
(accountsServer: AccountsServer) =>
|
|
11
|
+
async (req: express.Request, res: express.Response, next: any) => {
|
|
12
|
+
let authToken =
|
|
13
|
+
get(req.cookies, "X-Auth-Token") ||
|
|
14
|
+
get(req.headers, "Authorization") ||
|
|
15
|
+
get(req.headers, "authorization");
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
authToken =
|
|
18
|
+
authToken && authToken.replace("Bearer ", "").replace("BEARER ", "");
|
|
19
|
+
authToken =
|
|
20
|
+
authToken && authToken.split(",").length > 1
|
|
21
|
+
? authToken.split(",")[0]
|
|
22
|
+
: authToken;
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const userSpaces = await db.find("space_users", {
|
|
36
|
-
filters: [["user", "=", user.id],["user_accepted", "=", true]],
|
|
37
|
-
fields: ["space"],
|
|
24
|
+
if (!isEmpty(authToken)) {
|
|
25
|
+
try {
|
|
26
|
+
(req as any).authToken = authToken;
|
|
27
|
+
const user: any = await accountsServer.resumeSession(authToken);
|
|
28
|
+
user.id = user._id;
|
|
29
|
+
user.userId = user._id;
|
|
30
|
+
if (user.emails && user.emails.length > 0) {
|
|
31
|
+
user.email = user.emails[0].address;
|
|
32
|
+
}
|
|
33
|
+
(req as any).user = user;
|
|
34
|
+
(req as any).userId = user.id;
|
|
35
|
+
const spaces = [];
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
const userSpaces = await db.find("space_users", {
|
|
38
|
+
filters: [
|
|
39
|
+
["user", "=", user.id],
|
|
40
|
+
["user_accepted", "=", true],
|
|
41
|
+
],
|
|
42
|
+
fields: ["space"],
|
|
43
|
+
});
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
let steedosService = getSteedosService();
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if (userSpaces && userSpaces.length > 0) {
|
|
48
|
+
const dbSpaces = await db.find("spaces", {
|
|
49
|
+
filters: [["_id", "in", map(userSpaces, "space")]],
|
|
50
|
+
fields: ["_id", "name", "avatar", "avatar_dark"],
|
|
51
|
+
});
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
for (let space of dbSpaces) {
|
|
54
|
+
let logo_url = "";
|
|
55
|
+
if (steedosService) {
|
|
56
|
+
if (space.avatar_dark) {
|
|
57
|
+
logo_url =
|
|
58
|
+
steedosService +
|
|
59
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
60
|
+
space.avatar_dark;
|
|
61
|
+
} else if (space.avatar) {
|
|
62
|
+
logo_url =
|
|
63
|
+
steedosService +
|
|
64
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
65
|
+
space.avatar;
|
|
66
|
+
}
|
|
56
67
|
}
|
|
68
|
+
spaces.push({
|
|
69
|
+
_id: space._id,
|
|
70
|
+
name: space.name,
|
|
71
|
+
logo_url,
|
|
72
|
+
});
|
|
57
73
|
}
|
|
58
|
-
spaces.push({
|
|
59
|
-
_id: space._id,
|
|
60
|
-
name: space.name,
|
|
61
|
-
logo_url
|
|
62
|
-
})
|
|
63
74
|
}
|
|
75
|
+
(req as any).user.spaces = spaces;
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.log(e);
|
|
64
78
|
}
|
|
65
|
-
(req as any).user.spaces = spaces
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.log(e);
|
|
68
79
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
80
|
+
return next();
|
|
81
|
+
};
|