mirror of https://gitgud.io/fatchan/jschan.git
Let users self-delete their account, provided they dont hold any staff positions closes #240
parent
8aea6e3abf
commit
18240670cf
5 changed files with 69 additions and 1 deletions
@ -0,0 +1,37 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const deleteAccount = require(__dirname+'/../../models/forms/deleteaccount.js') |
||||||
|
, dynamicResponse = require(__dirname+'/../../helpers/dynamic.js') |
||||||
|
|
||||||
|
module.exports = async (req, res, next) => { |
||||||
|
|
||||||
|
if (!req.body.confirm) { |
||||||
|
return dynamicResponse(req, res, 400, 'message', { |
||||||
|
'title': 'Bad request', |
||||||
|
'error': 'Missing confirmation', |
||||||
|
'redirect': '/account.html' |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
const { modBoards, ownedBoards } = res.locals.user; |
||||||
|
if (ownedBoards.length > 0 || modBoards.length > 0) { |
||||||
|
return dynamicResponse(req, res, 400, 'message', { |
||||||
|
'title': 'Bad request', |
||||||
|
'message': 'You cannot delete your account while you hold staff position on any board', |
||||||
|
'redirect': `/account.html` |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
await deleteAccount(res.locals.user.username); |
||||||
|
} catch (err) { |
||||||
|
return next(err); |
||||||
|
} |
||||||
|
|
||||||
|
return dynamicResponse(req, res, 200, 'message', { |
||||||
|
'title': 'Success', |
||||||
|
'message': 'Board deleted', |
||||||
|
'redirect': req.params.board ? '/' : '/globalmanage/settings.html' |
||||||
|
}); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const { Accounts } = require(__dirname+'/../../db/') |
||||||
|
|
||||||
|
module.exports = async (username) => { |
||||||
|
|
||||||
|
//this definitely needs to be its own file (v:
|
||||||
|
await Accounts.deleteOne(username); |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue