expephalon-kumisms/core/helpers/otp.py

25 lines
667 B
Python
Raw Normal View History

from core.models import OTPUser
from core.modules.otp import providers
def get_user_otps(user):
try:
all_otps = OTPUser.objects.filter(user=user)
except:
return {}
user_providers = [otp.provider for otp in all_otps]
active_providers = {}
for name, provider in providers.items():
if name in user_providers:
active_providers[name] = provider
return active_providers
def get_otp_by_name(name):
for pname, provider in providers.items():
if pname == name:
return provider
def get_otp_choices(user):
return [(name, provider) for name, provider in get_user_otps(user).items()]