Don't delete the User object, just remove all the properties except for _id

This commit is contained in:
laituan245 2015-02-24 22:36:12 +09:00
parent d325623699
commit eb53381083
2 changed files with 9 additions and 2 deletions

View file

@ -100,7 +100,7 @@ module.exports = class AccountSettingsView extends CocoView
Backbone.Mediator.publish("auth:logging-out", {})
window.tracker?.trackEvent 'Log Out', category:'Homepage', ['Google Analytics'] if @id is 'home-view'
logoutUser($('#login-email').val())
window.location = '../';
window.location = '../'
, 500
error: (jqXHR, status, error) ->
console.error jqXHR

View file

@ -219,11 +219,18 @@ UserHandler = class UserHandler extends Handler
return true
delete: (req, res, userID) ->
# Instead of just deleting the User object, we should remove all the properties except for _id
@getDocumentForIdOrSlug userID, (err, user) => # Check first
return @sendDatabaseError res, err if err
return @sendNotFoundError res unless user
return @sendForbiddenError res unless @hasAccessToDocument(req, user)
user.remove (err, user) =>
obj = user.toObject()
for prop, val of obj
if !(prop is '_id')
user.set(prop, undefined)
user.set('anonymous', true)
delete obj.dateCreated
user.save (err) =>
return @sendDatabaseError(res, err) if err
@sendNoContent res