Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/controllers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ const sockets = require('../socket.io');
const authenticationController = module.exports;

async function registerAndLoginUser(req, res, userData) {
console.log("In registerAndLoginUser \n");
if (!userData.hasOwnProperty('email')) {
userData.updateEmail = true;
}

const data = await plugins.hooks.fire('filter:register.interstitial', {
req,
userData,
Expand Down Expand Up @@ -74,10 +75,13 @@ async function registerAndLoginUser(req, res, userData) {
authenticationController.register = async function (req, res) {
const registrationType = meta.config.registrationType || 'normal';


if (registrationType === 'disabled') {
return res.sendStatus(403);
}

console.log("In register function, user req \n");
// console.log(req)
const userData = req.body;
try {
if (userData.token || registrationType === 'invite-only' || registrationType === 'admin-invite-only') {
Expand All @@ -89,6 +93,7 @@ authenticationController.register = async function (req, res) {
userData.username.length < meta.config.minimumUsernameLength ||
slugify(userData.username).length < meta.config.minimumUsernameLength
) {
console.log("username too short");
throw new Error('[[error:username-too-short]]');
}

Expand Down Expand Up @@ -122,11 +127,13 @@ authenticationController.register = async function (req, res) {
res.json(data);
}
} catch (err) {
console.log(err.message);
helpers.noScriptErrors(req, res, err.message, 400);
}
};

async function addToApprovalQueue(req, userData) {
console.log("addToApprovalQueue\n")
userData.ip = req.ip;
await user.addToApprovalQueue(userData);
let message = '[[register:registration-added-to-queue]]';
Expand All @@ -143,6 +150,7 @@ async function addToApprovalQueue(req, userData) {
}

authenticationController.registerComplete = async function (req, res) {
console.log("registerComplete\n")
try {
// For the interstitials that respond, execute the callback with the form body
const data = await plugins.hooks.fire('filter:register.interstitial', {
Expand Down Expand Up @@ -238,6 +246,7 @@ authenticationController.registerAbort = function (req, res) {
};

authenticationController.login = async (req, res, next) => {
console.log("login\n");
let { strategy } = await plugins.hooks.fire('filter:login.override', { req, strategy: 'local' });
if (!passport._strategy(strategy)) {
winston.error(`[auth/override] Requested login strategy "${strategy}" not found, reverting back to local login strategy.`);
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/write/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ Utilities.ping.post = (req, res) => {

Utilities.login = (req, res) => {
res.locals.redirectAfterLogin = async (req, res) => {
console.log("redirect after logging in r \n");
const userData = (await user.getUsers([req.uid], req.uid)).pop();
helpers.formatApiResponse(200, res, userData);
};
res.locals.noScriptErrors = (req, res, err, statusCode) => {
console.log("noScriptErrors \n");
helpers.formatApiResponse(statusCode, res, new Error(err));
};

Expand Down