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 @@


-
-
- @if (Model.flow.Ui.Messages != null) - { - foreach (var message in Model.flow.Ui.Messages) - { - @await Component.InvokeAsync("KratosUiTextMessage", message) - } - } - @foreach (var node in Model.flow.Ui.Nodes) +
+ @await Component.InvokeAsync("KratosUiTextMessages", Model.flow.Ui.Messages) + + @await Component.InvokeAsync("KratosUi", new KratosUiModel( + Model.flow.Ui, + FlowType.Login, + Model.forgotPasswordUrl)) +
+ + - \ No newline at end of file +
--> \ No newline at end of file diff --git a/KratosSelfService/Views/Recovery/Recovery.cshtml b/KratosSelfService/Views/Recovery/Recovery.cshtml index 2855fa5..71ce9da 100644 --- a/KratosSelfService/Views/Recovery/Recovery.cshtml +++ b/KratosSelfService/Views/Recovery/Recovery.cshtml @@ -12,17 +12,8 @@


-
- @if (Model.flow.Ui.Messages != null) - { - foreach (var message in Model.flow.Ui.Messages) - { - @await Component.InvokeAsync("KratosUiTextMessage", message) - } - } - @foreach (var node in Model.flow.Ui.Nodes) - { - var model = new KratosUiNodeModel(node, FlowType.Recovery); - @await Component.InvokeAsync("KratosUiNodeInput", model) - } -
\ 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 @@


-
-
- @if (Model.flow.Ui.Messages != null) +
+ @await Component.InvokeAsync("KratosUiTextMessages", Model.flow.Ui.Messages) + + @await Component.InvokeAsync("KratosUi", new KratosUiModel( + Model.flow.Ui, + FlowType.Registration)) +
+ - \ No newline at end of file +
--> \ No newline at end of file diff --git a/KratosSelfService/Views/Settings/Settings.cshtml b/KratosSelfService/Views/Settings/Settings.cshtml index 17f1808..a116d65 100644 --- a/KratosSelfService/Views/Settings/Settings.cshtml +++ b/KratosSelfService/Views/Settings/Settings.cshtml @@ -63,13 +63,7 @@ @OryTranslator.Get("settings.subtitle-instructions") } - @if (Model.flow.Ui.Messages != null) - { - foreach (var message in Model.flow.Ui.Messages) - { - @await Component.InvokeAsync("KratosUiTextMessage", message) - } - } + @await Component.InvokeAsync("KratosUiTextMessages", Model.flow.Ui.Messages) @foreach (var group in groups) { diff --git a/KratosSelfService/Views/Shared/Components/KratosUi/Default.cshtml b/KratosSelfService/Views/Shared/Components/KratosUi/Default.cshtml new file mode 100644 index 0000000..6536bca --- /dev/null +++ b/KratosSelfService/Views/Shared/Components/KratosUi/Default.cshtml @@ -0,0 +1,30 @@ +@model KratosUiModel + +@{ + // this component is used by all flows except the settings flow + + var allGroups = Model.ui.Nodes + .GroupBy(node => node.Group).ToList(); + var defaultNodes = allGroups + .First(group => group.Key == KratosUiNode.GroupEnum.Default) + .ToArray(); + var groups = allGroups + .Where(group => group.Key != KratosUiNode.GroupEnum.Default) + .ToArray(); +} + +@foreach (var group in groups) +{ +
+ @foreach (var node in defaultNodes) + { + var model = new KratosUiNodeModel(node, Model.flowType, Model.forgotPasswordUrl); + @await Component.InvokeAsync("KratosUiNodeInput", model) + } + @foreach (var node in group) + { + var model = new KratosUiNodeModel(node, Model.flowType, Model.forgotPasswordUrl); + @await Component.InvokeAsync("KratosUiNodeInput", model) + } +
+} \ 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")


-
- @if (Model.flow.Ui.Messages != null) - { - foreach (var message in Model.flow.Ui.Messages) - { - @await Component.InvokeAsync("KratosUiTextMessage", message) - } - } - @foreach (var node in Model.flow.Ui.Nodes) - { - var model = new KratosUiNodeModel(node, FlowType.Verification); - @await Component.InvokeAsync("KratosUiNodeInput", model) - } -
\ 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