Skip to content

Commit

Permalink
Revert ban check removal
Browse files Browse the repository at this point in the history
Add ability to bypass error thrown when user is banned
  • Loading branch information
uplift authored and julianlam committed Aug 6, 2021
1 parent a93e247 commit 2903428
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Controllers.renderAdminPage = async (req, res) => {
res.render('admin/plugins/session-sharing', { groups: groupData });
};

Controllers.retrieveUser = async (req, res) {
Controllers.retrieveUser = async (req, res) => {
const main = module.parent.exports;
const remoteId = req.query.id;

Expand All @@ -34,7 +34,7 @@ Controllers.retrieveUser = async (req, res) {
}
};

Controllers.process = async (req, res) {
Controllers.process = async (req, res) => {
const main = module.parent.exports;

if (!req.body || !req.body.token) {
Expand Down
29 changes: 19 additions & 10 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const plugin = {
adminRevalidate: 'off',
noRegistration: 'off',
payloadParent: undefined,
allowBannedUsers: false,
},
};

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

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

SocketPlugins.sessionSharing.showUserIds = async (socket, data) {
SocketPlugins.sessionSharing.showUserIds = async (socket, data) => {
// Retrieve the hash and find matches
const { uids } = data;

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

SocketPlugins.sessionSharing.findUserByRemoteId = async (socket, data) {
SocketPlugins.sessionSharing.findUserByRemoteId = async (socket, data) => {
if (!data.remoteId) {
throw new Error('no-remote-id-supplied');
}
Expand Down Expand Up @@ -143,7 +144,7 @@ plugin.process = async (token) => {
return uid;
};

plugin.normalizePayload = async (payload) {
plugin.normalizePayload = async (payload) => {
const userData = {};

if (plugin.settings.payloadParent) {
Expand Down Expand Up @@ -201,9 +202,17 @@ plugin.verifyUser = async (token, uid, isNewUser) => {
isNewUser: isNewUser,
token: token,
});

// Check ban state of user
const isBanned = await user.bans.isBanned(uid);

// Reject if banned and settings dont allow banned users to login
if (isBanned && !plugin.settings.allowBannedUsers) {
throw new Error('banned');
}
};

plugin.findOrCreateUser = async (userData) {
plugin.findOrCreateUser = async (userData) => {
const { id } = userData;
let isNewUser = false;
let userId = null;
Expand Down Expand Up @@ -255,7 +264,7 @@ plugin.findOrCreateUser = async (userData) {
return [userId, isNewUser];
};

plugin.updateUserProfile = async (uid, userData, isNewUser) {
plugin.updateUserProfile = async (uid, userData, isNewUser) => {
winston.debug('consider updateProfile?', isNewUser || plugin.settings.updateProfile === 'on');
let userObj = {};

Expand Down Expand Up @@ -293,7 +302,7 @@ plugin.updateUserProfile = async (uid, userData, isNewUser) {
}
};

plugin.updateUserGroups = async (uid, userData, isNewUser) {
plugin.updateUserGroups = async (uid, userData, isNewUser) => {
if (!userData.groups || !Array.isArray(userData.groups)) {
return;
}
Expand Down Expand Up @@ -343,7 +352,7 @@ async function executeJoinLeave(uid, join, leave) {
]);
}

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

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

plugin.cleanup = async (data) {
plugin.cleanup = async (data) => {
if (plugin.settings.cookieDomain) {
winston.verbose('[session-sharing] Clearing cookie');
data.res.clearCookie(plugin.settings.cookieName, {
Expand Down Expand Up @@ -530,7 +539,7 @@ plugin.generate = function (req, res) {
res.sendStatus(200);
};

plugin.addAdminNavigation = async (header) {
plugin.addAdminNavigation = async (header) => {
header.plugins.push({
route: '/plugins/session-sharing',
icon: 'fa-user-secret',
Expand Down

0 comments on commit 2903428

Please sign in to comment.