Skip to content

Commit

Permalink
Prevent IntegrityError on repeated reset of journalist password
Browse files Browse the repository at this point in the history
  • Loading branch information
rmol committed Nov 5, 2020
1 parent 6b39892 commit bc43a6b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions securedrop/journalist_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ def cleanup_expired_revoked_tokens() -> None:


def revoke_token(user: Journalist, auth_token: str) -> None:
revoked_token = RevokedToken(token=auth_token, journalist_id=user.id)
db.session.add(revoked_token)
db.session.commit()
try:
revoked_token = RevokedToken(token=auth_token, journalist_id=user.id)
db.session.add(revoked_token)
db.session.commit()
except IntegrityError as e:
db.session.rollback()
if "UNIQUE constraint failed: revoked_tokens.token" not in str(e):
raise e

0 comments on commit bc43a6b

Please sign in to comment.