From 2ecb5a4b71de1f631ff5a6d3d898cfbc68474b99 Mon Sep 17 00:00:00 2001 From: Raphael Maenle Date: Fri, 15 May 2020 16:00:54 +0200 Subject: [PATCH] updates routines script and google certification handling --- app.py | 2 +- backend | 2 +- server/googleHandler.py | 12 ++++++------ server/routes.py | 12 ++++++++++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 98d357f..81a55a7 100644 --- a/app.py +++ b/app.py @@ -7,4 +7,4 @@ from backend import routine if __name__ == "__main__": context = ('certificate/xip.io.crt', 'certificate/xip.io.key')#certificate and key files # app.run('0.0.0.0', 8084, ssl_context='adhoc', debug=True) - app.run(host='0.0.0.0', port=8084) + app.run(host='0.0.0.0', port=8084, debug=True) diff --git a/backend b/backend index 8d546e3..b5dbfd8 160000 --- a/backend +++ b/backend @@ -1 +1 @@ -Subproject commit 8d546e37a890846313e62d1392a09956d109794a +Subproject commit b5dbfd87defaaed87c73f321ac3087fe5a7c689b diff --git a/server/googleHandler.py b/server/googleHandler.py index ae18493..c0a8915 100644 --- a/server/googleHandler.py +++ b/server/googleHandler.py @@ -119,7 +119,6 @@ def getCalendarJson(): # Load credentials from the session. credentials = google.oauth2.credentials.Credentials( **flask.session['credentials']) - todaysCal = caltojson.generateJsonFromCalendarEntries(credentials) with open('./userinfo/' + current_user.id + '/calendarevents.json', 'w') as outfile: json.dump(todaysCal, outfile) @@ -132,19 +131,20 @@ def updateCalendars(): return flask.redirect('login/google') # Load credentials from the session. - credentials = google.oauth2.credentials.Credentials( - **flask.session['credentials']) + # credentials = google.oauth2.credentials.Credentials( + # **flask.session['credentials']) + # a = flask.session['credentials'] + # print(a, flush=True) + # print(current_user.getGoogleCredentials(), flush=True) - + credentials = google.oauth2.credentials.Credentials(**current_user.getGoogleCredentials()) calendars = caltojson.getCalendarList(credentials) - for calendar in calendars: if dbCalendar.getCalendar(dbCalendar, current_user.id, calendar.calendarId) == None: dbCalendar.create(dbCalendar, current_user.id, calendar.calendarId, calendar.summary, calendar.color) print("updated Calendars") - # Save credentials back to session in case access token was refreshed. # ACTION ITEM: In a production app, you likely want to save these # credentials in a persistent database instead. diff --git a/server/routes.py b/server/routes.py index fe354b0..f403391 100644 --- a/server/routes.py +++ b/server/routes.py @@ -76,6 +76,14 @@ def register(): return redirect(url_for('emaillogin')) return render_template('register.html', title='Register', form=form) +@app.route("/test") +def testAPI(): + if current_user.is_authenticated: + google.updateCalendars() + return redirect('/account') + + + @app.route("/login/google") def googlelogin(): authorization_url = google.login() @@ -128,8 +136,8 @@ def credentials_to_dict(credentials): @app.route("/userinfo//calendarevents.json") def downloader(user): - print(user) - path = "userinfo/" + user + path = "/home/calendarwatch/userinfo/" + user + "/" + print(path, flush=True) return flask.send_from_directory(path, "calendarevents.json") # POST