#271 regenerate cards on username/avatar change

This commit is contained in:
Avris 2021-10-15 16:15:13 +02:00
parent d1d8879eed
commit a5fab6bb83
2 changed files with 10 additions and 1 deletions

View File

@ -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.

View File

@ -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)});
}));