X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Froutes%2Fusers.js;h=d637e13c1f2e186be5df4060578f1b990fb5b619;hp=7898ac8a8ee4b6a45c4ccfa84dd09af1d39164e6;hb=80b38d463c0d5dacac93bc2aeb666bbb19781e1e;hpb=0234201fb338fc239d6f613c677fa932c7c3697c diff --git a/server/routes/users.js b/server/routes/users.js index 7898ac8a..d637e13c 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -4,6 +4,22 @@ const sendEmail = require('../utils/mailer'); const genToken = require("../utils/tokenGenerator"); const access = require("../utils/access"); const params = require("../config/parameters"); +const sanitizeHtml = require('sanitize-html'); + +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 +32,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 +53,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 +75,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 +96,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)