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
This commit is contained in:
2020-05-17 22:59:12 +02:00
parent 1b7980e834
commit ee54dd5daa
13 changed files with 38 additions and 66 deletions

View File

@ -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)

View File

@ -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()
db.session.commit()

View File

@ -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")