From 09ef58350c516f6d809be3897b4f5fdc9e72d4f0 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 17 May 2020 00:03:06 +0200 Subject: [PATCH] flows: rename AuthenticationStage to StageView as its a general base view --- passbook/flows/stage.py | 12 +++--------- passbook/stages/captcha/stage.py | 4 ++-- passbook/stages/dummy/stage.py | 4 ++-- passbook/stages/email/stage.py | 4 ++-- passbook/stages/identification/stage.py | 5 +++-- passbook/stages/invitation/stage.py | 4 ++-- passbook/stages/otp/stage.py | 4 ++-- passbook/stages/password/stage.py | 4 ++-- passbook/stages/prompt/stage.py | 4 ++-- passbook/stages/user_delete/stage.py | 4 ++-- passbook/stages/user_login/stage.py | 4 ++-- passbook/stages/user_logout/stage.py | 4 ++-- passbook/stages/user_write/stage.py | 4 ++-- 13 files changed, 28 insertions(+), 33 deletions(-) diff --git a/passbook/flows/stage.py b/passbook/flows/stage.py index 17bc90adb..546300c1d 100644 --- a/passbook/flows/stage.py +++ b/passbook/flows/stage.py @@ -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) diff --git a/passbook/stages/captcha/stage.py b/passbook/stages/captcha/stage.py index 2d95b8232..69e789ac3 100644 --- a/passbook/stages/captcha/stage.py +++ b/passbook/stages/captcha/stage.py @@ -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 diff --git a/passbook/stages/dummy/stage.py b/passbook/stages/dummy/stage.py index 94a2a4cb6..43a3edcdf 100644 --- a/passbook/stages/dummy/stage.py +++ b/passbook/stages/dummy/stage.py @@ -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): diff --git a/passbook/stages/email/stage.py b/passbook/stages/email/stage.py index 252cc83dd..e0dce139b 100644 --- a/passbook/stages/email/stage.py +++ b/passbook/stages/email/stage.py @@ -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 diff --git a/passbook/stages/identification/stage.py b/passbook/stages/identification/stage.py index 5c1a05e0a..d06474aaf 100644 --- a/passbook/stages/identification/stage.py +++ b/passbook/stages/identification/stage.py @@ -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"] = [] diff --git a/passbook/stages/invitation/stage.py b/passbook/stages/invitation/stage.py index e4ca3a5ef..2ec3a5de7 100644 --- a/passbook/stages/invitation/stage.py +++ b/passbook/stages/invitation/stage.py @@ -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: diff --git a/passbook/stages/otp/stage.py b/passbook/stages/otp/stage.py index 3d62f7519..7d303a9c1 100644 --- a/passbook/stages/otp/stage.py +++ b/passbook/stages/otp/stage.py @@ -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" diff --git a/passbook/stages/password/stage.py b/passbook/stages/password/stage.py index 80b2114ba..6514d72ef 100644 --- a/passbook/stages/password/stage.py +++ b/passbook/stages/password/stage.py @@ -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 diff --git a/passbook/stages/prompt/stage.py b/passbook/stages/prompt/stage.py index c7b256d46..8dba3e555 100644 --- a/passbook/stages/prompt/stage.py +++ b/passbook/stages/prompt/stage.py @@ -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" diff --git a/passbook/stages/user_delete/stage.py b/passbook/stages/user_delete/stage.py index 1547cf944..ecde61c32 100644 --- a/passbook/stages/user_delete/stage.py +++ b/passbook/stages/user_delete/stage.py @@ -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 diff --git a/passbook/stages/user_login/stage.py b/passbook/stages/user_login/stage.py index 6b3c85969..abfe18b84 100644 --- a/passbook/stages/user_login/stage.py +++ b/passbook/stages/user_login/stage.py @@ -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: diff --git a/passbook/stages/user_logout/stage.py b/passbook/stages/user_logout/stage.py index 889b94c70..cda6b7300 100644 --- a/passbook/stages/user_logout/stage.py +++ b/passbook/stages/user_logout/stage.py @@ -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: diff --git a/passbook/stages/user_write/stage.py b/passbook/stages/user_write/stage.py index 1ffc7ba35..4910e0426 100644 --- a/passbook/stages/user_write/stage.py +++ b/passbook/stages/user_write/stage.py @@ -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: