diff --git a/authentik/flows/challenge.py b/authentik/flows/challenge.py index e503c9dc2..1c64f4a29 100644 --- a/authentik/flows/challenge.py +++ b/authentik/flows/challenge.py @@ -1,3 +1,5 @@ +from authentik.flows.transfer.common import DataclassEncoder +from dataclasses import asdict, is_dataclass from enum import Enum from json.encoder import JSONEncoder @@ -25,13 +27,6 @@ class ChallengeResponse(Serializer): pass -class ChallengeEncoder(JSONEncoder): - def default(self, obj): - if isinstance(obj, Enum): - return obj.value - return super().default(obj) - - class HttpChallengeResponse(JsonResponse): def __init__(self, challenge: Challenge, **kwargs) -> None: - super().__init__(challenge.data, encoder=ChallengeEncoder, **kwargs) + super().__init__(challenge.data, encoder=DataclassEncoder, **kwargs) diff --git a/authentik/flows/stage.py b/authentik/flows/stage.py index 92c2b69cf..5f1a72296 100644 --- a/authentik/flows/stage.py +++ b/authentik/flows/stage.py @@ -61,7 +61,7 @@ class ChallengeStageView(StageView): return HttpChallengeResponse(challenge) def post(self, request: HttpRequest, *args, **kwargs) -> HttpResponse: - challenge = self.response_class(data=request.POST) + challenge: ChallengeResponse = self.response_class(data=request.POST) if not challenge.is_valid(): return self.challenge_invalid(challenge) return self.challenge_valid(challenge) diff --git a/authentik/flows/transfer/common.py b/authentik/flows/transfer/common.py index c3cd629d0..30b3b3bbb 100644 --- a/authentik/flows/transfer/common.py +++ b/authentik/flows/transfer/common.py @@ -1,5 +1,6 @@ """transfer common classes""" from dataclasses import asdict, dataclass, field, is_dataclass +from enum import Enum from typing import Any from uuid import UUID @@ -74,6 +75,8 @@ class DataclassEncoder(DjangoJSONEncoder): return asdict(o) if isinstance(o, UUID): return str(o) + if isinstance(o, Enum): + return o.value return super().default(o) # pragma: no cover diff --git a/authentik/stages/identification/stage.py b/authentik/stages/identification/stage.py index b2adf8eb5..59569ef93 100644 --- a/authentik/stages/identification/stage.py +++ b/authentik/stages/identification/stage.py @@ -34,6 +34,8 @@ class IdentificationChallengeResponse(ChallengeResponse): class IdentificationStageView(ChallengeStageView): """Form to identify the user""" + response_class = IdentificationChallengeResponse + def get_user(self, uid_value: str) -> Optional[User]: """Find user instance. Returns None if no user was found.""" current_stage: IdentificationStage = self.executor.current_stage @@ -96,7 +98,7 @@ class IdentificationStageView(ChallengeStageView): user_identifier = challenge.data.get("uid_field") pre_user = self.get_user(user_identifier) if not pre_user: - LOGGER.debug("invalid_login") + LOGGER.debug("invalid_login", identifier=user_identifier) messages.error(self.request, _("Failed to authenticate.")) return self.challenge_invalid(challenge) self.executor.plan.context[PLAN_CONTEXT_PENDING_USER] = pre_user diff --git a/web/src/elements/AdminLoginsChart.ts b/web/src/elements/AdminLoginsChart.ts index 898d59d0a..63d1b3c35 100644 --- a/web/src/elements/AdminLoginsChart.ts +++ b/web/src/elements/AdminLoginsChart.ts @@ -47,7 +47,7 @@ export class AdminLoginsChart extends LitElement { level_tag: "error", message: "Unexpected error" }); - console.log(e); + console.error(e); }) .then((r) => { const canvas = this.shadowRoot?.querySelector("canvas"); diff --git a/web/src/elements/Expand.ts b/web/src/elements/Expand.ts index 3cb684702..524eaf702 100644 --- a/web/src/elements/Expand.ts +++ b/web/src/elements/Expand.ts @@ -19,7 +19,6 @@ export class Expand extends LitElement { } render(): TemplateResult { - console.log(this.expanded); return html`
@@ -61,26 +81,12 @@ export class IdentificationStage extends BaseStage { `; } diff --git a/web/src/pages/generic/SiteShell.ts b/web/src/pages/generic/SiteShell.ts index 687fc8d78..0e7eda4a4 100644 --- a/web/src/pages/generic/SiteShell.ts +++ b/web/src/pages/generic/SiteShell.ts @@ -138,7 +138,7 @@ export class SiteShell extends LitElement { level_tag: "error", message: "Unexpected error" }); - console.log(e); + console.error(e); }); }); });