Skip to content

Commit 0f0f41a

Browse files
jpaniagualaconichclaudep
authored andcommitted
unregister also when phonenumber plugin app is no longer installed (fixes #663)
1 parent 13a0f80 commit 0f0f41a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

  • two_factor/plugins/phonenumber
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.apps import AppConfig
1+
from django.apps import AppConfig, apps
22
from django.conf import settings
33
from django.test.signals import setting_changed
44

@@ -12,19 +12,21 @@ class TwoFactorPhoneNumberConfig(AppConfig):
1212
url_prefix = 'phone'
1313

1414
def ready(self):
15-
register_methods(self, None, None)
16-
setting_changed.connect(register_methods)
15+
updated_registered_methods(self, None, None)
16+
setting_changed.connect(updated_registered_methods)
1717

1818

19-
def register_methods(sender, setting, value, **kwargs):
19+
def updated_registered_methods(sender, setting, value, **kwargs):
2020
# This allows for dynamic registration, typically when testing.
2121
from .method import PhoneCallMethod, SMSMethod
2222

23-
if getattr(settings, 'TWO_FACTOR_CALL_GATEWAY', None):
23+
phone_number_app_installed = apps.is_installed('two_factor.plugins.phonenumber')
24+
25+
if phone_number_app_installed and getattr(settings, 'TWO_FACTOR_CALL_GATEWAY', None):
2426
registry.register(PhoneCallMethod())
2527
else:
2628
registry.unregister('call')
27-
if getattr(settings, 'TWO_FACTOR_SMS_GATEWAY', None):
29+
if phone_number_app_installed and getattr(settings, 'TWO_FACTOR_SMS_GATEWAY', None):
2830
registry.register(SMSMethod())
2931
else:
3032
registry.unregister('sms')

0 commit comments

Comments
 (0)