Remove redundant DB query on account activation

This commit is contained in:
coolneng 2020-10-04 16:42:18 +02:00
parent ac16b4dfee
commit f37b7392e2
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 10 additions and 6 deletions

View File

@ -60,12 +60,16 @@ def update_otp(data: OTPResend, db):
db.commit() db.commit()
def activate_account(data: OTPVerify, db): )
db.query(Users).filter(Users.access_key == data.access_key).update( return user
def activate_account(user, db):
db.query(Users).filter(Users.access_key == user.access_key).update(
{Users.status: 1} {Users.status: 1}
) )
user = fetch_user_by_key(data=data, db=db) db.commit()
return user db.refresh(user)
def verify_otp(data: OTPVerify, db): def verify_otp(data: OTPVerify, db):
@ -74,7 +78,7 @@ def verify_otp(data: OTPVerify, db):
valid_time = datetime.now() < user.otp_valid_time valid_time = datetime.now() < user.otp_valid_time
valid_otp = matching_otp and valid_time valid_otp = matching_otp and valid_time
if valid_otp: if valid_otp:
result = activate_account(data=data, db=db) activate_account(user=user, db=db)
return result return user
else: else:
raise HTTPException(status_code=400, detail="The OTP is not correct") raise HTTPException(status_code=400, detail="The OTP is not correct")