-
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Łukasz Wieczorek
committed
Oct 17, 2023
1 parent
bc9dea1
commit 57b144a
Showing
5 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
# Additional runtime dependencies | ||
|
||
plivo | ||
twilio | ||
phonenumberslite | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import plivo | ||
from django.conf import settings | ||
from django.template.loader import render_to_string | ||
|
||
|
||
class Plivo: | ||
""" | ||
Gateway for sending text messages using Plivo. | ||
""" | ||
|
||
def __init__(self): | ||
self.client = plivo.RestClient( | ||
auth_id=getattr(settings, 'PLIVO_AUTH_ID'), | ||
auth_token=getattr(settings, 'PLIVO_AUTH_TOKEN') | ||
) | ||
self.source_number = getattr(settings, 'PLIVO_SOURCE_NUMBER') | ||
|
||
def make_call(self, device, token): | ||
raise NotImplementedError | ||
|
||
def send_sms(self, device, token): | ||
text = render_to_string( | ||
'two_factor/plivo/sms_message.html', | ||
{'token': token} | ||
) | ||
send_kwargs = { | ||
'src': self.source_number, | ||
'dst': device.number.as_e164, | ||
'text': text, | ||
} | ||
|
||
self.client.messages.create(**send_kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% load i18n %} | ||
{% blocktrans trimmed %} | ||
Your OTP token is {{ token }} | ||
{% endblocktrans %} | ||
|