From a5fab6bb83acd4588be6b9880c9d50cb94775b9e Mon Sep 17 00:00:00 2001 From: Avris Date: Fri, 15 Oct 2021 16:15:13 +0200 Subject: [PATCH] #271 regenerate cards on username/avatar change --- locale/en/translations.suml | 3 ++- server/routes/user.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/locale/en/translations.suml b/locale/en/translations.suml index b60582b6..b64de1d8 100644 --- a/locale/en/translations.suml +++ b/locale/en/translations.suml @@ -400,7 +400,8 @@ contact: authors: 'Authors of the website' technical: > Do you have a technical issue or question? Please include your username and as many details as possible - (what does the error message say? are you on your phone or a desktop? which browser do you use? what steps can we do to reproduce the issue? etc.) + (what does the error message say? are you on your phone or a desktop? which browser do you use? + what steps can we do to reproduce the issue? can you attach a screenshot or a screen recording? etc.) hate: > Wanna send us queerphobic hate mail? Just give it up, we're not discussing with trolls. diff --git a/server/routes/user.js b/server/routes/user.js index 4a83e918..856b9240 100644 --- a/server/routes/user.js +++ b/server/routes/user.js @@ -190,6 +190,10 @@ const reloadUser = async (req, res, next) => { next(); } +const resetCards = async (db, id) => { + await db.get(SQL`UPDATE profiles SET card = null, cardDark = null WHERE userId = ${id}`); +} + const router = Router(); router.use(handleErrorAsync(reloadUser)); @@ -298,6 +302,8 @@ router.post('/user/change-username', handleErrorAsync(async (req, res) => { await req.db.get(SQL`UPDATE users SET username = ${req.body.username}, usernameNorm = ${normalise(req.body.username)} WHERE id = ${req.user.id}`); + await resetCards(req.db, req.user.id); + return res.json({token: await issueAuthentication(req.db, req.user)}); })); @@ -464,6 +470,8 @@ router.post('/user/set-avatar', handleErrorAsync(async (req, res) => { WHERE id = ${req.user.id} `) + await resetCards(req.db, req.user.id); + return res.json({token: await issueAuthentication(req.db, req.user)}); }));