Commit 9a12984b authored by Aron Carroll's avatar Aron Carroll Committed by Randall Leeds

Log the user out after disabling the account

parent 75a58033
class AccountManagement
@inject = ['$scope', '$rootScope', '$filter', 'flash', 'profile', 'util']
@inject = ['$scope', '$rootScope', '$filter', 'flash', 'profile', 'identity', 'util']
constructor: ($scope, $rootScope, $filter, flash, profile, util) ->
constructor: ($scope, $rootScope, $filter, flash, profile, identity, util) ->
persona_filter = $filter('persona')
onSuccess = (response) ->
......@@ -9,31 +9,35 @@ class AccountManagement
for type, msgs of response.flash
flash(type, msgs)
onDelete = (response) ->
identity.logout()
onSuccess(response)
onError = (form, data) ->
if 400 >= data.status < 500
util.applyValidationErrors(form, data.errors)
else
flash('error', 'Sorry, we were unable to perform your request')
$scope.deleteAccount = (form) ->
$scope.delete = (form) ->
# If the password is correct, the account is deleted.
# The extension is then removed from the page.
# Confirmation of success is given.
return unless form.$valid
username = persona_filter $scope.session.persona
username = persona_filter $scope.session.userid
packet =
username: username
pwd: form.deleteaccountpassword.$modelValue
promise = profile.disable_user(packet)
promise.$promise.then(onSuccess, angular.bind(null, onError, form))
promise.$promise.then(onDelete, angular.bind(null, onError, form))
$scope.submit = (form) ->
# In the frontend change_email and change_password are two different
# forms. However, in the backend it is just one: edit_profile
return unless form.$valid
username = persona_filter $scope.session.persona
username = persona_filter $scope.session.userid
if form.$name is 'editProfile'
packet =
username: username
......@@ -49,7 +53,7 @@ class AccountManagement
promise.$promise.then(onSuccess, angular.bind(null, onError, form))
$rootScope.$on 'nav:account', ->
$scope.sheet = true
$scope.$apply -> $scope.sheet = true
$rootScope.$on 'logout', ->
$scope.sheet = false
......
......@@ -7,6 +7,7 @@ describe 'h.controllers.AccountManagement', ->
fakeUtil = null
fakeFlash = null
fakeProfile = null
fakeIdentity = null
editProfilePromise = null
disableUserPromise = null
createController = null
......@@ -14,6 +15,8 @@ describe 'h.controllers.AccountManagement', ->
beforeEach module ($provide, $filterProvider) ->
fakeProfile = {}
fakeFlash = sandbox.spy()
fakeIdentity =
logout: sandbox.spy()
fakeUtil =
applyValidationErrors: sandbox.spy()
......@@ -22,6 +25,7 @@ describe 'h.controllers.AccountManagement', ->
$provide.value 'profile', fakeProfile
$provide.value 'flash', fakeFlash
$provide.value 'identity', fakeIdentity
$provide.value 'util', fakeUtil
return
......@@ -29,7 +33,7 @@ describe 'h.controllers.AccountManagement', ->
beforeEach inject ($rootScope, $q, $controller) ->
$scope = $rootScope.$new()
$scope.session = persona: 'egon@columbia.edu'
$scope.session = userid: 'egon@columbia.edu'
disableUserPromise = {then: sandbox.stub()}
editProfilePromise = {then: sandbox.stub()}
......@@ -127,7 +131,7 @@ describe 'h.controllers.AccountManagement', ->
assert.calledWith(fakeFlash, 'error')
describe '.deleteAccount', ->
describe '.delete', ->
it 'disables the user account', ->
fakeForm =
$name: 'deleteAccount'
......@@ -135,7 +139,7 @@ describe 'h.controllers.AccountManagement', ->
deleteaccountpassword: $modelValue: 'paranormal'
controller = createController()
$scope.deleteAccount(fakeForm)
$scope.delete(fakeForm)
assert.calledWith fakeProfile.disable_user,
username: 'STUBBED_PERSONA_FILTER'
......@@ -150,7 +154,7 @@ describe 'h.controllers.AccountManagement', ->
deleteaccountpassword: $modelValue: 'paranormal'
controller = createController()
$scope.deleteAccount(fakeForm)
$scope.delete(fakeForm)
# Resolve the request.
disableUserPromise.then.callArg 1,
......@@ -168,7 +172,7 @@ describe 'h.controllers.AccountManagement', ->
deleteaccountpassword: $modelValue: 'paranormal'
controller = createController()
$scope.deleteAccount(fakeForm)
$scope.delete(fakeForm)
# Resolve the request.
disableUserPromise.then.callArg 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment