19 lines
543 B
Python
19 lines
543 B
Python
from secrets import randbits
|
|
from twilio.rest import Client
|
|
|
|
from constants import ACCOUNT_ID, SMS_SENDER, TOKEN
|
|
from database.crud import save_otp
|
|
|
|
|
|
def create_twilio_client(account_sid, auth_token):
|
|
client = Client(account_sid, auth_token)
|
|
return client
|
|
|
|
|
|
def send_otp(receiver):
|
|
client = create_twilio_client(account_sid=ACCOUNT_ID, auth_token=TOKEN)
|
|
code = randbits(k=16)
|
|
message = "Your OTP code is {0}".format(code)
|
|
client.messages.create(to=receiver, from_=SMS_SENDER, body=message)
|
|
save_otp(receiver, code)
|