2025-01-20 14:33:03 +05:00

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