mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-10 01:40:22 +02:00
User create / registeration queue refactor (#13905)
* feat: add options parameter to User.create
add emailVerification: ('send'|'verify'|'skip') param to User.create to control email verification
add a new method User.createOrQueue(). store options that will be passed to User.create() when registration is accepted in _opts
If there is no password passed to registration queue(SSO register) don't store hashedPassword
removed the isFirstUser hack in user.create, when creating the admin user in install.js passing `emailVerification: 'verify'` to immediately verify the email, same with all the hacks in tests
auth: if an SSO plugin sends back an info object, redirect to root and display the message
* refactor: make function private
* refactor: destruct return
* test: fix flag test
* test: group tests
* feat: show ssoIcon if available in register queue
* add icon/title
This commit is contained in:
@@ -41,13 +41,11 @@ async function registerAndLoginUser(req, res, userData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const queue = await user.shouldQueueUser(req.ip);
|
||||
const result = await plugins.hooks.fire('filter:register.shouldQueue', { req, res, userData, queue });
|
||||
if (result.queue) {
|
||||
return await addToApprovalQueue(req, userData);
|
||||
const { queued, uid, message } = await user.createOrQueue(req, userData);
|
||||
if (queued) {
|
||||
return { message };
|
||||
}
|
||||
|
||||
const uid = await user.create(userData);
|
||||
if (res.locals.processLogin) {
|
||||
const hasLoginPrivilege = await privileges.global.can('local:login', uid);
|
||||
if (hasLoginPrivilege) {
|
||||
@@ -125,22 +123,6 @@ authenticationController.register = async function (req, res) {
|
||||
}
|
||||
};
|
||||
|
||||
async function addToApprovalQueue(req, userData) {
|
||||
userData.ip = req.ip;
|
||||
await user.addToApprovalQueue(userData);
|
||||
let message = '[[register:registration-added-to-queue]]';
|
||||
if (meta.config.showAverageApprovalTime) {
|
||||
const average_time = await db.getObjectField('registration:queue:approval:times', 'average');
|
||||
if (average_time > 0) {
|
||||
message += ` [[register:registration-queue-average-time, ${Math.floor(average_time / 60)}, ${Math.floor(average_time % 60)}]]`;
|
||||
}
|
||||
}
|
||||
if (meta.config.autoApproveTime > 0) {
|
||||
message += ` [[register:registration-queue-auto-approve-time, ${meta.config.autoApproveTime}]]`;
|
||||
}
|
||||
return { message: message };
|
||||
}
|
||||
|
||||
authenticationController.registerComplete = async function (req, res) {
|
||||
try {
|
||||
// For the interstitials that respond, execute the callback with the form body
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const nconf = require('nconf');
|
||||
const winston = require('winston');
|
||||
const validator = require('validator');
|
||||
const querystring = require('querystring');
|
||||
const _ = require('lodash');
|
||||
@@ -23,8 +24,10 @@ const url = nconf.get('url');
|
||||
helpers.noScriptErrors = async function (req, res, error, httpStatus) {
|
||||
if (req.body.noscript !== 'true') {
|
||||
if (typeof error === 'string') {
|
||||
winston.error(`${new Error(error).stack}`);
|
||||
return res.status(httpStatus).send(error);
|
||||
}
|
||||
winston.error(`${new Error(JSON.stringify(error)).stack}`);
|
||||
return res.status(httpStatus).json(error);
|
||||
}
|
||||
const middleware = require('../middleware');
|
||||
|
||||
Reference in New Issue
Block a user