If you'd like to learn more about this change, visit the wiki's Player Names page.",
- "usernameTOSRequirements": "Usernames must conform to our Terms of Service and Community Guidelines. If you didn’t previously set a login name, your username was auto-generated.",
+ "usernameInfo": "Login names are now unique usernames that will be visible beside your display name and used for invitations, chat @mentions, and messaging.
If you'd like to learn more about this change, visit our wiki.",
+ "usernameTOSRequirements": "Usernames must conform to our Terms of Service and Community Guidelines. If you didn’t previously set a login name, your username was auto-generated.",
"usernameTaken": "Username already taken.",
"usernameWrongLength": "Username must be between 1 and 20 characters long.",
"displayNameWrongLength": "Display names must be between 1 and 30 characters long.",
"usernameBadCharacters": "Usernames can only contain letters a to z, numbers 0 to 9, hyphens, or underscores.",
- "nameBadWords": "Names cannot include any inappropriate words.",
- "confirmUsername": "Confirm Username",
- "usernameConfirmed": "Username Confirmed",
"passwordConfirmationMatch": "Password confirmation doesn't match password.",
"invalidLoginCredentials": "Incorrect username and/or email and/or password.",
"passwordResetPage": "Reset Password",
diff --git a/website/common/locales/en/messages.json b/website/common/locales/en/messages.json
index 2ddeef84fc..0a0e9b0c15 100644
--- a/website/common/locales/en/messages.json
+++ b/website/common/locales/en/messages.json
@@ -70,5 +70,7 @@
"beginningOfConversation": "This is the beginning of your conversation with <%= userName %>. Remember to be kind, respectful, and follow the Community Guidelines!",
- "messageDeletedUser": "Sorry, this user has deleted their account."
+ "messageDeletedUser": "Sorry, this user has deleted their account.",
+
+ "messageMissingDisplayName": "Missing display name."
}
diff --git a/website/common/locales/en/settings.json b/website/common/locales/en/settings.json
index 789294db6e..06ba78df64 100644
--- a/website/common/locales/en/settings.json
+++ b/website/common/locales/en/settings.json
@@ -199,7 +199,7 @@
"usernameIssueInvalidCharacters": "Usernames can only contain letters a to z, numbers 0 to 9, hyphens, or underscores.",
"currentUsername": "Current username:",
"displaynameIssueLength": "Display Names must be between 1 and 30 characters.",
- "displaynameIssueSlur": "Display Names may not contain inappropriate language",
+ "displaynameIssueSlur": "Display Names may not contain inappropriate language.",
"goToSettings": "Go to Settings",
"usernameVerifiedConfirmation": "Your username, <%= username %>, is confirmed!",
"usernameNotVerified": "Please confirm your username.",
diff --git a/website/server/controllers/api-v4/user.js b/website/server/controllers/api-v4/user.js
index 01cc9e7034..e0922db63f 100644
--- a/website/server/controllers/api-v4/user.js
+++ b/website/server/controllers/api-v4/user.js
@@ -1,5 +1,6 @@
import { authWithHeaders } from '../../middlewares/auth';
import * as userLib from '../../libs/user';
+import { verifyDisplayName } from '../../libs/user/validation';
const api = {};
@@ -206,4 +207,32 @@ api.userReset = {
},
};
+api.verifyDisplayName = {
+ method: 'POST',
+ url: '/user/auth/verify-display-name',
+ middlewares: [authWithHeaders({
+ optional: true,
+ })],
+ async handler (req, res) {
+ req.checkBody({
+ displayName: {
+ notEmpty: {errorMessage: res.t('messageMissingDisplayName')},
+ },
+ });
+
+ const validationErrors = req.validationErrors();
+ if (validationErrors) throw validationErrors;
+
+ const chosenDisplayName = req.body.displayName;
+
+ const issues = verifyDisplayName(chosenDisplayName, res);
+
+ if (issues.length > 0) {
+ res.respond(200, { isUsable: false, issues });
+ } else {
+ res.respond(200, { isUsable: true });
+ }
+ },
+};
+
module.exports = api;
diff --git a/website/server/libs/user/validation.js b/website/server/libs/user/validation.js
index a56446bc91..a064ef1a0a 100644
--- a/website/server/libs/user/validation.js
+++ b/website/server/libs/user/validation.js
@@ -26,6 +26,14 @@ function usernameContainsInvalidCharacters (username) {
return match !== null && match[0] !== null;
}
+export function verifyDisplayName (displayName, res) {
+ let issues = [];
+ if (displayName.length < 1 || displayName.length > 30) issues.push(res.t('displayNameWrongLength'));
+ if (nameContainsSlur(displayName)) issues.push(res.t('displaynameIssueSlur'));
+
+ return issues;
+}
+
export function verifyUsername (username, res) {
let issues = [];
if (username.length < 1 || username.length > 20) issues.push(res.t('usernameIssueLength'));