Browse Source

Fixed issue with case-sensitive profile pages.

KrisVos130 8 years ago
parent
commit
ab4cdaba26
1 changed files with 4 additions and 6 deletions
  1. 4 6
      backend/logic/actions/users.js

+ 4 - 6
backend/logic/actions/users.js

@@ -208,19 +208,18 @@ module.exports = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	findByUsername: (session, username, cb) => {
-		db.models.user.find({ username }, (err, account) => {
+		db.models.user.findOne({ username: new RegExp(`^${username}$`, 'i') }, (err, account) => {
 			if (err) {
 				logger.error("FIND_BY_USERNAME", "Find by username failed for username '" + username + "'. Mongo error.");
-				throw err;
+				return cb({ 'status': 'error', message: err.message });
 			}
-			else if (account.length == 0) {
+			else if (!account) {
 				logger.error("FIND_BY_USERNAME", "User not found for username '" + username + "'.");
 				return cb({
 					status: 'error',
-					message: 'Username cannot be found'
+					message: 'User cannot be found'
 				});
 			} else {
-				account = account[0];
 				logger.success("FIND_BY_USERNAME", "User found for username '" + username + "'.");
 				return cb({
 					status: 'success',
@@ -229,7 +228,6 @@ module.exports = {
 						username: account.username,
 						role: account.role,
 						email: account.email.address,
-						password: '',
 						createdAt: account.createdAt,
 						statistics: account.statistics,
 						liked: account.liked,