X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Froutes%2Fusers.js;h=a3fa70619381f52b8b0d94ee9a7222370db54bf4;hb=ad65975c9150ac761c7e7c6696930d4e9e87396c;hp=7898ac8a8ee4b6a45c4ccfa84dd09af1d39164e6;hpb=0234201fb338fc239d6f613c677fa932c7c3697c;p=vchess.git diff --git a/server/routes/users.js b/server/routes/users.js index 7898ac8a..a3fa7061 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -4,6 +4,31 @@ const sendEmail = require('../utils/mailer'); const genToken = require("../utils/tokenGenerator"); const access = require("../utils/access"); const params = require("../config/parameters"); +const sanitizeHtml_pkg = require('sanitize-html'); + +const allowedTags = [ + 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', 'li', 'b', + 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div', 'table', + 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre' +]; +function sanitizeHtml(text) { + return sanitizeHtml_pkg(text, { allowedTags: allowedTags }); +} + +router.get("/userbio", access.ajax, (req,res) => { + const uid = req.query["id"]; + if (!!(uid.toString().match(/^[0-9]+$/))) { + UserModel.getBio(uid, (err, bio) => { + res.json(bio); + }); + } +}); + +router.put('/userbio', access.logged, access.ajax, (req,res) => { + const bio = sanitizeHtml(req.body.bio); + UserModel.setBio(req.userId, bio); + res.json({}); +}); router.post('/register', access.unlogged, access.ajax, (req,res) => { const name = req.body.name; @@ -16,7 +41,8 @@ router.post('/register', access.unlogged, access.ajax, (req,res) => { ? "User name or email already in use" : "User creation failed. Try again"; res.json({errmsg: msg}); - } else { + } + else { const user = { id: ret.id, name: name, @@ -36,16 +62,14 @@ router.get("/whoami", access.ajax, (req,res) => { name: user.name, email: user.email, id: user.id, - notify: user.notify, - newsRead: user.newsRead + notify: user.notify }); }; const anonymous = { name: "", email: "", id: 0, - notify: false, - newsRead: 0 + notify: false }; if (!req.cookies.token) callback(anonymous); else if (req.cookies.token.match(/^[a-z0-9]+$/)) { @@ -60,8 +84,8 @@ router.get("/users", access.ajax, (req,res) => { const ids = req.query["ids"]; // NOTE: slightly too permissive RegExp if (ids.match(/^([0-9]+,?)+$/)) { - UserModel.getByIds(ids, (err,users) => { - res.json({users:users}); + UserModel.getByIds(ids, (err, users) => { + res.json({ users:users }); }); } }); @@ -81,12 +105,6 @@ router.put('/update', access.logged, access.ajax, (req,res) => { } }); -// Special route to update newsRead timestamp: -router.put('/newsread', access.logged, access.ajax, (req,res) => { - UserModel.setNewsRead(req.userId); - res.json({}); -}); - // Authentication-related methods: // to: object user (to who we send an email)