2018-12-14 08:49:34 +00:00
|
|
|
"""passbook multi-factor authentication engine"""
|
2020-05-08 14:10:27 +00:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
2019-10-07 14:33:48 +00: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
|
|
|
|
|
2020-05-08 14:10:27 +00:00
|
|
|
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
|
|
|
|
from passbook.flows.views import FlowExecutorView
|
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 14:33:48 +00:00
|
|
|
form: ModelForm = None
|
2020-05-08 14:10:27 +00:00
|
|
|
|
|
|
|
executor: FlowExecutorView
|
|
|
|
|
2019-10-07 14:33:48 +00:00
|
|
|
request: HttpRequest = None
|
2019-12-31 11:51:16 +00:00
|
|
|
template_name = "login/form_with_user.html"
|
2018-12-14 08:49:34 +00:00
|
|
|
|
2020-05-08 14:10:27 +00:00
|
|
|
def __init__(self, executor: FlowExecutorView):
|
|
|
|
self.executor = executor
|
2018-12-14 08:49:34 +00:00
|
|
|
|
2020-05-08 14:10:27 +00:00
|
|
|
def get_context_data(self, **kwargs: Dict[str, Any]) -> Dict[str, Any]:
|
2019-12-31 11:51:16 +00:00
|
|
|
kwargs["config"] = CONFIG.y("passbook")
|
|
|
|
kwargs["title"] = _("Log in to your account")
|
|
|
|
kwargs["primary_action"] = _("Log in")
|
2020-05-08 14:10:27 +00:00
|
|
|
if PLAN_CONTEXT_PENDING_USER in self.executor.plan.context:
|
|
|
|
kwargs["user"] = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]
|
2018-12-14 08:49:34 +00:00
|
|
|
return super().get_context_data(**kwargs)
|