mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-28 10:42:43 +00:00
Forge a form submission to avoid CORS checking with wufoo.
This commit is contained in:
parent
32b57f228c
commit
1c9d0a417f
1 changed files with 26 additions and 17 deletions
|
@ -2,12 +2,12 @@ define [
|
|||
"base"
|
||||
], (App) ->
|
||||
App.factory "logHintsFeedback", ($http, $q) ->
|
||||
if window.sharelatex?.wufoo? and window.sharelatex.wufoo?.token? and window.sharelatex.wufoo?.url?
|
||||
hintsFeedbackFormAPIHash = "rl4xgvr1v5t64a"
|
||||
hintFieldAPIId = '3'
|
||||
feedbackFieldAPIId = '1'
|
||||
basicAuthVal = window.btoa "#{ window.sharelatex.wufoo.token }:anypasswilldo"
|
||||
submitEndpoint = "#{ window.sharelatex.wufoo.url }/api/v3/forms/#{ hintsFeedbackFormAPIHash }/entries.json"
|
||||
idStampVal = "OPkEWEFHUFAm7hKlraQMhiOXQabafWo8NipRvLT397w="
|
||||
hintFieldAPIId = "3"
|
||||
reasonFieldAPIId = "1"
|
||||
reasonOtherFieldAPIId = "1_other_other"
|
||||
submitEndpoint = "https://sharelatex.wufoo.eu/forms/#{ hintsFeedbackFormAPIHash }/#public"
|
||||
|
||||
feedbackOpts =
|
||||
DIDNT_UNDERSTAND: "didnt_understand"
|
||||
|
@ -16,25 +16,34 @@ define [
|
|||
OTHER: "other"
|
||||
|
||||
createRequest = (hintId, feedbackOpt, feedbackOtherVal = "") ->
|
||||
formData = new FormData()
|
||||
|
||||
formData.append "Field#{ hintFieldAPIId }", hintId
|
||||
formData.append "Field#{ reasonFieldAPIId }", feedbackOpt
|
||||
formData.append "Field#{ reasonOtherFieldAPIId }", feedbackOtherVal
|
||||
formData.append "idstamp", idStampVal
|
||||
|
||||
req =
|
||||
method: 'POST'
|
||||
url: submitEndpoint
|
||||
headers:
|
||||
Authorization: "Basic #{ basicAuthVal }"
|
||||
|
||||
req.data = {}
|
||||
req.data["Field#{ hintFieldAPIId }"] = hintId
|
||||
req.data["Field#{ hintFieldAPIId }"] = feedbackOpt
|
||||
|
||||
if feedbackOpt == feedbackOpts.OTHER and feedbackOtherVal != ""
|
||||
req.data["Field#{ hintFieldAPIId }"] = feedbackOtherVal
|
||||
# This will effectively disable Angular's default serialization mechanisms,
|
||||
# forcing the XHR to be done with whatever data we provide (in this case,
|
||||
# form data). Without this, Angular will forcefully try to serialize data
|
||||
# to JSON.
|
||||
transformRequest: angular.identity
|
||||
data: formData
|
||||
headers :
|
||||
# This will tell Angular to use the browser-provided value, which is
|
||||
# computed according to the data being sent (in this case, multipart
|
||||
# form + browser-specific multipart boundary). Without this, Angular
|
||||
# will set JSON.
|
||||
"Content-Type": undefined
|
||||
|
||||
return req
|
||||
|
||||
submitFeedback = (hintId, feedbackOpt, feedbackOtherVal = "") ->
|
||||
submitRequest = createRequest hintId, feedbackOpt, feedbackOtherVal
|
||||
|
||||
submitFeedback.then (response) ->
|
||||
$http(submitRequest).then (response) ->
|
||||
console.log response
|
||||
|
||||
service =
|
||||
|
|
Loading…
Reference in a new issue