From aa12ffb0a1371abdb757fca8b273ce35c1ffed40 Mon Sep 17 00:00:00 2001 From: hippoz Date: Thu, 3 Dec 2020 01:46:29 +0200 Subject: [PATCH] use colors throughout the whole app --- api/v1/gateway/index.js | 11 +++++++---- api/v1/users.js | 3 ++- app/app.html | 6 +++--- models/User.js | 7 +++++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/api/v1/gateway/index.js b/api/v1/gateway/index.js index e647e9d..275ff02 100644 --- a/api/v1/gateway/index.js +++ b/api/v1/gateway/index.js @@ -128,8 +128,9 @@ GatewayServer.prototype.eventSetup = function() { socket.user = { username: data.username, _id: user._id, - token, // Maybe not secure - permissionLevel + token, // NOTE(hippoz): Maybe not secure + permissionLevel, + color: user.color }; console.log(`[*] [gateway] [handshake] User ${data.username} has successfully authenticated`); return callback(); @@ -168,7 +169,8 @@ GatewayServer.prototype.eventSetup = function() { const messageObject = { author: { username: socket.user.username, - _id: socket.user._id + _id: socket.user._id, + color: socket.user.color }, category: { title: categoryTitle, @@ -236,7 +238,8 @@ GatewayServer.prototype._getSocketsInRoom = async function(room) { updatedClientList.push({ user: { username: client.user.username, - _id: client.user._id + _id: client.user._id, + color: client.user.color } }); }); diff --git a/api/v1/users.js b/api/v1/users.js index 26a1340..08f345c 100755 --- a/api/v1/users.js +++ b/api/v1/users.js @@ -53,7 +53,8 @@ app.post('/account/create', [ username, email, password: hashedPassword, - role: startingRole + role: startingRole, + color: User.generateColorFromUsername(username) }); const userObject = await user.getPublicObject(); diff --git a/app/app.html b/app/app.html index 23f9d77..8477e53 100755 --- a/app/app.html +++ b/app/app.html @@ -142,7 +142,7 @@

Browsing {{ selection.category.title }}

Browsing {{ selection.category.title }} with - {{ user.user.username }} + {{ user.user.username }}

arrow_back refresh @@ -152,7 +152,7 @@
- by {{ post.creator.username }} + by {{ post.creator.username }}
@@ -164,7 +164,7 @@
- {{ post.author.username }} + {{ post.author.username }} {{ post.content }} diff --git a/models/User.js b/models/User.js index fe86fef..3bfe5e8 100755 --- a/models/User.js +++ b/models/User.js @@ -6,7 +6,8 @@ const userSchema = new mongoose.Schema({ username: String, password: String, email: String, - role: String + role: String, + color: String }); userSchema.method('getPublicObject', function() { @@ -14,6 +15,7 @@ userSchema.method('getPublicObject', function() { username: this.username, permissionLevel: config.roleMap[this.role], role: this.role, + color: this.color, _id: this._id } }); @@ -25,6 +27,7 @@ userSchema.method('getFullObject', function() { email: this.email, permissionLevel: config.roleMap[this.role], role: this.role, + color: this.color, _id: this._id } }); @@ -65,7 +68,7 @@ User.findByUsername = async function(username) { }; User.getPulicFields = function() { - return 'username role _id'; + return 'username role _id color'; }; module.exports = User; \ No newline at end of file