diff --git a/KratosSelfService/Controllers/RecoveryController.cs b/KratosSelfService/Controllers/RecoveryController.cs index 99a9f03..4ca6617 100644 --- a/KratosSelfService/Controllers/RecoveryController.cs +++ b/KratosSelfService/Controllers/RecoveryController.cs @@ -1,3 +1,4 @@ +using KratosSelfService.Models; using KratosSelfService.Services; using Microsoft.AspNetCore.Mvc; using Ory.Kratos.Client.Client; @@ -8,9 +9,18 @@ namespace KratosSelfService.Controllers; public class RecoveryController(ILogger logger, ApiService api) : Controller { [HttpGet("recovery")] - public async Task Recovery([FromQuery(Name = "flow")] string? flowId) + public async Task Recovery( + [FromQuery(Name = "flow")] string? flowId, + [FromQuery(Name = "return_to")] string? returnTo) { - if (flowId == null) return Redirect(api.GetUrlForBrowserFlow("recovery")); + if (flowId == null) + { + logger.LogDebug("No flow ID found in URL query initializing login flow"); + return Redirect(api.GetUrlForBrowserFlow("recovery", new Dictionary() + { + ["return_to"] = returnTo + })); + } KratosRecoveryFlow flow; try @@ -21,9 +31,17 @@ public async Task Recovery([FromQuery(Name = "flow")] string? flo { logger.LogError(exception.Message); // restart flow - return Redirect("recovery"); + return Redirect(api.GetUrlForBrowserFlow("recovery", new Dictionary() + { + ["return_to"] = returnTo + })); } - return View("Recovery", flow); + var loginUrl = api.GetUrlForBrowserFlow("login", new Dictionary() + { + ["return_to"] = returnTo + }); + var model = new RecoveryModel(flow, loginUrl); + return View("Recovery", model); } } \ No newline at end of file diff --git a/KratosSelfService/KratosSelfService.csproj b/KratosSelfService/KratosSelfService.csproj index f80ef71..f96b8b2 100644 --- a/KratosSelfService/KratosSelfService.csproj +++ b/KratosSelfService/KratosSelfService.csproj @@ -72,13 +72,8 @@ - - - + - - - diff --git a/KratosSelfService/Models/models.cs b/KratosSelfService/Models/models.cs index 215e56a..633c252 100644 --- a/KratosSelfService/Models/models.cs +++ b/KratosSelfService/Models/models.cs @@ -17,9 +17,7 @@ public record LogoutModel( KratosLogoutFlow flow ); -public record RecoveryModel( - KratosRecoveryFlow flow -); +public record RecoveryModel(KratosRecoveryFlow flow, string loginUrl); public record RegistrationModel( KratosRegistrationFlow flow diff --git a/KratosSelfService/Views/Logout/Logout.cshtml b/KratosSelfService/Views/Logout/Logout.cshtml new file mode 100644 index 0000000..6d909b8 --- /dev/null +++ b/KratosSelfService/Views/Logout/Logout.cshtml @@ -0,0 +1,15 @@ +@model LogoutModel +@{ + ViewData["Title"] = OryTranslator.Get("logout.title"); + Layout = "_CardLayout"; +} + +

@OryTranslator.Get("logout.title")

+ \ No newline at end of file diff --git a/KratosSelfService/Views/Recovery/Recovery.cshtml b/KratosSelfService/Views/Recovery/Recovery.cshtml index edc5270..1c490ad 100644 --- a/KratosSelfService/Views/Recovery/Recovery.cshtml +++ b/KratosSelfService/Views/Recovery/Recovery.cshtml @@ -1,4 +1,4 @@ -@model KratosRecoveryFlow +@model RecoveryModel @{ ViewData["Title"] = OryTranslator.Get("recovery.title"); Layout = "_CardLayout"; @@ -7,20 +7,20 @@

@OryTranslator.Get("recovery.title")

@OryTranslator.Get("recovery.login-label") - + @OryTranslator.Get("recovery.login-button")


-
- @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) } } - @foreach (var node in Model.Ui.Nodes) + @foreach (var node in Model.flow.Ui.Nodes) { var model = new KratosUiNodeModel(node); @await Component.InvokeAsync("KratosUiNodeInput", model)