From 0d792817fe0f6e67375ab18a65723decbc722fe5 Mon Sep 17 00:00:00 2001 From: Evert Date: Thu, 23 Nov 2017 18:26:53 +0200 Subject: [PATCH] Do some cleanups on the data --- server/api/external.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/api/external.js b/server/api/external.js index 4e41c87..5921124 100644 --- a/server/api/external.js +++ b/server/api/external.js @@ -62,6 +62,17 @@ const API = { uuid: uuidV1() }, data) + // Some data cleanups + + // Limit display name length + udataLimited.display_name = udataLimited.display_name.substring(0, 32) + + // Remove illegal characters from the username + udataLimited.username = udataLimited.username.replace(/\W+/gi, '') + + // Limit user name length + udataLimited.username = udataLimited.username.substring(0, 26) + // Check if the username is already taken if (await UAPI.User.get(udataLimited.username) != null) { udataLimited.username = udataLimited.username + UAPI.Hash(4) @@ -77,7 +88,7 @@ const API = { } } - // Create a new user based on the information we got from Facebook + // Create a new user based on the information we got from an external service let newUser = await models.User.query().insert(udataLimited) await API.Common.new(service, identifier, newUser) @@ -317,7 +328,7 @@ const API = { } let cleanedData = Object.assign(data, { - username: data.name.replace(/\W+/gi, ''), + username: data.name, display_name: data.name, email: data.email || '' }) @@ -404,7 +415,6 @@ const API = { // Create a new user let cleanedData = Object.assign(ddata, { - username: ddata.username.replace(/\W+/gi, '_'), display_name: ddata.username, email: ddata.email || '' })