Started work on flair
This commit is contained in:
parent
0fcd72b063
commit
4b4cb2ed3d
9 changed files with 149 additions and 10 deletions
|
|
@ -16,9 +16,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
|
||||
//NPM Imports
|
||||
const validator = require('validator');//No express here, so regular validator it is!
|
||||
const loggerUtils = require('../../utils/loggerUtils');
|
||||
const userModel = require('../../schemas/userSchema');
|
||||
|
||||
module.exports.defineListeners = function(io, socket){
|
||||
socket.on("chat-message", (data) => {
|
||||
socket.on("chatMessage", (data) => {
|
||||
//Trim and Sanatize for XSS
|
||||
const msg = validator.trim(validator.escape(data.msg));
|
||||
//make sure high is an int
|
||||
|
|
@ -34,6 +36,22 @@ module.exports.defineListeners = function(io, socket){
|
|||
return;
|
||||
}
|
||||
|
||||
io.in(socket.chan).emit("chat-message", {user: socket.user.user, msg, high});
|
||||
io.in(socket.chan).emit("chatMessage", {user: socket.user.user, flair: socket.user.flair, high, msg});
|
||||
});
|
||||
|
||||
socket.on("setFlair", async (data) => {
|
||||
const userDB = await userModel.findOne({user: socket.user.user});
|
||||
|
||||
if(userDB){
|
||||
try{
|
||||
//We can take this data raw since our schema checks it against existing flairs, and mongoose sanatizes queries
|
||||
userDB.flair = data.flair;
|
||||
await userDB.save();
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue