2020-04-06 07:45:56 -04:00
|
|
|
define(['../base'], function(App) {
|
2019-07-16 05:13:18 -04:00
|
|
|
App.controller('AccountSettingsController', function(
|
|
|
|
$scope,
|
|
|
|
$http,
|
|
|
|
$modal,
|
2019-08-28 08:59:41 -04:00
|
|
|
// eslint-disable-next-line camelcase
|
2019-10-23 08:22:50 -04:00
|
|
|
eventTracking,
|
2019-07-31 04:23:30 -04:00
|
|
|
UserAffiliationsDataService
|
2019-07-16 05:13:18 -04:00
|
|
|
) {
|
|
|
|
$scope.subscribed = true
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.unsubscribe = function() {
|
|
|
|
$scope.unsubscribing = true
|
|
|
|
return $http({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: '/user/newsletter/unsubscribe',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
$scope.unsubscribing = false
|
2019-08-28 08:59:41 -04:00
|
|
|
$scope.subscribed = false
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2019-07-16 05:13:18 -04:00
|
|
|
.catch(() => ($scope.unsubscribing = true))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.deleteAccount = function() {
|
2019-08-28 08:59:41 -04:00
|
|
|
$modal.open({
|
2019-07-16 05:13:18 -04:00
|
|
|
templateUrl: 'deleteAccountModalTemplate',
|
|
|
|
controller: 'DeleteAccountModalController',
|
|
|
|
resolve: {
|
|
|
|
userDefaultEmail() {
|
|
|
|
return UserAffiliationsDataService.getUserDefaultEmail()
|
|
|
|
.then(
|
|
|
|
defaultEmailDetails =>
|
|
|
|
(defaultEmailDetails != null
|
|
|
|
? defaultEmailDetails.email
|
|
|
|
: undefined) || null
|
|
|
|
)
|
|
|
|
.catch(() => null)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2019-08-28 08:59:41 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-08-28 08:59:41 -04:00
|
|
|
$scope.upgradeIntegration = service =>
|
2019-10-23 08:22:50 -04:00
|
|
|
eventTracking.send('subscription-funnel', 'settings-page', service)
|
2019-07-16 05:13:18 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-08-28 08:59:41 -04:00
|
|
|
App.controller('DeleteAccountModalController', function(
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope,
|
|
|
|
$modalInstance,
|
|
|
|
$timeout,
|
|
|
|
$http,
|
|
|
|
userDefaultEmail
|
|
|
|
) {
|
|
|
|
$scope.state = {
|
|
|
|
isValid: false,
|
|
|
|
deleteText: '',
|
|
|
|
password: '',
|
|
|
|
confirmV1Purge: false,
|
|
|
|
confirmSharelatexDelete: false,
|
|
|
|
inflight: false,
|
|
|
|
error: null
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.userDefaultEmail = userDefaultEmail
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$modalInstance.opened.then(() =>
|
|
|
|
$timeout(() => $scope.$broadcast('open'), 700)
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.checkValidation = () =>
|
|
|
|
($scope.state.isValid =
|
|
|
|
userDefaultEmail != null &&
|
|
|
|
$scope.state.deleteText.toLowerCase() ===
|
|
|
|
userDefaultEmail.toLowerCase() &&
|
|
|
|
$scope.state.password.length > 0 &&
|
|
|
|
$scope.state.confirmV1Purge &&
|
|
|
|
$scope.state.confirmSharelatexDelete)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.delete = function() {
|
|
|
|
$scope.state.inflight = true
|
|
|
|
$scope.state.error = null
|
|
|
|
return $http({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/user/delete',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
password: $scope.state.password
|
|
|
|
},
|
|
|
|
disableAutoLoginRedirect: true // we want to handle errors ourselves
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
$modalInstance.close()
|
|
|
|
$scope.state.inflight = false
|
|
|
|
$scope.state.error = null
|
2019-08-28 08:59:41 -04:00
|
|
|
setTimeout(() => (window.location = '/login'), 1000)
|
2019-07-16 05:13:18 -04:00
|
|
|
})
|
|
|
|
.catch(function(response) {
|
|
|
|
const { data, status } = response
|
|
|
|
$scope.state.inflight = false
|
|
|
|
if (status === 403) {
|
|
|
|
$scope.state.error = { code: 'InvalidCredentialsError' }
|
2019-08-28 08:59:41 -04:00
|
|
|
} else if (data.error) {
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.state.error = { code: data.error }
|
2019-08-28 08:59:41 -04:00
|
|
|
} else {
|
|
|
|
$scope.state.error = { code: 'UserDeletionError' }
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2019-08-28 08:59:41 -04:00
|
|
|
$scope.cancel = () => $modalInstance.dismiss('cancel')
|
2019-07-16 05:13:18 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|