Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if user is None:
user = User(token=oauth_token)
# Set this to use API to get user data
g.user = user
user_data = github.get("user")
# extract data
uid = user_data["id"]
username = user_data["login"]
avatar_url = user_data["avatar_url"]
# Create/update the user
user = User.query.filter_by(uid=uid).first()
if user is None:
user = User(
token=oauth_token,
uid=uid,
username=username,
avatar_url=avatar_url,
)
else:
user.username = username
user.avatar_url = avatar_url
user.token = oauth_token
user.save()
session["username"] = user.username
session["user_id"] = user.id
g.user = user
# Ensure a user with token doesn't already exist
user = User.query.filter_by(token=oauth_token).first()
if user is None:
user = User(token=oauth_token)
# Set this to use API to get user data
g.user = user
user_data = github.get("user")
# extract data
uid = user_data["id"]
username = user_data["login"]
avatar_url = user_data["avatar_url"]
# Create/update the user
user = User.query.filter_by(uid=uid).first()
if user is None:
user = User(
token=oauth_token,
uid=uid,
username=username,
avatar_url=avatar_url,
)
else:
user.username = username
user.avatar_url = avatar_url
user.token = oauth_token
user.save()
session["username"] = user.username
session["user_id"] = user.id
def authorized(oauth_token):
"""Github authorization callback."""
next_url = request.args.get("next") or url_for("user.user")
if oauth_token is None:
flash("Authorization failed.")
return redirect(next_url)
# Ensure a user with token doesn't already exist
user = User.query.filter_by(token=oauth_token).first()
if user is None:
user = User(token=oauth_token)
# Set this to use API to get user data
g.user = user
user_data = github.get("user")
# extract data
uid = user_data["id"]
username = user_data["login"]
avatar_url = user_data["avatar_url"]
# Create/update the user
user = User.query.filter_by(uid=uid).first()
if user is None:
user = User(
token=oauth_token,
uid=uid,
def authorized(oauth_token):
"""Github authorization callback."""
next_url = request.args.get("next") or url_for("user.user")
if oauth_token is None:
flash("Authorization failed.")
return redirect(next_url)
# Ensure a user with token doesn't already exist
user = User.query.filter_by(token=oauth_token).first()
if user is None:
user = User(token=oauth_token)
# Set this to use API to get user data
g.user = user
user_data = github.get("user")
# extract data
uid = user_data["id"]
username = user_data["login"]
avatar_url = user_data["avatar_url"]
# Create/update the user
user = User.query.filter_by(uid=uid).first()
if user is None:
user = User(
def before_request():
"""Execute before requests."""
g.user = None
if "user_id" in session:
g.user = User.query.get(session["user_id"])
if "db" not in g:
g.db = db