Skip to content

Commit 4229084

Browse files
committed
Add delete function for authenticated users
Allow users to delete themselbes. This is require to be GDPR compliant. See: https://gdpr-info.eu/art-17-gdpr/ Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
1 parent 408ab7a commit 4229084

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

lib/web/userRouter.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const Router = require('express').Router
44

55
const response = require('../response')
6+
const config = require('../config')
67
const models = require('../models')
78
const logger = require('../logger')
89
const {generateAvatar} = require('../letter-avatars')
@@ -36,6 +37,29 @@ UserRouter.get('/me', function (req, res) {
3637
}
3738
})
3839

40+
// delete the currently authenticated user
41+
UserRouter.get('/me/delete', function (req, res) {
42+
if (req.isAuthenticated()) {
43+
models.User.findOne({
44+
where: {
45+
id: req.user.id
46+
}
47+
}).then(function (user) {
48+
if (!user) { return response.errorNotFound(res) }
49+
user.destroy().then(function () {
50+
res.redirect(config.serverURL + '/')
51+
})
52+
}).catch(function (err) {
53+
logger.error('delete user failed: ' + err)
54+
return response.errorInternalError(res)
55+
})
56+
} else {
57+
res.send({
58+
status: 'forbidden'
59+
})
60+
}
61+
})
62+
3963
UserRouter.get('/user/:username/avatar.svg', function (req, res, next) {
4064
res.setHeader('Content-Type', 'image/svg+xml')
4165
res.setHeader('Cache-Control', 'public, max-age=86400')

0 commit comments

Comments
 (0)