nodebb-plugin-session-sharing 4.7.2 → 5.1.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/lib/controllers.js +30 -28
- package/library.js +321 -378
- package/package.json +5 -3
- package/plugin.json +3 -2
- package/static/lib/admin.js +30 -28
- package/static/templates/admin/plugins/session-sharing.tpl +30 -1
- package/test/index.js +183 -0
package/lib/controllers.js
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const groups = require.main.require('./src/groups');
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const Controllers = {};
|
|
6
6
|
|
|
7
7
|
Controllers.renderAdminPage = async (req, res) => {
|
|
8
8
|
const groupData = await groups.getGroupsFromSet('groups:visible:createtime', 0, -1);
|
|
9
9
|
res.render('admin/plugins/session-sharing', { groups: groupData });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
Controllers.retrieveUser =
|
|
12
|
+
Controllers.retrieveUser = async (req, res) => {
|
|
13
13
|
const main = module.parent.exports;
|
|
14
14
|
const remoteId = req.query.id;
|
|
15
|
-
|
|
16
|
-
if (remoteId) {
|
|
17
|
-
|
|
18
|
-
if (err) {
|
|
19
|
-
res.status(500).json({
|
|
20
|
-
error: err.message,
|
|
21
|
-
});
|
|
22
|
-
} else if (userObj) {
|
|
23
|
-
res.status(200).json(userObj);
|
|
24
|
-
} else {
|
|
25
|
-
res.sendStatus(404);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
res.status(400).json({
|
|
15
|
+
|
|
16
|
+
if (!remoteId) {
|
|
17
|
+
return res.status(400).json({
|
|
30
18
|
error: 'no-id-supplied',
|
|
31
19
|
});
|
|
32
20
|
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const userObj = await main.getUser(remoteId);
|
|
24
|
+
|
|
25
|
+
if (!userObj) {
|
|
26
|
+
return res.sendStatus(404);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return res.status(200).json(userObj);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return res.status(500).json({
|
|
32
|
+
error: error.message,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
33
35
|
};
|
|
34
36
|
|
|
35
|
-
Controllers.process =
|
|
37
|
+
Controllers.process = async (req, res) => {
|
|
36
38
|
const main = module.parent.exports;
|
|
37
39
|
|
|
38
40
|
if (!req.body || !req.body.token) {
|
|
@@ -40,18 +42,18 @@ Controllers.process = function (req, res) {
|
|
|
40
42
|
error: 'no-token-provided',
|
|
41
43
|
});
|
|
42
44
|
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const uid = await main.process(req.body.token);
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
if (err) {
|
|
46
|
-
return res.status(500).json({
|
|
47
|
-
error: err.message,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
res.status(200).json({
|
|
49
|
+
return res.status(200).json({
|
|
52
50
|
uid,
|
|
53
51
|
});
|
|
54
|
-
})
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return res.status(500).json({
|
|
54
|
+
error: error.message,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
module.exports = Controllers;
|