Skip to content

Commit

Permalink
Add legacy support for users not using the plugin previously
Browse files Browse the repository at this point in the history
This should only really apply to LHC, as we previously did
a bit of weird hacks to make it work previously.
  • Loading branch information
Kiro47 committed Mar 13, 2020
1 parent 1fe5298 commit 1acce32
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/discord_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def discord_oauth_callback():
if user_json:
# lookup by email
user = Users.query.filter_by(email=user_json["email"]).first()
discord_user = DiscordUser.query.filter_by(id=user_json["id"]).first()
if user is None:
# Check if user changed email
discord_user = DiscordUser.query.filter_by(id=user_json["id"]).first()
if discord_user:
user = Users.query.filter_by(email=discord_user.email)
if user:
Expand Down Expand Up @@ -105,6 +105,20 @@ def discord_oauth_callback():
db.session.add(user)
db.session.add(discord_user)
db.session.commit()
else:
# Create Discord association if does not exist (legacy support)
if not discord_user:
discord_user = DiscordUser(
id=user_json["id"],
username=user_json["username"],
discriminator=user_json["discriminator"],
avatar_hash=user_json["avatar"],
mfa_enabled=user_json["mfa_enabled"],
verified=user_json["verified"],
email=user_json["email"]
)
db.session.add(discord_user)
db.session.commit()
# Login
login_user(user)
else:
Expand Down

0 comments on commit 1acce32

Please sign in to comment.