Skip to content

Node.js based forum software built for the modern web

feat: return registration pending message

Barış Soner Uşaklı31f883f948d1
diff --git a/public/language/en-GB/error.json b/public/language/en-GB/error.json
index 15ec33c044..ff4edb1119 100644
--- a/public/language/en-GB/error.json
+++ b/public/language/en-GB/error.json
@@ -28,6 +28,7 @@
"invalid-user-data": "Invalid User Data",
"invalid-password": "Invalid Password",
"invalid-login-credentials": "Invalid login credentials",
+ "registration-pending": "Registration is still pending",
"invalid-username-or-password": "Please specify both a username and password",
"username-required": "Please enter your username",
"password-required": "Please enter your password",
diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js
index 51e6da939b..acba79b404 100644
--- a/src/controllers/authentication.js
+++ b/src/controllers/authentication.js
@@ -434,6 +434,10 @@ authenticationController.localLogin = async function (req, username, password, n
}
const uid = await user.getUidByUserslug(userslug);
+ if (!parseInt(uid, 10) && await user.isRegistrationPending(username, password, req.ip)) {
+ throw new Error('[[error:registration-pending]]');
+ }
+
try {
const [userData, isAdminOrGlobalMod, canLoginIfBanned] = await Promise.all([
user.getUserFields(uid, ['uid', 'passwordExpiry']),
diff --git a/src/user/approval.js b/src/user/approval.js
index 61d18fcb4b..518924e37b 100644
--- a/src/user/approval.js
+++ b/src/user/approval.js
@@ -10,6 +10,7 @@ const groups = require('../groups');
const utils = require('../utils');
const slugify = require('../slugify');
const plugins = require('../plugins');
+const Password = require('../password');
const tx = require('../translator');
module.exports = function (User) {
@@ -216,4 +217,20 @@ module.exports = function (User) {
}
}
};
+
+ User.isRegistrationPending = async (username, password, ip) => {
+ const hashedPassword = await db.getObjectField(`registration:queue:name:${username.trim()}`, 'hashedPassword');
+ if (!hashedPassword) {
+ return false;
+ }
+ password = password || '';
+ try {
+ User.isPasswordValid(password, 0);
+ } catch (e) {
+ return false;
+ }
+
+ await User.auth.logIPAttempt(ip);
+ return await Password.compare(password, hashedPassword, 1);
+ };
};
diff --git a/src/user/auth.js b/src/user/auth.js
index d3f0c59fcf..9152b2a6e2 100644
--- a/src/user/auth.js
+++ b/src/user/auth.js
@@ -10,7 +10,7 @@ const utils = require('../utils');
module.exports = function (User) {
User.auth = {};
- User.auth.logAttempt = async function (uid, ip) {
+ User.auth.logIPAttempt = async function (ip) {
const onHourMs = 60 * 60 * 1000;
const ipLocked = await db.exists(`lockout:ip:${ip}`);
if (ipLocked) {
@@ -30,6 +30,10 @@ module.exports = function (User) {
});
throw new Error('[[error:ip-locked]]');
}
+ };
+
+ User.auth.logAttempt = async function (uid, ip) {
+ await User.auth.logIPAttempt(ip);
// Use a fixed dummy key for non‑existent users to prevent username enumeration (CWE-203)
const targetKey = parseInt(uid, 10) > 0 ? uid : 'dummy';