Skip to content

Node.js based forum software built for the modern web

email and username checks on profile update

barisusakliba4b98de0e3c
diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json
index 75d43fce3f..c9de71d2f4 100644
--- a/public/language/en_GB/error.json
+++ b/public/language/en_GB/error.json
@@ -23,6 +23,7 @@
"email-not-confirmed": "Your email is not confirmed, please click here to confirm your email.",
"username-too-short": "Username too short",
+ "username-too-long": "Username too long",
"user-banned": "User banned",
diff --git a/src/user/profile.js b/src/user/profile.js
index d76ac2bf65..e8d42da6d5 100644
--- a/src/user/profile.js
+++ b/src/user/profile.js
@@ -29,6 +29,10 @@ module.exports = function(User) {
return next();
}
+ if (!utils.isEmailValid(data.email)) {
+ return next(new Error('[[error:invalid-email]]'));
+ }
+
User.getUserField(uid, 'email', function(err, email) {
if(email === data.email) {
return next();
@@ -53,6 +57,14 @@ module.exports = function(User) {
return next();
}
+ if (data.username.length < meta.config.minimumUsernameLength) {
+ return next(new Error('[[error:username-too-short]]'));
+ }
+
+ if (data.username.length > meta.config.maximumUsernameLength) {
+ return next(new Error('[[error:username-too-long]]'));
+ }
+
if(!utils.isUserNameValid(data.username) || !userslug) {
return next(new Error('[[error:invalid-username]]'));
}