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/<user.id>/calendarevents.json
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
|
@ -86,7 +86,7 @@ def verifyResponse():
|
||||
flask.session['credentials'] = credentials_to_dict(credentials)
|
||||
|
||||
session = flow.authorized_session()
|
||||
return session
|
||||
return session, credentials_to_dict(credentials)
|
||||
|
||||
|
||||
def get_google_provider_cfg():
|
||||
@ -103,7 +103,7 @@ def calendarsFromDb():
|
||||
pyCalendars = []
|
||||
for calendar in calendars:
|
||||
name = calendar.name
|
||||
calId = calendar.calendar_id
|
||||
# calId = calendar.calendar_id
|
||||
toggle = calendar.toggle
|
||||
color = calendar.color
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import json
|
||||
from flask_login import UserMixin
|
||||
from server import login_manager, db
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
@ -12,6 +13,8 @@ class User(UserMixin, db.Model):
|
||||
email = db.Column(db.String(120), index=True, unique=True)
|
||||
profile_pic = db.Column(db.String(256))
|
||||
password_hash = db.Column(db.String(128))
|
||||
calendarJson = db.Column(db.String)
|
||||
google_credentials = db.Column(db.String)
|
||||
|
||||
def __repr__(self):
|
||||
return '<User {}>'.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)
|
||||
|
@ -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/<path:user>/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
|
||||
|
Reference in New Issue
Block a user