From ee54dd5daabed0dd2d50ca74e22d66fdc0639ff2 Mon Sep 17 00:00:00 2001 From: Raphael Maenle Date: Sun, 17 May 2020 22:59:12 +0200 Subject: [PATCH] updates color generation, tries fixing credentials bug - credentials still lost the refresh token after a certain event - this was now fixed by completely removing any saves past the first one - https://trello.com/c/iORYLYHl/44-1-check-on-credentials - Color Coding is now updated - fixed an incorrect color mapping in the colors.json - updates some calls to functions to correctly get the natural colors - the incorrect red -> yellow mapping might have to do with the previous credentials error --- app.db | Bin 45056 -> 45056 bytes app.db.old | Bin 0 -> 45056 bytes backend | 2 +- docker/calendarwatch/Dockerfile | 3 ++ docker/calendarwatch/docker-entrypoint.sh | 8 ++++- migrations/versions/66f62f457a22_.py | 28 ------------------ migrations/versions/7bbc2215d87d_.py | 28 ------------------ .../{92db2e496087_.py => af001b07177d_.py} | 10 ++++--- routine.py | 13 ++++++++ app.py => server.py | 0 server/googleHandler.py | 5 ++-- server/models.py | 3 +- server/routes.py | 4 ++- 13 files changed, 38 insertions(+), 66 deletions(-) create mode 100644 app.db.old delete mode 100644 migrations/versions/66f62f457a22_.py delete mode 100644 migrations/versions/7bbc2215d87d_.py rename migrations/versions/{92db2e496087_.py => af001b07177d_.py} (86%) mode change 100644 => 100755 routine.py rename app.py => server.py (100%) diff --git a/app.db b/app.db index 518e5ee827094f5e4f06ece7471dc8ec04e4a07c..b9794f2dcb97b6c11a3a870f183f0911221e5af6 100644 GIT binary patch delta 1545 zcmZ`&TWs4@81{)9C-LnxWxZ^LEh|i0rKOGQq;`5+?rYj4UDB*=%2-HJH;Hm_>m*GZ z3R?sM#0woqLX!{zX}mCmMyZ6DrV8zeNl5TA0S}v);9=T86A~bJnZWV1%L~Wy@%g{= zeZT+nfA-m1y0f=*TfOEf48th(emD&0j`9bmumRf$1OLHDY72u5yv(xf4dzSc6zybq z>JGKFV{UJ!&^78~vROA6x;s0;t5I}=9MBEh5lvNfqzRp+dRmY3l#MuSB)UgC(O0l% zC(2ytpi|2>8<(~ToF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v>c{93TJ$fB+Bx0zd!=00AHX1b_e#00KbZ zWg#$?xEVj?*)TGl;8M>zZT9Z}e;1>FNB{fFQhF!{5C8%|00;m9AOHk_01yBIKmZ5; U0U+?@2|RHFxRRJnom|HGzYs!?OaK4? literal 0 HcmV?d00001 diff --git a/backend b/backend index b5dbfd8..804ab33 160000 --- a/backend +++ b/backend @@ -1 +1 @@ -Subproject commit b5dbfd87defaaed87c73f321ac3087fe5a7c689b +Subproject commit 804ab33a6d07b34c2f0942a63c71f652dfb067f3 diff --git a/docker/calendarwatch/Dockerfile b/docker/calendarwatch/Dockerfile index 61b2119..20a239d 100644 --- a/docker/calendarwatch/Dockerfile +++ b/docker/calendarwatch/Dockerfile @@ -1,10 +1,13 @@ FROM python:3.8-slim-buster RUN apt-get update && apt-get upgrade +RUN apt-get install -y cron RUN pip3 install flask Flask-SQLAlchemy flask_migrate flask_login flask_wtf python-dotenv RUN apt-get install gcc libpcre3 libpcre3-dev -y RUN pip3 install uwsgi + RUN pip3 install email-validator RUN pip3 install google google-oauth google-auth-oauthlib google-api-python-client + COPY docker-entrypoint.sh /usr/local/bin/ EXPOSE 8084 ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/docker/calendarwatch/docker-entrypoint.sh b/docker/calendarwatch/docker-entrypoint.sh index 4c26842..8d96ba4 100755 --- a/docker/calendarwatch/docker-entrypoint.sh +++ b/docker/calendarwatch/docker-entrypoint.sh @@ -1,4 +1,10 @@ #!/bin/sh cd /home/calendarwatch # uwsgi --http-socket 0.0.0.0:8084 -w wsgi --protocol=https -python3 app.py + +python3 routine.py & +echo "routine has been started" + +python3 server.py +echo "server has been started" + diff --git a/migrations/versions/66f62f457a22_.py b/migrations/versions/66f62f457a22_.py deleted file mode 100644 index 51d1d96..0000000 --- a/migrations/versions/66f62f457a22_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""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 deleted file mode 100644 index 7da6d2e..0000000 --- a/migrations/versions/7bbc2215d87d_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""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/migrations/versions/92db2e496087_.py b/migrations/versions/af001b07177d_.py similarity index 86% rename from migrations/versions/92db2e496087_.py rename to migrations/versions/af001b07177d_.py index 2c396a3..00a7927 100644 --- a/migrations/versions/92db2e496087_.py +++ b/migrations/versions/af001b07177d_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 92db2e496087 +Revision ID: af001b07177d Revises: -Create Date: 2020-04-20 21:33:50.061962 +Create Date: 2020-05-16 13:53:02.747714 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '92db2e496087' +revision = 'af001b07177d' down_revision = None branch_labels = None depends_on = None @@ -29,11 +29,13 @@ def upgrade(): op.create_index(op.f('ix_calendar_name'), 'calendar', ['name'], unique=False) op.create_index(op.f('ix_calendar_usr_id'), 'calendar', ['usr_id'], unique=False) op.create_table('user', - sa.Column('id', sa.String(length=21), nullable=False), + sa.Column('id', sa.String(length=64), nullable=False), sa.Column('username', sa.String(length=64), nullable=True), sa.Column('email', sa.String(length=120), nullable=True), sa.Column('profile_pic', sa.String(length=256), nullable=True), sa.Column('password_hash', sa.String(length=128), nullable=True), + sa.Column('calendarJson', sa.String(), nullable=True), + sa.Column('google_credentials', sa.String(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True) diff --git a/routine.py b/routine.py old mode 100644 new mode 100755 index 95209d7..3ce435e --- a/routine.py +++ b/routine.py @@ -1,4 +1,17 @@ +#!/usr/bin/env python3 from backend.Routine import Routine +import sched, time +s = sched.scheduler(time.time, time.sleep) routine = Routine() + +def run_routine(sc): + # do some stuff + routine.start() + + #schedule next routine + s.enter(600, 1, run_routine, (sc,)) + routine.start() +s.enter(600, 1, run_routine, (s, )) +s.run() diff --git a/app.py b/server.py similarity index 100% rename from app.py rename to server.py diff --git a/server/googleHandler.py b/server/googleHandler.py index c0a8915..62cbd36 100644 --- a/server/googleHandler.py +++ b/server/googleHandler.py @@ -73,7 +73,7 @@ def verifyResponse(): flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file( CLIENT_SECRETS_FILE, scopes=SCOPES, state=state) - flow.redirect_uri = request.base_url + flow.redirect_uri = flask.url_for('callback', _external=True) # Use the authorization server's response to fetch the OAuth 2.0 tokens. authorization_response = flask.request.url @@ -82,9 +82,10 @@ def verifyResponse(): # Store credentials in the session. # ACTION ITEM: In a production app, you likely want to save these # credentials in a persistent database instead. + credentials = flow.credentials flask.session['credentials'] = credentials_to_dict(credentials) - + print(credentials_to_dict(credentials), flush=True) session = flow.authorized_session() return session, credentials_to_dict(credentials) diff --git a/server/models.py b/server/models.py index a061988..245f1a5 100644 --- a/server/models.py +++ b/server/models.py @@ -39,6 +39,7 @@ class User(UserMixin, db.Model): def getGoogleCredentials(self): if self.google_credentials is None: + print("no credentials", flush=True) return None return json.loads(self.google_credentials) @@ -86,4 +87,4 @@ class Calendar(db.Model): newcal = Calendar(usr_id=user_id, calendar_id=calendar_id, name=name, toggle=toggle, color=color) db.session.add(newcal) - db.session.commit() \ No newline at end of file + db.session.commit() diff --git a/server/routes.py b/server/routes.py index f403391..49d5d6a 100644 --- a/server/routes.py +++ b/server/routes.py @@ -116,7 +116,9 @@ def callback(): print("login:" + user.id) login_user(user) - user.setGoogleCredentials(credentials) + # TODO currently not using the credentials anymore + if user.getGoogleCredentials() is None: + user.setGoogleCredentials(credentials) return flask.redirect(flask.url_for('index')) @app.route("/logout")