2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../../base'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export default App.controller(
|
|
|
|
'UserOauthController',
|
|
|
|
function ($http, $scope, $q) {
|
|
|
|
const _reset = function () {
|
|
|
|
$scope.ui = {
|
2020-05-19 05:02:56 -04:00
|
|
|
hasError: false,
|
2021-04-27 03:52:58 -04:00
|
|
|
errorMessage: '',
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -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'
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.unlink = providerId => {
|
|
|
|
if (window.ExposedSettings.isOverleaf) {
|
|
|
|
// UI
|
|
|
|
$scope.providers[providerId].ui = {
|
|
|
|
hasError: false,
|
2021-04-27 03:52:58 -04:00
|
|
|
isProcessing: true,
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
// Data for update
|
|
|
|
const data = {
|
|
|
|
_csrf: window.csrfToken,
|
|
|
|
link: false,
|
2021-04-27 03:52:58 -04:00
|
|
|
providerId,
|
2021-04-14 09:17:21 -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
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
_reset()
|
|
|
|
}
|
|
|
|
)
|