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