mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-20 15:30:39 +01:00
* feat: #7514 Optional timer for registration queue * feat: show minutes in average time * fix: don't show total number of minutes * feat: implement requested changes * fix: just store minutes instead of milliseconds * feat: set default values
This commit is contained in:
@@ -136,6 +136,8 @@
|
||||
"necroThreshold": 7,
|
||||
"categoryWatchState": "watching",
|
||||
"submitPluginUsage": 1,
|
||||
"showAverageApprovalTime": true,
|
||||
"autoApproveTime": 0,
|
||||
"maxUserSessions": 10,
|
||||
"useCompression": 0
|
||||
}
|
||||
@@ -43,6 +43,9 @@
|
||||
"registration-type.disabled": "No registration",
|
||||
"registration-type.help": "Normal - Users can register from the /register page.<br/>\nInvite Only - Users can invite others from the <a href=\"%1/users\" target=\"_blank\">users</a> page.<br/>\nAdmin Invite Only - Only administrators can invite others from <a href=\"%1/users\" target=\"_blank\">users</a> and <a href=\"%1/admin/manage/users\">admin/manage/users</a> pages.<br/>\nNo registration - No user registration.<br/>",
|
||||
"registration-approval-type.help": "Normal - Users are registered immediately.<br/>\nAdmin Approval - User registrations are placed in an <a href=\"%1/admin/manage/registration\">approval queue</a> for administrators.<br/>\nAdmin Approval for IPs - Normal for new users, Admin Approval for IP addresses that already have an account.<br/>",
|
||||
"registration-queue-auto-approve-time": "Automatic Approval Time",
|
||||
"registration-queue-auto-approve-time-help": "Hours before user is approved automatically. 0 to disable.",
|
||||
"registration-queue-show-average-time": "Show users average time it takes to approve a new user",
|
||||
"registration.max-invites": "Maximum Invitations per User",
|
||||
"max-invites": "Maximum Invitations per User",
|
||||
"max-invites-help": "0 for no restriction. Admins get infinite invitations<br>Only applicable for \"Invite Only\"",
|
||||
|
||||
@@ -18,9 +18,10 @@
|
||||
"agree_to_terms_of_use": "I agree to the Terms of Use",
|
||||
"terms_of_use_error": "You must agree to the Terms of Use",
|
||||
"registration-added-to-queue": "Your registration has been added to the approval queue. You will receive an email when it is accepted by an administrator.",
|
||||
"registration-queue-average-time": "Our average time for approving memberships is %1 hours %2 minutes.",
|
||||
"registration-queue-auto-approve-time": "Your membership to this forum will be fully activated in up to %1 hours.",
|
||||
"interstitial.intro": "We require some additional information before we can create your account.",
|
||||
"interstitial.errors-found": "We could not complete your registration:",
|
||||
|
||||
"gdpr_agree_data": "I consent to the collection and processing of my personal information on this website.",
|
||||
"gdpr_agree_email": "I consent to receive digest and notification emails from this website.",
|
||||
"gdpr_consent_denied": "You must give consent to this site to collect/process your information, and to send you emails."
|
||||
|
||||
@@ -118,7 +118,15 @@ authenticationController.register = async function (req, res) {
|
||||
async function addToApprovalQueue(req, userData) {
|
||||
userData.ip = req.ip;
|
||||
await user.addToApprovalQueue(userData);
|
||||
return { message: '[[register:registration-added-to-queue]]' };
|
||||
let message = '[[register:registration-added-to-queue]]';
|
||||
if (meta.config.showAverageApprovalTime) {
|
||||
const average_time = await db.getObjectField('registration:queue:approval:times', 'average');
|
||||
message += ` [[register:registration-queue-average-time, ${Math.floor(average_time / 60)}, ${average_time % 60}]]`;
|
||||
}
|
||||
if (meta.config.autoApproveTime > 0) {
|
||||
message += ` [[register:registration-queue-auto-approve-time, ${meta.config.autoApproveTime}]]`;
|
||||
}
|
||||
return { message: message };
|
||||
}
|
||||
|
||||
authenticationController.registerComplete = function (req, res, next) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const validator = require('validator');
|
||||
const cronJob = require('cron').CronJob;
|
||||
|
||||
const db = require('../database');
|
||||
const meta = require('../meta');
|
||||
@@ -12,6 +13,10 @@ const slugify = require('../slugify');
|
||||
const plugins = require('../plugins');
|
||||
|
||||
module.exports = function (User) {
|
||||
new cronJob('0 * * * * *', function () {
|
||||
User.autoApprove();
|
||||
}, null, true);
|
||||
|
||||
User.addToApprovalQueue = async function (userData) {
|
||||
userData.username = userData.username.trim();
|
||||
userData.userslug = slugify(userData.username);
|
||||
@@ -59,7 +64,7 @@ module.exports = function (User) {
|
||||
if (!userData) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
const creation_time = await db.sortedSetScore('registration:queue', username);
|
||||
const uid = await User.create(userData);
|
||||
await User.setUserField(uid, 'password', userData.hashedPassword);
|
||||
await removeFromQueue(username);
|
||||
@@ -71,6 +76,9 @@ module.exports = function (User) {
|
||||
template: 'registration_accepted',
|
||||
uid: uid,
|
||||
});
|
||||
const total = await db.incrObjectField('registration:queue:approval:times', 'totalTime', Math.floor((Date.now() - creation_time) / 60000));
|
||||
const counter = await db.incrObjectField('registration:queue:approval:times', 'counter', 1);
|
||||
await db.setObjectField('registration:queue:approval:times', 'average', total / counter);
|
||||
return uid;
|
||||
};
|
||||
|
||||
@@ -140,4 +148,16 @@ module.exports = function (User) {
|
||||
const uids = await User.getUidsFromSet('ip:' + user.ip + ':uid', 0, -1);
|
||||
user.ipMatch = await User.getUsersFields(uids, ['uid', 'username', 'picture']);
|
||||
}
|
||||
|
||||
User.autoApprove = async function () {
|
||||
if (meta.config.autoApproveTime <= 0) {
|
||||
return;
|
||||
}
|
||||
const users = await db.getSortedSetRevRangeWithScores('registration:queue', 0, -1);
|
||||
const now = Date.now();
|
||||
for (const user of users.filter(user => now - user.score >= meta.config.autoApproveTime * 3600000)) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await User.acceptRegistration(user.value);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -186,6 +186,19 @@
|
||||
[[admin/settings/user:registration-approval-type.help, {config.relative_path}]]
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>[[admin/settings/user:registration-queue-auto-approve-time]]</label>
|
||||
<input type="number" class="form-control" data-field="autoApproveTime" placeholder="0">
|
||||
<p class="help-block">
|
||||
[[admin/settings/user:registration-queue-auto-approve-time-help]]
|
||||
</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
||||
<input class="mdl-switch__input" type="checkbox" data-field="showAverageApprovalTime">
|
||||
<span class="mdl-switch__label"><strong>[[admin/settings/user:registration-queue-show-average-time]]</strong></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>[[admin/settings/user:max-invites]]</label>
|
||||
<input type="number" class="form-control" data-field="maximumInvites" placeholder="0">
|
||||
|
||||
Reference in New Issue
Block a user