overleaf/services/web/public/coffee/main/account-settings.coffee

92 lines
2.6 KiB
CoffeeScript
Raw Normal View History

2014-07-08 07:02:26 -04:00
define [
"base"
], (App) ->
App.controller "AccountSettingsController", ["$scope", "$http", "$modal", "event_tracking", "UserAffiliationsDataService", ($scope, $http, $modal, event_tracking, UserAffiliationsDataService) ->
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
})
.then () ->
2014-07-08 07:02:26 -04:00
$scope.unsubscribing = false
$scope.subscribed = false
.catch () ->
2014-07-08 07:02:26 -04:00
$scope.unsubscribing = true
$scope.deleteAccount = () ->
modalInstance = $modal.open(
templateUrl: "deleteAccountModalTemplate"
controller: "DeleteAccountModalController"
resolve:
userDefaultEmail: () ->
UserAffiliationsDataService
.getUserDefaultEmail()
.then (defaultEmailDetails) ->
return defaultEmailDetails?.email or null
.catch () -> null
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", "userDefaultEmail",
($scope, $modalInstance, $timeout, $http, userDefaultEmail) ->
$scope.state =
isValid : false
deleteText: ""
password: ""
2014-07-08 07:02:26 -04:00
inflight: false
error: false
invalidCredentials: false
2014-07-08 07:02:26 -04:00
$modalInstance.opened.then () ->
$timeout () ->
$scope.$broadcast "open"
, 700
$scope.checkValidation = ->
$scope.state.isValid = userDefaultEmail? and $scope.state.deleteText == userDefaultEmail and $scope.state.password.length > 0
2014-07-08 07:02:26 -04:00
$scope.delete = () ->
$scope.state.inflight = true
$scope.state.error = false
$scope.state.invalidCredentials = false
2014-07-08 07:02:26 -04:00
$http({
method: "POST"
url: "/user/delete"
2014-07-08 07:02:26 -04:00
headers:
"X-CSRF-Token": window.csrfToken
"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
})
.then () ->
2014-07-08 07:02:26 -04:00
$modalInstance.close()
$scope.state.inflight = false
$scope.state.error = false
$scope.state.invalidCredentials = false
setTimeout(
() ->
window.location = "/login"
, 1000
)
.catch (response) ->
{ data, status } = response
$scope.state.inflight = false
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')
]