Skip to content

Commit

Permalink
make phonenumber plugin really a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaniagualaconich committed Sep 10, 2023
1 parent d6d8b63 commit 3ea487f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions two_factor/views/profile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.apps.registry import apps
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, resolve_url
Expand Down Expand Up @@ -30,24 +29,22 @@ class ProfileView(TemplateView):
template_name = 'two_factor/profile/profile.html'

def get_context_data(self, **kwargs):
user = self.request.user

try:
backup_tokens = self.request.user.staticdevice_set.all()[0].token_set.count()
backup_tokens = user.staticdevice_set.all()[0].token_set.count()

except Exception:
backup_tokens = 0

context = {
'default_device': default_device(self.request.user),
'default_device_type': default_device(self.request.user).__class__.__name__,
'default_device': default_device(user),
'default_device_type': default_device(user).__class__.__name__,
'backup_tokens': backup_tokens,
'backup_phones': backup_phones(user),
'available_phone_methods': get_available_phone_methods(),
}

if (apps.is_installed('two_factor.plugins.phonenumber')):
context.update({
'backup_phones': backup_phones(self.request.user),
'available_phone_methods': get_available_phone_methods(),
})

return context


Expand Down

0 comments on commit 3ea487f

Please sign in to comment.