@steedos/accounts 3.0.0-beta.9 → 3.0.0-beta.92
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
|
@@ -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
|
+
};
|