mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-16 11:37:37 +01:00
refactor: checkUsername function https://github.com/NodeBB/NodeBB/issues/10864
This commit is contained in:
@@ -84,17 +84,7 @@ authenticationController.register = async function (req, res) {
|
|||||||
await user.verifyInvitation(userData);
|
await user.verifyInvitation(userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
user.checkUsernameLength(userData.username);
|
||||||
!userData.username ||
|
|
||||||
userData.username.length < meta.config.minimumUsernameLength ||
|
|
||||||
slugify(userData.username).length < meta.config.minimumUsernameLength
|
|
||||||
) {
|
|
||||||
throw new Error('[[error:username-too-short]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userData.username.length > meta.config.maximumUsernameLength) {
|
|
||||||
throw new Error('[[error:username-too-long]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userData.password !== userData['password-confirm']) {
|
if (userData.password !== userData['password-confirm']) {
|
||||||
throw new Error('[[user:change-password-error-match]]');
|
throw new Error('[[user:change-password-error-match]]');
|
||||||
|
|||||||
@@ -170,13 +170,7 @@ module.exports = function (User) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.username.length < meta.config.minimumUsernameLength) {
|
User.checkUsernameLength(data.username);
|
||||||
throw new Error('[[error:username-too-short]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.username.length > meta.config.maximumUsernameLength) {
|
|
||||||
throw new Error('[[error:username-too-long]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
const userslug = slugify(data.username);
|
const userslug = slugify(data.username);
|
||||||
if (!utils.isUserNameValid(data.username) || !userslug) {
|
if (!utils.isUserNameValid(data.username) || !userslug) {
|
||||||
@@ -201,6 +195,20 @@ module.exports = function (User) {
|
|||||||
}
|
}
|
||||||
User.checkUsername = async username => isUsernameAvailable({ username });
|
User.checkUsername = async username => isUsernameAvailable({ username });
|
||||||
|
|
||||||
|
User.checkUsernameLength = function (username) {
|
||||||
|
if (
|
||||||
|
!username ||
|
||||||
|
username.length < meta.config.minimumUsernameLength ||
|
||||||
|
slugify(username).length < meta.config.minimumUsernameLength
|
||||||
|
) {
|
||||||
|
throw new Error('[[error:username-too-short]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (username.length > meta.config.maximumUsernameLength) {
|
||||||
|
throw new Error('[[error:username-too-long]]');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async function isAboutMeValid(callerUid, data) {
|
async function isAboutMeValid(callerUid, data) {
|
||||||
if (!data.aboutme) {
|
if (!data.aboutme) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user