-
-
Notifications
You must be signed in to change notification settings - Fork 457
Expand file tree
/
Copy pathapps.py
More file actions
34 lines (27 loc) · 1.13 KB
/
apps.py
File metadata and controls
34 lines (27 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from django.apps import AppConfig
from django.conf import settings
from django.test.signals import setting_changed
from two_factor.plugins.registry import registry
class TwoFactorPhoneNumberConfig(AppConfig):
name = 'two_factor.plugins.phonenumber'
verbose_name = "Django Two Factor Authentication – Phone Method"
default_auto_field = "django.db.models.AutoField"
url_prefix = 'phone'
def ready(self):
register_methods(self, None, None)
setting_changed.connect(register_methods)
def register_methods(sender, setting, value, **kwargs):
# This allows for dynamic registration, typically when testing.
from .method import PhoneCallMethod, SMSMethod, WhatsAppMethod
if getattr(settings, 'TWO_FACTOR_CALL_GATEWAY', None):
registry.register(PhoneCallMethod())
else:
registry.unregister('call')
if getattr(settings, 'TWO_FACTOR_SMS_GATEWAY', None):
registry.register(SMSMethod())
else:
registry.unregister('sms')
if getattr(settings, 'TWO_FACTOR_WHATSAPP_GATEWAY', None):
registry.register(WhatsAppMethod())
else:
registry.unregister('wa')