diff --git a/backend/main.py b/backend/main.py index bb1ee72..6af9d4d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -92,7 +92,8 @@ def login(): db.collection("Users").document(validation[1]).set(user.__dict__) if '127.0.0.1' in service: - redirect_url='http://127.0.0.1:5000/dashboard' + #redirect_url='http://127.0.0.1:5000/dashboard' + redirect_url = 'http://127.0.0.1:5000' else: redirect_url='https://majoraudit.web.app/dashboard' @@ -283,7 +284,7 @@ def get_data(): @app.route('/sync_data', methods = ['POST']) -@cross_origin() +@cross_origin(origins='http://127.0.0.1:5000', supports_credentials=True) def sync_data(): # if req.method == 'OPTIONS': @@ -303,13 +304,19 @@ def sync_data(): #if not netid: # return redirect('/user_login') + headers = { + 'Access-Control-Allow-Credentials': 'true', + 'Access-Control-Allow-Origin': 'true' + } + print("here sync data") + print(session["NETID"]) data = request.json user = User("jy692", data) db.collection("Users").document("jy692").set(user.__dict__) print(data, flush=True) - return data + make_response((data, 200, headers)) #return make_response(('Data received', 200, headers)) diff --git a/frontend/index.html b/frontend/index.html index 4212d82..58a1954 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -48,6 +48,8 @@ + +
@@ -86,6 +88,27 @@ }) } + function syncData() { + var event = new CustomEvent("scrapeData", { + detail: { action: "openWebsite" } + }); + document.dispatchEvent(event); + } + + document.addEventListener("getData", function(e) { + fetch('http://127.0.0.1:5001/majoraudit/us-central1/functions/sync_data', { + method: 'POST', + mode: 'cors', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + }, + body: e.detail + }); + console.log(e); + + }); + $('document').ready(setup);