2018-12-14 08:49:34 +00:00
|
|
|
"""passbook multi-factor authentication engine"""
|
2019-10-07 15:33:48 +01:00
|
|
|
from django.forms import ModelForm
|
|
|
|
from django.http import HttpRequest
|
2018-12-14 08:49:34 +00:00
|
|
|
from django.utils.translation import gettext as _
|
|
|
|
from django.views.generic import TemplateView
|
|
|
|
|
2019-10-07 15:33:48 +01:00
|
|
|
from passbook.core.models import User
|
|
|
|
from passbook.factors.view import AuthenticationView
|
2018-12-14 08:49:34 +00:00
|
|
|
from passbook.lib.config import CONFIG
|
|
|
|
|
|
|
|
|
|
|
|
class AuthenticationFactor(TemplateView):
|
|
|
|
"""Abstract Authentication factor, inherits TemplateView but can be combined with FormView"""
|
|
|
|
|
2019-10-07 15:33:48 +01:00
|
|
|
form: ModelForm = None
|
|
|
|
required: bool = True
|
2019-10-08 13:30:17 +01:00
|
|
|
authenticator: AuthenticationView
|
|
|
|
pending_user: User
|
2019-10-07 15:33:48 +01:00
|
|
|
request: HttpRequest = None
|
2019-02-23 19:41:43 +00:00
|
|
|
template_name = 'login/form_with_user.html'
|
2018-12-14 08:49:34 +00:00
|
|
|
|
2019-10-07 15:33:48 +01:00
|
|
|
def __init__(self, authenticator: AuthenticationView):
|
2018-12-14 08:49:34 +00:00
|
|
|
self.authenticator = authenticator
|
2019-10-08 13:30:17 +01:00
|
|
|
self.pending_user = None
|
2018-12-14 08:49:34 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2019-09-30 17:04:04 +01:00
|
|
|
kwargs['config'] = CONFIG.y('passbook')
|
2018-12-14 08:49:34 +00:00
|
|
|
kwargs['is_login'] = True
|
|
|
|
kwargs['title'] = _('Log in to your account')
|
|
|
|
kwargs['primary_action'] = _('Log in')
|
2019-02-23 19:41:43 +00:00
|
|
|
kwargs['user'] = self.pending_user
|
2018-12-14 08:49:34 +00:00
|
|
|
return super().get_context_data(**kwargs)
|