|
|
|
@ -22,7 +22,7 @@ const sockets = require('../socket.io');
|
|
|
|
|
const authenticationController = module.exports;
|
|
|
|
|
|
|
|
|
|
async function registerAndLoginUser(req, res, userData) {
|
|
|
|
|
const data = await plugins.fireHook('filter:register.interstitial', {
|
|
|
|
|
const data = await plugins.hooks.fire('filter:register.interstitial', {
|
|
|
|
|
userData: userData,
|
|
|
|
|
interstitials: [],
|
|
|
|
|
});
|
|
|
|
@ -45,7 +45,7 @@ async function registerAndLoginUser(req, res, userData) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const queue = await user.shouldQueueUser(req.ip);
|
|
|
|
|
const result = await plugins.fireHook('filter:register.shouldQueue', { req: req, res: res, userData: userData, queue: queue });
|
|
|
|
|
const result = await plugins.hooks.fire('filter:register.shouldQueue', { req: req, res: res, userData: userData, queue: queue });
|
|
|
|
|
if (result.queue) {
|
|
|
|
|
return await addToApprovalQueue(req, userData);
|
|
|
|
|
}
|
|
|
|
@ -61,7 +61,7 @@ async function registerAndLoginUser(req, res, userData) {
|
|
|
|
|
}
|
|
|
|
|
await user.deleteInvitationKey(userData.email);
|
|
|
|
|
const referrer = req.body.referrer || req.session.referrer || nconf.get('relative_path') + '/';
|
|
|
|
|
const complete = await plugins.fireHook('filter:register.complete', { uid: uid, referrer: referrer });
|
|
|
|
|
const complete = await plugins.hooks.fire('filter:register.complete', { uid: uid, referrer: referrer });
|
|
|
|
|
req.session.returnTo = complete.referrer;
|
|
|
|
|
return complete;
|
|
|
|
|
}
|
|
|
|
@ -105,7 +105,7 @@ authenticationController.register = async function (req, res) {
|
|
|
|
|
user.isPasswordValid(userData.password);
|
|
|
|
|
|
|
|
|
|
res.locals.processLogin = true; // set it to false in plugin if you wish to just register only
|
|
|
|
|
await plugins.fireHook('filter:register.check', { req: req, res: res, userData: userData });
|
|
|
|
|
await plugins.hooks.fire('filter:register.check', { req: req, res: res, userData: userData });
|
|
|
|
|
|
|
|
|
|
const data = await registerAndLoginUser(req, res, userData);
|
|
|
|
|
if (data) {
|
|
|
|
@ -137,7 +137,7 @@ async function addToApprovalQueue(req, userData) {
|
|
|
|
|
|
|
|
|
|
authenticationController.registerComplete = function (req, res, next) {
|
|
|
|
|
// For the interstitials that respond, execute the callback with the form body
|
|
|
|
|
plugins.fireHook('filter:register.interstitial', {
|
|
|
|
|
plugins.hooks.fire('filter:register.interstitial', {
|
|
|
|
|
userData: req.session.registration,
|
|
|
|
|
interstitials: [],
|
|
|
|
|
}, function (err, data) {
|
|
|
|
@ -217,14 +217,14 @@ authenticationController.registerAbort = function (req, res) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
authenticationController.login = function (req, res, next) {
|
|
|
|
|
if (plugins.hasListeners('action:auth.overrideLogin')) {
|
|
|
|
|
if (plugins.hooks.hasListeners('action:auth.overrideLogin')) {
|
|
|
|
|
return continueLogin(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var loginWith = meta.config.allowLoginWith || 'username-email';
|
|
|
|
|
req.body.username = req.body.username.trim();
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:login.check', { req: req, res: res, userData: req.body }, (err) => {
|
|
|
|
|
plugins.hooks.fire('filter:login.check', { req: req, res: res, userData: req.body }, (err) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return helpers.noScriptErrors(req, res, err.message, 403);
|
|
|
|
|
}
|
|
|
|
@ -355,7 +355,7 @@ authenticationController.onSuccessfulLogin = async function (req, uid) {
|
|
|
|
|
// Force session check for all connected socket.io clients with the same session id
|
|
|
|
|
sockets.in('sess_' + req.sessionID).emit('checkSession', uid);
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('action:user.loggedIn', { uid: uid, req: req });
|
|
|
|
|
plugins.hooks.fire('action:user.loggedIn', { uid: uid, req: req });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
req.session.destroy();
|
|
|
|
|
throw err;
|
|
|
|
@ -428,14 +428,14 @@ authenticationController.logout = async function (req, res, next) {
|
|
|
|
|
|
|
|
|
|
await user.setUserField(uid, 'lastonline', Date.now() - (meta.config.onlineCutoff * 60000));
|
|
|
|
|
await db.sortedSetAdd('users:online', Date.now() - (meta.config.onlineCutoff * 60000), uid);
|
|
|
|
|
await plugins.fireHook('static:user.loggedOut', { req: req, res: res, uid: uid, sessionID: sessionID });
|
|
|
|
|
await plugins.hooks.fire('static:user.loggedOut', { req: req, res: res, uid: uid, sessionID: sessionID });
|
|
|
|
|
|
|
|
|
|
// Force session check for all connected socket.io clients with the same session id
|
|
|
|
|
sockets.in('sess_' + sessionID).emit('checkSession', 0);
|
|
|
|
|
const payload = {
|
|
|
|
|
next: nconf.get('relative_path') + '/',
|
|
|
|
|
};
|
|
|
|
|
plugins.fireHook('filter:user.logout', payload);
|
|
|
|
|
plugins.hooks.fire('filter:user.logout', payload);
|
|
|
|
|
|
|
|
|
|
if (req.body.noscript === 'true') {
|
|
|
|
|
return res.redirect(payload.next);
|
|
|
|
|