[TASK] Implement DELETE /user.
This commit is contained in:
parent
699f061281
commit
7c19cf0470
|
@ -67,8 +67,39 @@ var constructor = function(db) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(req.method == "DELETE") {
|
if(req.method == "DELETE") {
|
||||||
//verify credentials before erasing all data
|
if(req.session.data.login == false) {
|
||||||
console.log(req);
|
res.send(200, JSON.stringify({
|
||||||
|
"success": false,
|
||||||
|
"err": "You are not logged in!"
|
||||||
|
}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//check if user document exists
|
||||||
|
db.get(req.session.data.user._id, function (err, doc) {
|
||||||
|
console.log(["delete/db.get", arguments]);
|
||||||
|
if(err && err.error == "not_found" && err.reason == "missing") {
|
||||||
|
res.send(200, JSON.stringify({
|
||||||
|
"success": false,
|
||||||
|
"err": "User document does not exist!"
|
||||||
|
}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
db.remove(doc._id, doc._rev, function(err, result) {
|
||||||
|
if(err) {
|
||||||
|
res.send(200, JSON.stringify({
|
||||||
|
"success": false,
|
||||||
|
"error": "Could not delete user document!"
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
//kill session data, too
|
||||||
|
delete req.session;
|
||||||
|
//TODO: delete profile document here, too!
|
||||||
|
res.send(200, JSON.stringify({
|
||||||
|
"success": true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue