2020-03-18 20:56:06 +01:00
|
|
|
from secrets import randbits
|
2020-09-17 17:36:15 +02:00
|
|
|
from twilio.rest import Client
|
|
|
|
|
|
|
|
from constants import ACCOUNT_ID, SMS_SENDER, TOKEN
|
2020-04-19 21:30:41 +02:00
|
|
|
from database.crud import save_otp
|
2020-03-18 20:56:06 +01:00
|
|
|
|
|
|
|
|
2020-09-17 17:36:15 +02:00
|
|
|
def create_twilio_client(account_sid, auth_token):
|
2020-03-18 20:56:06 +01:00
|
|
|
client = Client(account_sid, auth_token)
|
|
|
|
return client
|
|
|
|
|
|
|
|
|
2020-09-12 19:34:11 +02:00
|
|
|
def send_otp(receiver):
|
2020-09-17 17:36:15 +02:00
|
|
|
client = create_twilio_client(account_sid=ACCOUNT_ID, auth_token=TOKEN)
|
|
|
|
code = randbits(k=16)
|
2020-03-18 20:56:06 +01:00
|
|
|
message = "Your OTP code is {0}".format(code)
|
2020-06-05 01:09:55 +02:00
|
|
|
client.messages.create(to=receiver, from_=SMS_SENDER, body=message)
|
2020-04-19 21:30:41 +02:00
|
|
|
save_otp(receiver, code)
|