From c89ecd71343faf0c59254443f48a2fb736b3490c Mon Sep 17 00:00:00 2001 From: raphael Date: Fri, 24 Apr 2020 17:54:56 +0000 Subject: [PATCH] adds backend script which can be run as a cronjob every n minutes to generate new json files for google calendars - database updated to save google credentials - database updated to save json calendar information - json still saved as a json file under userinfo//calendarevents.json --- app.db | Bin 45056 -> 45056 bytes app.py | 3 +++ migrations/versions/66f62f457a22_.py | 28 +++++++++++++++++++++++++++ migrations/versions/7bbc2215d87d_.py | 28 +++++++++++++++++++++++++++ server/__init__.py | 1 - server/googleHandler.py | 4 ++-- server/models.py | 20 +++++++++++++++++++ server/routes.py | 7 +++---- 8 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 migrations/versions/66f62f457a22_.py create mode 100644 migrations/versions/7bbc2215d87d_.py diff --git a/app.db b/app.db index b6fb9828714fac150c0468ad7b44488677d25b67..ca2cebc86685583770bd51e66cf630ebed74614b 100644 GIT binary patch delta 1463 zcmb_c&u6kc0yQow*($x5a6fHw!%lFg50VZprw3^s&7DPSD(LukA^YbM^^S$1b3 z7`bcIQ>sd>%b(C*daIjDdq^wwlylBKA zJUpE={Qil3@#3YWrMWN4)A8c>C0+&^G!$T6wXwlR+PTJNDc4ww>|?yI!LDpU1sVha z&Hm?~-&b#xtGPxeQYm&KA0uVezdC&w_+cUZl>7Z;^6Q0_cQ0J}WNG?a_=EeO1;2ZL zF`ZV^f-0sYAP7H2{tUn9h|gUKgmrG-_ki;~2t7HSoccmvuFnOe)x;zfytjSto#}FB zY5J8*+%bQE429o_{4M)398i5WzZT)oRvVF3t@&P)n7(P8Q-8e?kl@gL=&8uJ7nK!ffZKLSEF3gS5^YJ<&$qGQo^%dMs~XqMpi^*h-;u$dif zWzF*L7RgsTJ3^|eu2;9~s#3`Ji;BFZHWGJHt0=|QVomARhb?KRtc}$AVLN|-HudXr ztCp`9+kLrkSRuQ$YlW*xr+gz{7r~w8U|4J?tESR-vc*!NfQ(A~?q0$bFlg4HW+ivq zN_B)YHNAfzuV;4RpYF5MYeCh5cCS0D!EiKG zj>=e%J&&X@vWDnfb&)r0NlB72QX=C@l9*Yyd(HrfsGr(H;=Te&x}QWC5P)>NXNy`d z3QW^JOYGRtqQ{-kTr58md6t=ufdvUuRC2nVUALwHJddi2x;d$AtmKftghKi$52S{VlvszypVOm&48hl+0&uC^BX4HZ}!G<unGL-BKNz^UPcZQF^6%v1-i$$tSp1ay8nsvx|$0GBzbnzQeUdii'.format(self.username) @@ -22,6 +25,23 @@ class User(UserMixin, db.Model): def checkPassword(self, password): return check_password_hash(self.password_hash, password) + def setJson(self, jsonObject): + self.calendarJson = json.dumps(jsonObject) + db.session.commit() + + def getJson(self): + return json.loads(self.calendarJson) + + def setGoogleCredentials(self, credentials): + self.google_credentials = json.dumps(credentials) + db.session.commit() + + def getGoogleCredentials(self): + + if self.google_credentials is None: + return None + return json.loads(self.google_credentials) + class Calendar(db.Model): usr_id = db.Column(db.String(21), index=True) calendar_id = db.Column(db.String(256), primary_key=True) diff --git a/server/routes.py b/server/routes.py index ffb9d64..defb040 100644 --- a/server/routes.py +++ b/server/routes.py @@ -82,8 +82,7 @@ def googlelogin(): @app.route("/login/google/callback") def callback(): - session = google.verifyResponse() - + session, credentials = google.verifyResponse() userinfo = session.get('https://www.googleapis.com/userinfo/v2/me').json() # Create a user in your db with the information provided @@ -107,7 +106,7 @@ def callback(): print("login:" + user.id) login_user(user) - + user.setGoogleCredentials(credentials) return flask.redirect(flask.url_for('index')) @app.route("/logout") @@ -128,7 +127,7 @@ def credentials_to_dict(credentials): @app.route("/userinfo//calendarevents.json") def downloader(user): print(user) - path = "/home/raphael/dev/website_ws/website/userinfo/" + user + path = "userinfo/" + user return flask.send_from_directory(path, "calendarevents.json") # POST