-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from nsidc/non-dev-db-issue
Fix invoke script using dev DB in non-dev
- Loading branch information
Showing
28 changed files
with
208 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import os | ||
|
||
from flask_dance.contrib.google import make_google_blueprint | ||
|
||
blueprint = make_google_blueprint( | ||
client_id=os.getenv('USAON_VTA_GOOGLE_CLIENT_ID'), | ||
client_secret=os.getenv('USAON_VTA_GOOGLE_CLIENT_SECRET'), | ||
scope=["profile", "email"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,31 @@ | ||
import os | ||
import time | ||
|
||
from flask import redirect, session, url_for | ||
from flask_dance.contrib.google import google, make_google_blueprint | ||
from flask import Blueprint, redirect, url_for | ||
from flask_dance.contrib.google import google | ||
from flask_login import login_user | ||
|
||
from usaon_vta_survey import app | ||
from usaon_vta_survey.util.db.user import ensure_user_exists | ||
|
||
blueprint = make_google_blueprint( | ||
client_id=os.getenv('USAON_VTA_GOOGLE_CLIENT_ID'), | ||
client_secret=os.getenv('USAON_VTA_GOOGLE_CLIENT_SECRET'), | ||
scope=["profile", "email"], | ||
) | ||
app.register_blueprint(blueprint, url_prefix="/google_oauth") | ||
login_bp = Blueprint('login', __name__, url_prefix='/login') | ||
|
||
|
||
@app.route("/login") | ||
@login_bp.route("") | ||
def login(): | ||
if not google.authorized: | ||
return redirect(url_for("google.login")) | ||
resp = google.get("/oauth2/v2/userinfo") | ||
assert resp.ok, resp.text | ||
|
||
user = ensure_user_exists(resp.json()) | ||
# breakpoint() | ||
login_user(user) | ||
|
||
return redirect('/') | ||
|
||
|
||
@app.before_request | ||
def before_request(): | ||
"""Handle expired google tokens as a pre-request hook.""" | ||
if token := (s := session).get('google_oauth_token'): | ||
print("Token expiring in", token['expires_at'] - time.time()) | ||
if time.time() >= token['expires_at']: | ||
del s['google_oauth_token'] | ||
# this may be the login issue | ||
# @app.before_request | ||
# def before_request(): | ||
# """Handle expired google tokens as a pre-request hook.""" | ||
# if token := (s := session).get('google_oauth_token'): | ||
# print("Token expiring in", token['expires_at'] - time.time()) | ||
# if time.time() >= token['expires_at']: | ||
# del s['google_oauth_token'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from flask import redirect | ||
from flask import Blueprint, redirect | ||
from flask_login import logout_user | ||
|
||
from usaon_vta_survey import app | ||
logout_bp = Blueprint('logout', __name__, url_prefix='/logout') | ||
|
||
|
||
@app.route("/logout") | ||
@logout_bp.route("") | ||
def logout(): | ||
logout_user() | ||
return redirect("/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.