Implement resend OTP
This commit is contained in:
parent
d87aade803
commit
97700c0855
|
@ -1,7 +1,7 @@
|
|||
from twilio.rest import Client
|
||||
|
||||
from constants import ACCOUNT_ID, SMS_SENDER, TOKEN
|
||||
from database.crud import fetch_user_by_key
|
||||
from database.crud import fetch_user_by_email, fetch_user_by_key
|
||||
|
||||
|
||||
def create_twilio_client(account_sid, auth_token):
|
||||
|
@ -13,4 +13,12 @@ def send_otp(data, db):
|
|||
client = create_twilio_client(account_sid=ACCOUNT_ID, auth_token=TOKEN)
|
||||
user = fetch_user_by_key(data=data, db=db)
|
||||
message = "Your OTP code is {0}".format(user.otp)
|
||||
client.messages.create(to=data.mobile, from_=SMS_SENDER, body=message)
|
||||
# client.messages.create(to=data.mobile, from_=SMS_SENDER, body=message)
|
||||
|
||||
|
||||
def resend_otp(data, db):
|
||||
client = create_twilio_client(account_sid=ACCOUNT_ID, auth_token=TOKEN)
|
||||
user = fetch_user_by_email(data=data, db=db)
|
||||
message = "Your OTP code is {0}".format(user.otp)
|
||||
# client.messages.create(to=data.mobile, from_=SMS_SENDER, body=message)
|
||||
return user
|
||||
|
|
|
@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends
|
|||
from fastapi.security import OAuth2PasswordBearer
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.external_services import send_otp
|
||||
from app.external_services import resend_otp, send_otp
|
||||
from app.schemas import *
|
||||
from database.crud import get_db, insert_data, verify_otp
|
||||
|
||||
|
@ -31,3 +31,9 @@ def log_in(
|
|||
def validate_otp(data: OTPVerify, db: Session = Depends(get_db)):
|
||||
response = verify_otp(data=data, db=db)
|
||||
return response
|
||||
|
||||
|
||||
@router.post("/resendOTP", response_model=OTPresendResponse)
|
||||
def deliver_otp(data: OTPresend, db: Session = Depends(get_db)):
|
||||
response = resend_otp(data=data, db=db)
|
||||
return response
|
||||
|
|
|
@ -106,6 +106,20 @@ class OTPVerifyResponse(OTPBase):
|
|||
orm_mode = True
|
||||
|
||||
|
||||
class OTPresend(BaseModel):
|
||||
email: EmailStr
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class OTPresendResponse(UserCreateResponse):
|
||||
pass
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
access_key: str
|
||||
otp: int = Query(None, ge=6, le=6)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from pytest import mark, fixture
|
||||
from pytest import mark
|
||||
from secrets import token_hex
|
||||
|
||||
from app.schemas import *
|
||||
|
@ -45,3 +45,11 @@ def test_otp_verification(get_test_db):
|
|||
}
|
||||
response = client.post("/otpVerification", json=data)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_resend_otp():
|
||||
data = {
|
||||
"email": "testorganizer@odyfo.com",
|
||||
}
|
||||
response = client.post("/resendOTP", json=data)
|
||||
assert response.status_code == 200
|
||||
|
|
Loading…
Reference in New Issue