Skip to content

Commit

Permalink
port recovery flow, create logout view
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Oct 22, 2023
1 parent d64c3e2 commit 169d78e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
26 changes: 22 additions & 4 deletions KratosSelfService/Controllers/RecoveryController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using KratosSelfService.Models;
using KratosSelfService.Services;
using Microsoft.AspNetCore.Mvc;
using Ory.Kratos.Client.Client;
Expand All @@ -8,9 +9,18 @@ namespace KratosSelfService.Controllers;
public class RecoveryController(ILogger<RecoveryController> logger, ApiService api) : Controller
{
[HttpGet("recovery")]
public async Task<IActionResult> Recovery([FromQuery(Name = "flow")] string? flowId)
public async Task<IActionResult> 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<string, string?>()
{
["return_to"] = returnTo
}));
}

KratosRecoveryFlow flow;
try
Expand All @@ -21,9 +31,17 @@ public async Task<IActionResult> Recovery([FromQuery(Name = "flow")] string? flo
{
logger.LogError(exception.Message);
// restart flow
return Redirect("recovery");
return Redirect(api.GetUrlForBrowserFlow("recovery", new Dictionary<string, string?>()
{
["return_to"] = returnTo
}));
}

return View("Recovery", flow);
var loginUrl = api.GetUrlForBrowserFlow("login", new Dictionary<string, string?>()
{
["return_to"] = returnTo
});
var model = new RecoveryModel(flow, loginUrl);
return View("Recovery", model);
}
}
7 changes: 1 addition & 6 deletions KratosSelfService/KratosSelfService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@

<ItemGroup>
<AdditionalFiles Include="Views\Login\Login.cshtml" />
<AdditionalFiles Include="Views\Login\Recovery.cshtml" />
<AdditionalFiles Include="Views\Login\Registration.cshtml" />
<AdditionalFiles Include="Views\Recovery\Login.cshtml" />
<AdditionalFiles Include="Views\Logout\Logout.cshtml" />
<AdditionalFiles Include="Views\Recovery\Recovery.cshtml" />
<AdditionalFiles Include="Views\Recovery\Registration.cshtml" />
<AdditionalFiles Include="Views\Registration\Login.cshtml" />
<AdditionalFiles Include="Views\Registration\Recovery.cshtml" />
<AdditionalFiles Include="Views\Registration\Registration.cshtml" />
<AdditionalFiles Include="Views\Verification\Verification.cshtml" />
<AdditionalFiles Include="Views\Settings\Settings.cshtml"/>
Expand Down
4 changes: 1 addition & 3 deletions KratosSelfService/Models/models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions KratosSelfService/Views/Logout/Logout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@model LogoutModel
@{
ViewData["Title"] = OryTranslator.Get("logout.title");
Layout = "_CardLayout";
}

<h1 class="title">@OryTranslator.Get("logout.title")</h1>
<div class="buttons mt-5 is-fullwidth">
<a class="button is-dark" href="/">
@CustomTranslator.Get("logout.reject-button")
</a>
<a class="button is-warning" href="@Model.flow.LogoutUrl">
@CustomTranslator.Get("logout.accept-button")
</a>
</div>
12 changes: 6 additions & 6 deletions KratosSelfService/Views/Recovery/Recovery.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model KratosRecoveryFlow
@model RecoveryModel
@{
ViewData["Title"] = OryTranslator.Get("recovery.title");
Layout = "_CardLayout";
Expand All @@ -7,20 +7,20 @@
<h1 class="title has-text-centered">@OryTranslator.Get("recovery.title")</h1>
<p class="has-text-centered">
@OryTranslator.Get("recovery.login-label")
<a href="login">
<a href="@Model.loginUrl">
@OryTranslator.Get("recovery.login-button")
</a>
</p>
<hr/>
<form method="@Model.Ui.Method.ToLower()" action="@Model.Ui.Action">
@if (Model.Ui.Messages != null)
<form method="@Model.flow.Ui.Method.ToLower()" action="@Model.flow.Ui.Action">
@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)
Expand Down

0 comments on commit 169d78e

Please sign in to comment.