diff --git a/app/core/auth.coffee b/app/core/auth.coffee index 06390af82..75e321de0 100644 --- a/app/core/auth.coffee +++ b/app/core/auth.coffee @@ -50,7 +50,12 @@ module.exports.loginUser = (userObject, failure=genericFailure, nextURL=null) -> module.exports.logoutUser = -> FB?.logout?() - res = $.post('/auth/logout', {}, -> window.location.reload()) + callback = -> + if (window.location.href.indexOf("/account/settings") > -1) + window.location = '/' + else + window.location.reload() + res = $.post('/auth/logout', {}, callback) res.fail(genericFailure) onSetVolume = (e) -> diff --git a/app/schemas/models/user.coffee b/app/schemas/models/user.coffee index 01b0765d9..f1c745f2c 100644 --- a/app/schemas/models/user.coffee +++ b/app/schemas/models/user.coffee @@ -276,6 +276,7 @@ _.extend UserSchema.properties, earned: c.RewardSchema 'earned by achievements' purchased: c.RewardSchema 'purchased with gems or money' + deleted: {type: 'boolean'} spent: {type: 'number'} stripeCustomerID: { type: 'string' } # TODO: Migrate away from this property diff --git a/app/views/account/AccountSettingsView.coffee b/app/views/account/AccountSettingsView.coffee index ddeded5b3..327eb7c99 100644 --- a/app/views/account/AccountSettingsView.coffee +++ b/app/views/account/AccountSettingsView.coffee @@ -100,7 +100,6 @@ 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 = '../' , 500 error: (jqXHR, status, error) -> console.error jqXHR diff --git a/server/users/user_handler.coffee b/server/users/user_handler.coffee index db5381d01..b8cc6b6fa 100644 --- a/server/users/user_handler.coffee +++ b/server/users/user_handler.coffee @@ -220,16 +220,20 @@ UserHandler = class UserHandler extends Handler delete: (req, res, userID) -> # Instead of just deleting the User object, we should remove all the properties except for _id + # And add a `deleted: true` property @getDocumentForIdOrSlug userID, (err, user) => # Check first return @sendDatabaseError res, err if err return @sendNotFoundError res unless user return @sendForbiddenError res unless @hasAccessToDocument(req, user) obj = user.toObject() for prop, val of obj - if !(prop is '_id') - user.set(prop, undefined) - user.set('anonymous', true) + user.set(prop, undefined) unless prop is '_id' + user.set('deleted', true) + + # Hack to get saving of Users to work. Probably should replace these props with strings + # so that validation doesn't get hung up on Date objects in the documents. delete obj.dateCreated + user.save (err) => return @sendDatabaseError(res, err) if err @sendNoContent res