2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
2018-03-15 10:22:59 -04:00
|
|
|
App.controller "AccountSettingsController", ["$scope", "$http", "$modal", "event_tracking", ($scope, $http, $modal, event_tracking) ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.subscribed = true
|
|
|
|
|
|
|
|
$scope.unsubscribe = () ->
|
|
|
|
$scope.unsubscribing = true
|
|
|
|
$http({
|
|
|
|
method: "DELETE"
|
|
|
|
url: "/user/newsletter/unsubscribe"
|
|
|
|
headers:
|
|
|
|
"X-CSRF-Token": window.csrfToken
|
|
|
|
})
|
2017-06-20 06:49:55 -04:00
|
|
|
.then () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.unsubscribing = false
|
|
|
|
$scope.subscribed = false
|
2017-06-20 06:49:55 -04:00
|
|
|
.catch () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.unsubscribing = true
|
|
|
|
|
|
|
|
$scope.deleteAccount = () ->
|
|
|
|
modalInstance = $modal.open(
|
|
|
|
templateUrl: "deleteAccountModalTemplate"
|
2016-10-04 10:57:08 -04:00
|
|
|
controller: "DeleteAccountModalController",
|
|
|
|
scope: $scope
|
2014-07-08 07:02:26 -04:00
|
|
|
)
|
2018-03-15 10:22:59 -04:00
|
|
|
|
|
|
|
$scope.upgradeIntegration = (service) ->
|
|
|
|
event_tracking.send 'subscription-funnel', 'settings-page', service
|
2014-07-08 07:02:26 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "DeleteAccountModalController", [
|
|
|
|
"$scope", "$modalInstance", "$timeout", "$http",
|
|
|
|
($scope, $modalInstance, $timeout, $http) ->
|
2016-10-25 09:33:47 -04:00
|
|
|
$scope.state =
|
2014-07-28 11:52:23 -04:00
|
|
|
isValid : false
|
|
|
|
deleteText: ""
|
2016-10-25 11:23:50 -04:00
|
|
|
password: ""
|
2014-07-08 07:02:26 -04:00
|
|
|
inflight: false
|
2016-10-25 09:33:47 -04:00
|
|
|
error: false
|
2016-10-25 11:23:50 -04:00
|
|
|
invalidCredentials: false
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$modalInstance.opened.then () ->
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 700
|
|
|
|
|
2014-07-28 11:52:23 -04:00
|
|
|
$scope.checkValidation = ->
|
2016-10-25 11:23:50 -04:00
|
|
|
$scope.state.isValid = $scope.state.deleteText == $scope.email and $scope.state.password.length > 0
|
2014-07-28 11:52:23 -04:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.delete = () ->
|
|
|
|
$scope.state.inflight = true
|
2016-10-25 09:33:47 -04:00
|
|
|
$scope.state.error = false
|
2016-10-25 11:23:50 -04:00
|
|
|
$scope.state.invalidCredentials = false
|
2014-07-08 07:02:26 -04:00
|
|
|
$http({
|
2016-10-25 09:33:47 -04:00
|
|
|
method: "POST"
|
|
|
|
url: "/user/delete"
|
2014-07-08 07:02:26 -04:00
|
|
|
headers:
|
|
|
|
"X-CSRF-Token": window.csrfToken
|
2016-10-25 09:33:47 -04:00
|
|
|
"Content-Type": 'application/json'
|
|
|
|
data:
|
|
|
|
password: $scope.state.password
|
2016-11-04 11:44:12 -04:00
|
|
|
disableAutoLoginRedirect: true # we want to handle errors ourselves
|
2014-07-08 07:02:26 -04:00
|
|
|
})
|
2017-06-20 06:49:55 -04:00
|
|
|
.then () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$modalInstance.close()
|
2016-10-25 09:33:47 -04:00
|
|
|
$scope.state.inflight = false
|
|
|
|
$scope.state.error = false
|
2016-10-25 11:23:50 -04:00
|
|
|
$scope.state.invalidCredentials = false
|
2016-11-28 07:01:32 -05:00
|
|
|
setTimeout(
|
|
|
|
() ->
|
|
|
|
window.location = "/login"
|
|
|
|
, 1000
|
|
|
|
)
|
2017-06-20 11:04:06 -04:00
|
|
|
.catch (response) ->
|
|
|
|
{ data, status } = response
|
2016-10-25 09:33:47 -04:00
|
|
|
$scope.state.inflight = false
|
2016-10-25 11:23:50 -04:00
|
|
|
if status == 403
|
|
|
|
$scope.state.invalidCredentials = true
|
|
|
|
else
|
|
|
|
$scope.state.error = true
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
2016-10-04 10:57:08 -04:00
|
|
|
]
|