diff --git a/app.db b/app.db index b6fb982..ca2cebc 100644 Binary files a/app.db and b/app.db differ diff --git a/app.py b/app.py index eba3919..6a415da 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,8 @@ # Configuration from server import app +from backend import routine + +routine.start() if __name__ == "__main__": context = ('certificate/xip.io.crt', 'certificate/xip.io.key')#certificate and key files diff --git a/migrations/versions/66f62f457a22_.py b/migrations/versions/66f62f457a22_.py new file mode 100644 index 0000000..51d1d96 --- /dev/null +++ b/migrations/versions/66f62f457a22_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 66f62f457a22 +Revises: 7bbc2215d87d +Create Date: 2020-04-24 17:12:45.275636 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '66f62f457a22' +down_revision = '7bbc2215d87d' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('user', sa.Column('google_credentials', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('user', 'google_credentials') + # ### end Alembic commands ### diff --git a/migrations/versions/7bbc2215d87d_.py b/migrations/versions/7bbc2215d87d_.py new file mode 100644 index 0000000..7da6d2e --- /dev/null +++ b/migrations/versions/7bbc2215d87d_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 7bbc2215d87d +Revises: 92db2e496087 +Create Date: 2020-04-24 11:36:43.600038 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '7bbc2215d87d' +down_revision = '92db2e496087' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('user', sa.Column('calendarJson', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('user', 'calendarJson') + # ### end Alembic commands ### diff --git a/server/__init__.py b/server/__init__.py index 8f9a5b0..9984e05 100644 --- a/server/__init__.py +++ b/server/__init__.py @@ -1,4 +1,3 @@ - import os import sqlite3 diff --git a/server/googleHandler.py b/server/googleHandler.py index aa3caad..ae18493 100644 --- a/server/googleHandler.py +++ b/server/googleHandler.py @@ -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 diff --git a/server/models.py b/server/models.py index 58cd8ce..a061988 100644 --- a/server/models.py +++ b/server/models.py @@ -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 ''.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