mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-02-21 18:12:00 +00:00
24 lines
783 B
Python
24 lines
783 B
Python
from djangopasswordlessknox.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, **message_payload):
|
|
token = create_callback_token_for_user(user, alias_type)
|
|
send_action = None
|
|
if alias_type == 'email':
|
|
send_action = send_email_with_callback_token
|
|
elif alias_type == 'mobile':
|
|
send_action = send_sms_with_callback_token
|
|
|
|
if send_action is None:
|
|
raise ValueError(f"Invalid alias_type: {alias_type}")
|
|
|
|
# Send to alias
|
|
success = send_action(user, token, **message_payload)
|
|
return success
|