flows: rename AuthenticationStage to StageView as its a general base view

This commit is contained in:
Jens Langhammer 2020-05-17 00:03:06 +02:00
parent 0b70007926
commit 09ef58350c
13 changed files with 28 additions and 33 deletions

View File

@ -1,33 +1,27 @@
"""passbook stage Base view"""
from typing import Any, Dict
from django.forms import ModelForm
from django.http import HttpRequest
from django.utils.translation import gettext as _
from django.views.generic import TemplateView
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.views import FlowExecutorView
from passbook.lib.config import CONFIG
class AuthenticationStage(TemplateView):
"""Abstract Authentication stage, inherits TemplateView but can be combined with FormView"""
class StageView(TemplateView):
"""Abstract Stage, inherits TemplateView but can be combined with FormView"""
form: ModelForm = None
template_name = "login/form_with_user.html"
executor: FlowExecutorView
request: HttpRequest = None
template_name = "login/form_with_user.html"
def __init__(self, executor: FlowExecutorView):
self.executor = executor
def get_context_data(self, **kwargs: Dict[str, Any]) -> Dict[str, Any]:
kwargs["config"] = CONFIG.y("passbook")
kwargs["title"] = self.executor.flow.name
kwargs["primary_action"] = _("Log in")
if PLAN_CONTEXT_PENDING_USER in self.executor.plan.context:
kwargs["user"] = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]
return super().get_context_data(**kwargs)

View File

@ -2,11 +2,11 @@
from django.views.generic import FormView
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.stages.captcha.forms import CaptchaForm
class CaptchaStage(FormView, AuthenticationStage):
class CaptchaStage(FormView, StageView):
"""Simple captcha checker, logic is handeled in django-captcha module"""
form_class = CaptchaForm

View File

@ -1,10 +1,10 @@
"""passbook multi-stage authentication engine"""
from django.http import HttpRequest
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
class DummyStage(AuthenticationStage):
class DummyStage(StageView):
"""Dummy stage for testing with multiple stages"""
def post(self, request: HttpRequest):

View File

@ -12,7 +12,7 @@ from structlog import get_logger
from passbook.core.models import Token
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.stages.email.forms import EmailStageSendForm
from passbook.stages.email.tasks import send_mails
from passbook.stages.email.utils import TemplateEmailMessage
@ -21,7 +21,7 @@ LOGGER = get_logger()
QS_KEY_TOKEN = "token"
class EmailStageView(FormView, AuthenticationStage):
class EmailStageView(FormView, StageView):
"""E-Mail stage which sends E-Mail for verification"""
form_class = EmailStageSendForm

View File

@ -12,14 +12,14 @@ from structlog import get_logger
from passbook.core.models import Source, User
from passbook.flows.models import FlowDesignation
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.stages.identification.forms import IdentificationForm
from passbook.stages.identification.models import IdentificationStage
LOGGER = get_logger()
class IdentificationStageView(FormView, AuthenticationStage):
class IdentificationStageView(FormView, StageView):
"""Form to identify the user"""
form_class = IdentificationForm
@ -47,6 +47,7 @@ class IdentificationStageView(FormView, AuthenticationStage):
"passbook_flows:flow-executor",
kwargs={"flow_slug": recovery_flow.slug},
)
kwargs["primary_action"] = _("Log in")
# Check all enabled source, add them if they have a UI Login button.
kwargs["sources"] = []

View File

@ -2,14 +2,14 @@
from django.http import HttpRequest, HttpResponse
from django.shortcuts import get_object_or_404
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.stages.invitation.models import Invitation, InvitationStage
from passbook.stages.prompt.stage import PLAN_CONTEXT_PROMPT
INVITATION_TOKEN_KEY = "token"
class InvitationStageView(AuthenticationStage):
class InvitationStageView(StageView):
"""Finalise Authentication flow by logging the user in"""
def get(self, request: HttpRequest) -> HttpResponse:

View File

@ -6,14 +6,14 @@ from django_otp import match_token, user_has_device
from structlog import get_logger
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.stages.otp.forms import OTPVerifyForm
from passbook.stages.otp.views import OTP_SETTING_UP_KEY, EnableView
LOGGER = get_logger()
class OTPStage(FormView, AuthenticationStage):
class OTPStage(FormView, StageView):
"""OTP Stage View"""
template_name = "stages/otp/stage.html"

View File

@ -14,7 +14,7 @@ from structlog import get_logger
from passbook.core.models import User
from passbook.flows.models import Flow, FlowDesignation
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.lib.utils.reflection import path_to_class
from passbook.stages.password.forms import PasswordForm
@ -46,7 +46,7 @@ def authenticate(
)
class PasswordStage(FormView, AuthenticationStage):
class PasswordStage(FormView, StageView):
"""Authentication stage which authenticates against django's AuthBackend"""
form_class = PasswordForm

View File

@ -4,14 +4,14 @@ from django.utils.translation import gettext_lazy as _
from django.views.generic import FormView
from structlog import get_logger
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.stages.prompt.forms import PromptForm
LOGGER = get_logger()
PLAN_CONTEXT_PROMPT = "prompt_data"
class PromptStageView(FormView, AuthenticationStage):
class PromptStageView(FormView, StageView):
"""Prompt Stage, save form data in plan context."""
template_name = "login/form.html"

View File

@ -7,13 +7,13 @@ from structlog import get_logger
from passbook.core.models import User
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.stages.user_delete.forms import UserDeleteForm
LOGGER = get_logger()
class UserDeleteStageView(FormView, AuthenticationStage):
class UserDeleteStageView(FormView, StageView):
"""Finalise unenrollment flow by deleting the user object."""
form_class = UserDeleteForm

View File

@ -6,13 +6,13 @@ from django.utils.translation import gettext as _
from structlog import get_logger
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
LOGGER = get_logger()
class UserLoginStageView(AuthenticationStage):
class UserLoginStageView(StageView):
"""Finalise Authentication flow by logging the user in"""
def get(self, request: HttpRequest) -> HttpResponse:

View File

@ -3,12 +3,12 @@ from django.contrib.auth import logout
from django.http import HttpRequest, HttpResponse
from structlog import get_logger
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
LOGGER = get_logger()
class UserLogoutStageView(AuthenticationStage):
class UserLogoutStageView(StageView):
"""Finalise Authentication flow by logging the user in"""
def get(self, request: HttpRequest) -> HttpResponse:

View File

@ -7,7 +7,7 @@ from structlog import get_logger
from passbook.core.models import User
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage
from passbook.flows.stage import StageView
from passbook.lib.utils.reflection import class_to_path
from passbook.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
from passbook.stages.prompt.stage import PLAN_CONTEXT_PROMPT
@ -15,7 +15,7 @@ from passbook.stages.prompt.stage import PLAN_CONTEXT_PROMPT
LOGGER = get_logger()
class UserWriteStageView(AuthenticationStage):
class UserWriteStageView(StageView):
"""Finalise Enrollment flow by creating a user object."""
def get(self, request: HttpRequest) -> HttpResponse: