diff --git a/app/external_services.py b/app/external_services.py index 510f259..949160a 100644 --- a/app/external_services.py +++ b/app/external_services.py @@ -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 diff --git a/app/routes.py b/app/routes.py index 24b0a92..791d9ed 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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 diff --git a/app/schemas.py b/app/schemas.py index a421a9c..545ba1f 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -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) diff --git a/tests/requests_test.py b/tests/requests_test.py index 58036c3..48e8f4d 100644 --- a/tests/requests_test.py +++ b/tests/requests_test.py @@ -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