From 26b0fa5437d786356b72b7ab1007c62d989337cb Mon Sep 17 00:00:00 2001
From: Joscha <34318751+josxha@users.noreply.github.com>
Date: Fri, 3 Nov 2023 22:10:45 +0100
Subject: [PATCH] fix 2fa login, add ViewComponents
---
KratosSelfService/KratosSelfService.csproj | 1 +
KratosSelfService/Models/models.cs | 8 ++-
KratosSelfService/ViewComponents/KratosUi.cs | 13 +++++
.../ViewComponents/KratosUiTextMessages.cs | 13 +++++
KratosSelfService/Views/Login/Login.cshtml | 51 ++++++++-----------
.../Views/Recovery/Recovery.cshtml | 19 ++-----
.../Views/Registration/Registration.cshtml | 49 ++++++++----------
.../Views/Settings/Settings.cshtml | 8 +--
.../Shared/Components/KratosUi/Default.cshtml | 30 +++++++++++
.../KratosUiTextMessages/Default.cshtml | 9 ++++
.../Views/Verification/Verification.cshtml | 19 ++-----
11 files changed, 125 insertions(+), 95 deletions(-)
create mode 100644 KratosSelfService/ViewComponents/KratosUi.cs
create mode 100644 KratosSelfService/ViewComponents/KratosUiTextMessages.cs
create mode 100644 KratosSelfService/Views/Shared/Components/KratosUi/Default.cshtml
create mode 100644 KratosSelfService/Views/Shared/Components/KratosUiTextMessages/Default.cshtml
diff --git a/KratosSelfService/KratosSelfService.csproj b/KratosSelfService/KratosSelfService.csproj
index f96b8b2..6bfc6b9 100644
--- a/KratosSelfService/KratosSelfService.csproj
+++ b/KratosSelfService/KratosSelfService.csproj
@@ -75,6 +75,7 @@
+
diff --git a/KratosSelfService/Models/models.cs b/KratosSelfService/Models/models.cs
index c42117e..82e7c8a 100644
--- a/KratosSelfService/Models/models.cs
+++ b/KratosSelfService/Models/models.cs
@@ -33,8 +33,7 @@ List OtherSessions
);
public record SettingsModel(
- KratosSettingsFlow flow,
- string postUri
+ KratosSettingsFlow flow
);
public record VerificationModel(
@@ -63,3 +62,8 @@ public record KratosUiNodeModel(
string? forgotPasswordUrl = null
);
+public record KratosUiModel(
+ KratosUiContainer ui,
+ FlowType flowType,
+ string? forgotPasswordUrl = null
+);
\ No newline at end of file
diff --git a/KratosSelfService/ViewComponents/KratosUi.cs b/KratosSelfService/ViewComponents/KratosUi.cs
new file mode 100644
index 0000000..1b0a188
--- /dev/null
+++ b/KratosSelfService/ViewComponents/KratosUi.cs
@@ -0,0 +1,13 @@
+using KratosSelfService.Models;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.ViewComponents;
+
+namespace KratosSelfService.ViewComponents;
+
+public class KratosUi : ViewComponent
+{
+ public async Task InvokeAsync(KratosUiModel model)
+ {
+ return View("Default", model);
+ }
+}
\ No newline at end of file
diff --git a/KratosSelfService/ViewComponents/KratosUiTextMessages.cs b/KratosSelfService/ViewComponents/KratosUiTextMessages.cs
new file mode 100644
index 0000000..4d1b6ca
--- /dev/null
+++ b/KratosSelfService/ViewComponents/KratosUiTextMessages.cs
@@ -0,0 +1,13 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.ViewComponents;
+using Ory.Kratos.Client.Model;
+
+namespace KratosSelfService.ViewComponents;
+
+public class KratosUiTextMessages : ViewComponent
+{
+ public async Task InvokeAsync(List? model)
+ {
+ return View("Default", model);
+ }
+}
\ No newline at end of file
diff --git a/KratosSelfService/Views/Login/Login.cshtml b/KratosSelfService/Views/Login/Login.cshtml
index 6ccdae4..5cb1075 100644
--- a/KratosSelfService/Views/Login/Login.cshtml
+++ b/KratosSelfService/Views/Login/Login.cshtml
@@ -12,35 +12,28 @@
-
\ No newline at end of file
+@await Component.InvokeAsync("KratosUiTextMessages", Model.flow.Ui.Messages)
+
+@await Component.InvokeAsync("KratosUi", new KratosUiModel(
+ Model.flow.Ui,
+ FlowType.Recovery))
\ No newline at end of file
diff --git a/KratosSelfService/Views/Registration/Registration.cshtml b/KratosSelfService/Views/Registration/Registration.cshtml
index e3c9669..e6020aa 100644
--- a/KratosSelfService/Views/Registration/Registration.cshtml
+++ b/KratosSelfService/Views/Registration/Registration.cshtml
@@ -12,35 +12,26 @@
-
+}
\ No newline at end of file
diff --git a/KratosSelfService/Views/Shared/Components/KratosUiTextMessages/Default.cshtml b/KratosSelfService/Views/Shared/Components/KratosUiTextMessages/Default.cshtml
new file mode 100644
index 0000000..bc4e092
--- /dev/null
+++ b/KratosSelfService/Views/Shared/Components/KratosUiTextMessages/Default.cshtml
@@ -0,0 +1,9 @@
+@model List?
+
+@if (Model != null)
+{
+ foreach (var message in Model)
+ {
+ @await Component.InvokeAsync("KratosUiTextMessage", message)
+ }
+}
\ No newline at end of file
diff --git a/KratosSelfService/Views/Verification/Verification.cshtml b/KratosSelfService/Views/Verification/Verification.cshtml
index 5940f29..29798a1 100644
--- a/KratosSelfService/Views/Verification/Verification.cshtml
+++ b/KratosSelfService/Views/Verification/Verification.cshtml
@@ -6,17 +6,8 @@
@OryTranslator.Get("verification.title")
-
\ No newline at end of file
+@await Component.InvokeAsync("KratosUiTextMessages", Model.flow.Ui.Messages)
+
+@await Component.InvokeAsync("KratosUi", new KratosUiModel(
+ Model.flow.Ui,
+ FlowType.Verification))
\ No newline at end of file