04/27 Updated customer invitation allow customer to create username & password 4

This commit is contained in:
2026-04-27 15:13:24 -04:00
parent c31f08dbcc
commit f941762e34
+8 -1
View File
@@ -83,13 +83,20 @@ class User(UserMixin, db.Model):
user = User.query.filter_by(set_password_token=token).first() user = User.query.filter_by(set_password_token=token).first()
if user is None: if user is None:
return None return None
# Guard: account must still be in pending-setup state
if user.password_set:
return None
if user.set_password_token_expires is None: if user.set_password_token_expires is None:
return None return None
if now_eastern() > user.set_password_token_expires: if now_eastern() > user.set_password_token_expires:
return None return None
# Constant-time comparison — prevents timing oracle on the stored token # Constant-time comparison — prevents timing oracle on the stored token.
# Wrapped in try/except to guard against unexpected type mismatches.
try:
if not hmac.compare_digest(user.set_password_token, token): if not hmac.compare_digest(user.set_password_token, token):
return None return None
except (TypeError, ValueError):
return None
return user return user
def __repr__(self): def __repr__(self):