forked from aaronn/django-rest-framework-passwordless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.py
23 lines (20 loc) · 798 Bytes
/
services.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from drfpasswordless.settings import api_settings
from drfpasswordless.utils import (
create_callback_token_for_user,
send_email_with_callback_token,
send_sms_with_callback_token
)
class TokenService(object):
@staticmethod
def send_token(user, alias_type, token_type, **message_payload):
token = create_callback_token_for_user(user, alias_type, token_type)
send_action = None
if user.pk in api_settings.PASSWORDLESS_DEMO_USERS.keys():
return True
if alias_type == 'email':
send_action = send_email_with_callback_token
elif alias_type == 'mobile':
send_action = send_sms_with_callback_token
# Send to alias
success = send_action(user, token, **message_payload)
return success