Remove redundant DB query on account activation
This commit is contained in:
		
							parent
							
								
									ac16b4dfee
								
							
						
					
					
						commit
						f37b7392e2
					
				@ -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")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user