2020-05-19 05:02:56 -04:00
|
|
|
import App from '../base'
|
|
|
|
App.controller(
|
|
|
|
'TokenAccessPageController',
|
|
|
|
($scope, $http, $location, localStorage) => {
|
|
|
|
window.S = $scope
|
2022-07-28 05:20:44 -04:00
|
|
|
$scope.mode = 'accessAttempt' // 'accessAttempt' | 'v1Import' | 'requireAccept'
|
2020-02-25 04:39:53 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.v1ImportData = null
|
2022-07-28 05:20:44 -04:00
|
|
|
$scope.requireAccept = null
|
2020-02-25 04:39:53 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.accessInFlight = false
|
|
|
|
$scope.accessSuccess = false
|
|
|
|
$scope.accessError = false
|
2020-02-25 04:39:53 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.currentPath = () => {
|
|
|
|
return $location.path()
|
|
|
|
}
|
2020-02-25 04:39:53 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.buildZipDownloadPath = projectId => {
|
|
|
|
return `/overleaf/project/${projectId}/download/zip`
|
|
|
|
}
|
2020-02-25 04:39:53 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.getProjectName = () => {
|
2022-07-28 05:20:44 -04:00
|
|
|
if ($scope.v1ImportData?.name) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return $scope.v1ImportData.name
|
2022-07-28 05:20:44 -04:00
|
|
|
} else if ($scope.requireAccept?.projectName) {
|
|
|
|
return $scope.requireAccept.projectName
|
|
|
|
} else {
|
|
|
|
return 'This project'
|
2020-02-25 04:39:53 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2020-02-25 04:39:53 -05:00
|
|
|
|
2022-07-28 05:20:44 -04:00
|
|
|
$scope.postConfirmedByUser = () => {
|
|
|
|
$scope.post(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.post = (confirmedByUser = false) => {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.mode = 'accessAttempt'
|
|
|
|
const textData = $('#overleaf-token-access-data').text()
|
2021-05-05 09:05:04 -04:00
|
|
|
const parsedData = JSON.parse(textData)
|
2020-05-19 05:02:56 -04:00
|
|
|
const { postUrl, csrfToken } = parsedData
|
|
|
|
$scope.accessInFlight = true
|
2020-02-25 04:39:53 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: postUrl,
|
|
|
|
data: {
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: csrfToken,
|
2022-07-28 05:20:44 -04:00
|
|
|
confirmedByUser,
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}).then(
|
|
|
|
function successCallback(response) {
|
|
|
|
$scope.accessInFlight = false
|
|
|
|
$scope.accessError = false
|
|
|
|
const { data } = response
|
|
|
|
if (data.redirect) {
|
|
|
|
const redirect = response.data.redirect
|
|
|
|
if (!redirect) {
|
2020-02-25 04:39:53 -05:00
|
|
|
console.warn(
|
2020-05-19 05:02:56 -04:00
|
|
|
'no redirect supplied in success response data',
|
2020-02-25 04:39:53 -05:00
|
|
|
response
|
|
|
|
)
|
|
|
|
$scope.accessError = true
|
2020-05-19 05:02:56 -04:00
|
|
|
return
|
2020-02-25 04:39:53 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
window.location.replace(redirect)
|
|
|
|
} else if (data.v1Import) {
|
|
|
|
$scope.mode = 'v1Import'
|
|
|
|
$scope.v1ImportData = data.v1Import
|
2022-07-28 05:20:44 -04:00
|
|
|
} else if (data.requireAccept) {
|
|
|
|
$scope.mode = 'requireAccept'
|
|
|
|
$scope.requireAccept = data.requireAccept
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
console.warn(
|
|
|
|
'invalid data from server in success response',
|
|
|
|
response
|
|
|
|
)
|
|
|
|
$scope.accessError = true
|
2020-02-25 04:39:53 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
function errorCallback(response) {
|
|
|
|
console.warn('error response from server', response)
|
|
|
|
$scope.accessInFlight = false
|
|
|
|
$scope.accessError = response.status === 404 ? 'not_found' : 'error'
|
|
|
|
}
|
|
|
|
)
|
2020-02-25 04:39:53 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
)
|