Commit c6c0a6ab authored by Chris Lamb's avatar Chris Lamb
Browse files

Expose the "default_device" lazily in all templates via a context processor. (Closes: #46)

parent 94277cc7
from two_factor.utils import default_device
from django.contrib import messages
from django.shortcuts import render, redirect, get_object_or_404
......@@ -31,7 +29,6 @@ def view(request, state_slug=''):
'page': page,
'state': state,
'by_state': by_state,
'default_device': default_device(request.user),
})
......
......@@ -42,6 +42,7 @@ TEMPLATES = [{
'django.template.context_processors.media',
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
'freenodejobs.utils.context_processors.django_otp_context',
'freenodejobs.utils.context_processors.settings_context',
],
'builtins': [
......
from django.conf import settings
from django.utils.functional import SimpleLazyObject
from two_factor.utils import default_device
def settings_context(request):
......@@ -8,3 +11,15 @@ def settings_context(request):
"""
return {'settings': settings}
def django_otp_context(request):
"""
Lazily expose the 2FA "default_device" directly in the template for the
current user.
"""
def callback():
return default_device(request.user)
return {'default_device': SimpleLazyObject(callback)}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment