Skip to content

Commit 2903428

Browse files
upliftjulianlam
authored andcommitted
Revert ban check removal
Add ability to bypass error thrown when user is banned
1 parent a93e247 commit 2903428

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

lib/controllers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Controllers.renderAdminPage = async (req, res) => {
99
res.render('admin/plugins/session-sharing', { groups: groupData });
1010
};
1111

12-
Controllers.retrieveUser = async (req, res) {
12+
Controllers.retrieveUser = async (req, res) => {
1313
const main = module.parent.exports;
1414
const remoteId = req.query.id;
1515

@@ -34,7 +34,7 @@ Controllers.retrieveUser = async (req, res) {
3434
}
3535
};
3636

37-
Controllers.process = async (req, res) {
37+
Controllers.process = async (req, res) => {
3838
const main = module.parent.exports;
3939

4040
if (!req.body || !req.body.token) {

library.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const plugin = {
4848
adminRevalidate: 'off',
4949
noRegistration: 'off',
5050
payloadParent: undefined,
51+
allowBannedUsers: false,
5152
},
5253
};
5354

@@ -72,7 +73,7 @@ plugin.init = async (params) => {
7273
await plugin.reloadSettings();
7374
};
7475

75-
plugin.appendConfig = async (config) {
76+
plugin.appendConfig = async (config) => {
7677
config.sessionSharing = {
7778
logoutRedirect: plugin.settings.logoutRedirect,
7879
loginOverride: plugin.settings.loginOverride,
@@ -99,7 +100,7 @@ SocketPlugins.sessionSharing.showUserIds = async (socket, data) => {
99100
return Promise.all(uids.map(async (uid) => db.getSortedSetRangeByScore(plugin.settings.name + ':uid', 0, -1, uid, uid)));
100101
};
101102

102-
SocketPlugins.sessionSharing.showUserIds = async (socket, data) {
103+
SocketPlugins.sessionSharing.showUserIds = async (socket, data) => {
103104
// Retrieve the hash and find matches
104105
const { uids } = data;
105106

@@ -110,7 +111,7 @@ SocketPlugins.sessionSharing.showUserIds = async (socket, data) {
110111
return Promise.all(uids.map(async (uid) => db.getSortedSetRangeByScore(plugin.settings.name + ':uid', 0, -1, uid, uid)));
111112
};
112113

113-
SocketPlugins.sessionSharing.findUserByRemoteId = async (socket, data) {
114+
SocketPlugins.sessionSharing.findUserByRemoteId = async (socket, data) => {
114115
if (!data.remoteId) {
115116
throw new Error('no-remote-id-supplied');
116117
}
@@ -143,7 +144,7 @@ plugin.process = async (token) => {
143144
return uid;
144145
};
145146

146-
plugin.normalizePayload = async (payload) {
147+
plugin.normalizePayload = async (payload) => {
147148
const userData = {};
148149

149150
if (plugin.settings.payloadParent) {
@@ -201,9 +202,17 @@ plugin.verifyUser = async (token, uid, isNewUser) => {
201202
isNewUser: isNewUser,
202203
token: token,
203204
});
205+
206+
// Check ban state of user
207+
const isBanned = await user.bans.isBanned(uid);
208+
209+
// Reject if banned and settings dont allow banned users to login
210+
if (isBanned && !plugin.settings.allowBannedUsers) {
211+
throw new Error('banned');
212+
}
204213
};
205214

206-
plugin.findOrCreateUser = async (userData) {
215+
plugin.findOrCreateUser = async (userData) => {
207216
const { id } = userData;
208217
let isNewUser = false;
209218
let userId = null;
@@ -255,7 +264,7 @@ plugin.findOrCreateUser = async (userData) {
255264
return [userId, isNewUser];
256265
};
257266

258-
plugin.updateUserProfile = async (uid, userData, isNewUser) {
267+
plugin.updateUserProfile = async (uid, userData, isNewUser) => {
259268
winston.debug('consider updateProfile?', isNewUser || plugin.settings.updateProfile === 'on');
260269
let userObj = {};
261270

@@ -293,7 +302,7 @@ plugin.updateUserProfile = async (uid, userData, isNewUser) {
293302
}
294303
};
295304

296-
plugin.updateUserGroups = async (uid, userData, isNewUser) {
305+
plugin.updateUserGroups = async (uid, userData, isNewUser) => {
297306
if (!userData.groups || !Array.isArray(userData.groups)) {
298307
return;
299308
}
@@ -343,7 +352,7 @@ async function executeJoinLeave(uid, join, leave) {
343352
]);
344353
}
345354

346-
plugin.createUser = async (userData) {
355+
plugin.createUser = async (userData) => {
347356
winston.verbose('[session-sharing] No user found, creating a new user for this login');
348357

349358
const uid = await user.create(_.pick(userData, profileFields));
@@ -485,7 +494,7 @@ plugin.addMiddleware = async function (req, res, next) {
485494
}
486495
};
487496

488-
plugin.cleanup = async (data) {
497+
plugin.cleanup = async (data) => {
489498
if (plugin.settings.cookieDomain) {
490499
winston.verbose('[session-sharing] Clearing cookie');
491500
data.res.clearCookie(plugin.settings.cookieName, {
@@ -530,7 +539,7 @@ plugin.generate = function (req, res) {
530539
res.sendStatus(200);
531540
};
532541

533-
plugin.addAdminNavigation = async (header) {
542+
plugin.addAdminNavigation = async (header) => {
534543
header.plugins.push({
535544
route: '/plugins/session-sharing',
536545
icon: 'fa-user-secret',

0 commit comments

Comments
 (0)