diff --git a/app.db b/app.db index 518e5ee..b9794f2 100644 Binary files a/app.db and b/app.db differ diff --git a/app.db.old b/app.db.old new file mode 100644 index 0000000..73e7dab Binary files /dev/null and b/app.db.old differ 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")