From 80ed58c85649a91a3d693f15ea801056e71d7ba9 Mon Sep 17 00:00:00 2001 From: hippoz Date: Thu, 21 Oct 2021 22:22:35 +0300 Subject: [PATCH] improvement!: remove "color" attribute for users and instead let the clients decide --- api/v1/users.js | 3 +-- models/User.js | 39 +++------------------------------------ resources/Docs/DOCS.md | 1 - 3 files changed, 4 insertions(+), 39 deletions(-) diff --git a/api/v1/users.js b/api/v1/users.js index f2647d9..4517e07 100755 --- a/api/v1/users.js +++ b/api/v1/users.js @@ -87,8 +87,7 @@ app.post("/account/create", [ username, email, password: hashedPassword, - role: startingRole, - color: User.generateColorFromUsername(username) + role: startingRole }); const userObject = await user.getPublicObject(); diff --git a/models/User.js b/models/User.js index c5b4723..a6e740e 100755 --- a/models/User.js +++ b/models/User.js @@ -7,7 +7,6 @@ const userSchema = new mongoose.Schema({ password: String, email: String, role: String, - color: String }); userSchema.method("getPublicObject", function() { @@ -15,7 +14,6 @@ userSchema.method("getPublicObject", function() { username: this.username, permissionLevel: config.roleMap[this.role], role: this.role, - color: this.color, _id: this._id }; }); @@ -27,51 +25,20 @@ userSchema.method("getFullObject", function() { email: this.email, permissionLevel: config.roleMap[this.role], role: this.role, - color: this.color, _id: this._id }; }); const User = mongoose.model("User", userSchema); -// NOTE(hippoz): These are all actually material design colors, taken from https://material-ui.com/customization/color/#playground -const colors = [ - "#f44336", - "#e91e63", - "#9c27b0", - "#673ab7", - "#3f51b5", - "#2196f3", - "#03a9f4", - "#00bcd4", - "#009688", - "#4caf50", - "#8bc34a", - "#cddc39", - "#ffeb3b", - "#ffc107", - "#ff9800", - "#ff5722" -]; - -User.generateColorFromUsername = function(username) { - let sum = 0; - for (let i in username) { - sum += username.charCodeAt(i); - } - const colorIndex = sum % colors.length; - return colors[colorIndex]; -}; - User.findByUsername = async function(username) { return await User.findOne({ username }).exec(); }; User.getPulicFields = function(isPartial=false) { - if (isPartial) { - return "username _id color"; - } - return "username role _id color"; + if (isPartial) + return "username _id"; + return "username role _id"; }; module.exports = User; \ No newline at end of file diff --git a/resources/Docs/DOCS.md b/resources/Docs/DOCS.md index b256e59..0dc42ba 100644 --- a/resources/Docs/DOCS.md +++ b/resources/Docs/DOCS.md @@ -223,7 +223,6 @@ Used mostly for messages. | - | - | | _id | The id of the user | | name | The name of the user | -| color | A hex color that represents that user | ## Message author object