Skip to content

Commit

Permalink
fix self service settings form post url
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Oct 18, 2023
1 parent 48cb9b2 commit f8a22a2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 4 additions & 2 deletions KratosSelfService/Controllers/SettingsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KratosSelfService.Services;
using KratosSelfService.Models;
using KratosSelfService.Services;
using Microsoft.AspNetCore.Mvc;

namespace KratosSelfService.Controllers;
Expand All @@ -16,6 +17,7 @@ public async Task<IActionResult> 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);
}
}
5 changes: 5 additions & 0 deletions KratosSelfService/Models/SettingsModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Ory.Kratos.Client.Model;

namespace KratosSelfService.Models;

public record SettingsModel(KratosSettingsFlow flow, string postUri);
6 changes: 6 additions & 0 deletions KratosSelfService/Services/ApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public string GetUrlForFlow(string flow, Dictionary<string, string>? 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}";
}
}
11 changes: 6 additions & 5 deletions KratosSelfService/Views/Settings/Settings.cshtml
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -15,9 +16,9 @@

<section class="section">
<h1 class="title">@Translator.GetTranslation("Account Settings")</h1>
@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)
}
Expand All @@ -26,7 +27,7 @@
{
<hr/>
<h3 class="subtitle mt-3">@group.Key.ToLocalString(Translator)</h3>
<form class="mb-3" action="@Model.ReturnTo" method="post">
<form class="mb-3" action="@Model.postUri" method="post">
@foreach (var node in defaultNodes)
{
@await Component.InvokeAsync("KratosUiNodeInput", node)
Expand Down

0 comments on commit f8a22a2

Please sign in to comment.