From f8a22a2b810d91c0d0b2e0c6875f54a5c0dedeab Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Thu, 19 Oct 2023 01:25:50 +0200 Subject: [PATCH] fix self service settings form post url --- KratosSelfService/Controllers/SettingsController.cs | 6 ++++-- KratosSelfService/Models/SettingsModel.cs | 5 +++++ KratosSelfService/Services/ApiService.cs | 6 ++++++ KratosSelfService/Views/Settings/Settings.cshtml | 11 ++++++----- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 KratosSelfService/Models/SettingsModel.cs diff --git a/KratosSelfService/Controllers/SettingsController.cs b/KratosSelfService/Controllers/SettingsController.cs index 8dde68c..35068a9 100644 --- a/KratosSelfService/Controllers/SettingsController.cs +++ b/KratosSelfService/Controllers/SettingsController.cs @@ -1,4 +1,5 @@ -using KratosSelfService.Services; +using KratosSelfService.Models; +using KratosSelfService.Services; using Microsoft.AspNetCore.Mvc; namespace KratosSelfService.Controllers; @@ -16,6 +17,7 @@ public async Task Settings([FromQuery(Name = "flow")] string? flo } var flow = await api.Frontend.GetSettingsFlowAsync(flowId, cookie: Request.Headers.Cookie); - return View("Settings", flow); + var model = new SettingsModel(flow, api.GetSettingsUrl(flow.Id)); + return View("Settings", model); } } \ No newline at end of file diff --git a/KratosSelfService/Models/SettingsModel.cs b/KratosSelfService/Models/SettingsModel.cs new file mode 100644 index 0000000..b7e9025 --- /dev/null +++ b/KratosSelfService/Models/SettingsModel.cs @@ -0,0 +1,5 @@ +using Ory.Kratos.Client.Model; + +namespace KratosSelfService.Models; + +public record SettingsModel(KratosSettingsFlow flow, string postUri); \ No newline at end of file diff --git a/KratosSelfService/Services/ApiService.cs b/KratosSelfService/Services/ApiService.cs index ce324e2..654a343 100644 --- a/KratosSelfService/Services/ApiService.cs +++ b/KratosSelfService/Services/ApiService.cs @@ -22,4 +22,10 @@ public string GetUrlForFlow(string flow, Dictionary? query = nul var baseUrl = env.KratosBrowserUrl ?? env.KratosPublicUrl; return $"{baseUrl.RemoveTrailingSlash()}/self-service/{flow}/browser?{queryString}"; } + + public string GetSettingsUrl(string flowId) + { + var baseUrl = env.KratosBrowserUrl ?? env.KratosPublicUrl; + return $"{baseUrl.RemoveTrailingSlash()}/self-service/settings?flow={flowId}"; + } } \ No newline at end of file diff --git a/KratosSelfService/Views/Settings/Settings.cshtml b/KratosSelfService/Views/Settings/Settings.cshtml index a828a39..d3efba4 100644 --- a/KratosSelfService/Views/Settings/Settings.cshtml +++ b/KratosSelfService/Views/Settings/Settings.cshtml @@ -1,10 +1,11 @@ @inject ICustomTranslator Translator @using KratosSelfService.Extensions -@model KratosSettingsFlow +@using KratosSelfService.Services +@model SettingsModel @{ ViewData["Title"] = Translator.GetTranslation("Account Settings"); Layout = "_CardLayout"; - var allGroups = Model.Ui.Nodes + var allGroups = Model.flow.Ui.Nodes .GroupBy(node => node.Group).ToList(); var defaultNodes = allGroups .First(group => group.Key == KratosUiNode.GroupEnum.Default) @@ -15,9 +16,9 @@

@Translator.GetTranslation("Account Settings")

- @if (Model.Ui.Messages != null) + @if (Model.flow.Ui.Messages != null) { - foreach (var message in Model.Ui.Messages) + foreach (var message in Model.flow.Ui.Messages) { @await Component.InvokeAsync("KratosUiTextMessage", message) } @@ -26,7 +27,7 @@ {

@group.Key.ToLocalString(Translator)

-
+ @foreach (var node in defaultNodes) { @await Component.InvokeAsync("KratosUiNodeInput", node)