Added soft deletes to all deletion functions and added deleted_at filters as required
This commit is contained in:
@@ -36,9 +36,9 @@ class AuthService:
|
||||
Raises:
|
||||
EmailAlreadyExistsError: If email is already registered
|
||||
"""
|
||||
# Check if email already exists
|
||||
existing_user = User.query.filter_by(email=email.lower()).first()
|
||||
if existing_user and existing_user.deleted_at is None:
|
||||
# Check if email already exists
|
||||
existing_user = User.query.filter_by(email=email.lower(), deleted_at=None).first()
|
||||
if existing_user:
|
||||
raise EmailAlreadyExistsError()
|
||||
|
||||
# Create user
|
||||
@@ -280,12 +280,11 @@ class AuthService:
|
||||
raise ConflictError("TOTP is already enabled for this account")
|
||||
|
||||
# Clean up any existing unverified TOTP enrollment attempts
|
||||
# Use hard delete for unverified methods since they're incomplete enrollment attempts
|
||||
# Soft delete for unverified methods since they're incomplete enrollment attempts
|
||||
existing_totp_method = user.get_totp_method()
|
||||
if existing_totp_method and not existing_totp_method.verified:
|
||||
logger.debug(f"Removing existing unverified TOTP method for user {user.id}")
|
||||
db.session.delete(existing_totp_method) # Hard delete - unverified methods are temporary
|
||||
db.session.commit() # Commit to ensure deletion before creating new record
|
||||
existing_totp_method.delete(soft=True) # Soft delete - unverified methods are temporary
|
||||
|
||||
# Generate TOTP secret
|
||||
secret = TOTPService.generate_secret()
|
||||
|
||||
Reference in New Issue
Block a user