2019-04-23 10:19:52 -04:00
|
|
|
define(['base'], App =>
|
2019-07-31 04:23:30 -04:00
|
|
|
App.controller('UserOauthController', function($http, $scope, $q) {
|
2019-07-16 05:13:18 -04:00
|
|
|
const _reset = function() {
|
|
|
|
$scope.ui = {
|
|
|
|
hasError: false,
|
2019-07-31 04:23:30 -04:00
|
|
|
errorMessage: ''
|
2019-04-23 10:19:52 -04:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.providers = window.oauthProviders
|
|
|
|
$scope.thirdPartyIds = window.thirdPartyIds
|
|
|
|
}
|
|
|
|
const _unlinkError = (providerId, err) => {
|
|
|
|
$scope.providers[providerId].ui.hasError = true
|
|
|
|
$scope.providers[providerId].ui.errorMessage =
|
|
|
|
err && err.data && err.data.message ? err.data.message : 'error'
|
|
|
|
}
|
2019-05-20 11:57:58 -04:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.unlink = providerId => {
|
|
|
|
if (window.ExposedSettings.isOverleaf) {
|
|
|
|
// UI
|
|
|
|
$scope.providers[providerId].ui = {
|
|
|
|
hasError: false,
|
|
|
|
isProcessing: true
|
|
|
|
}
|
|
|
|
// Data for update
|
|
|
|
const data = {
|
|
|
|
_csrf: window.csrfToken,
|
|
|
|
link: false,
|
|
|
|
providerId
|
2019-05-20 11:57:58 -04:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
$http
|
|
|
|
.post('/user/oauth-unlink', data)
|
|
|
|
.catch(error => {
|
|
|
|
$scope.providers[providerId].ui.isProcessing = false
|
|
|
|
_unlinkError(providerId, error)
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
$scope.providers[providerId].ui.isProcessing = false
|
|
|
|
if (response.status === 200) {
|
|
|
|
$scope.thirdPartyIds[providerId] = null
|
|
|
|
} else {
|
|
|
|
_unlinkError(providerId, response)
|
|
|
|
}
|
|
|
|
})
|
2019-05-20 11:57:58 -04:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2019-05-20 11:57:58 -04:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
_reset()
|
|
|
|
}))
|