forked from aaronn/django-rest-framework-passwordless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.py
22 lines (19 loc) · 833 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
from django.utils.module_loading import import_string
from drfpasswordless.settings import api_settings
from drfpasswordless.utils import (
create_callback_token_for_user,
)
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 = import_string(api_settings.PASSWORDLESS_EMAIL_CALLBACK)
elif alias_type == 'mobile':
send_action = import_string(api_settings.PASSWORDLESS_SMS_CALLBACK)
# Send to alias
success = send_action(user, token, **message_payload)
return success