-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split EntranceController to separate controllers
- Loading branch information
Showing
15 changed files
with
199 additions
and
150 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using KratosSelfService.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Net.Http.Headers; | ||
using Ory.Kratos.Client.Client; | ||
using Ory.Kratos.Client.Model; | ||
|
||
namespace KratosSelfService.Controllers; | ||
|
||
public class LoginController(ILogger<LoginController> logger, ApiService api) : Controller | ||
{ | ||
[HttpGet("login")] | ||
public async Task<IActionResult> Login([FromQuery(Name = "flow")] string? flowId) | ||
{ | ||
if (flowId == null) | ||
{ | ||
// initiate flow | ||
var url = api.GetUrlForFlow("login"); | ||
return Redirect(url); | ||
} | ||
|
||
KratosLoginFlow flow; | ||
try | ||
{ | ||
flow = await api.Frontend.GetLoginFlowAsync(flowId, Request.Headers.Cookie); | ||
} | ||
catch (ApiException exception) | ||
{ | ||
logger.LogError(exception.Message); | ||
// restart flow | ||
return Redirect("login"); | ||
} | ||
|
||
if (flow.Ui.Messages?.Any(text => text.Id == 4000010) ?? false) | ||
// the login requires that the user verifies their email address before logging in | ||
// we will create a new verification flow and redirect the user to the verification page | ||
try | ||
{ | ||
var response = await api.Frontend | ||
.CreateBrowserVerificationFlowWithHttpInfoAsync(flow.ReturnTo); | ||
var verificationFlow = response.Data; | ||
// we need the csrf cookie from the verification flow | ||
Response.Headers.Add(HeaderNames.SetCookie, response.Headers[HeaderNames.SetCookie].ToString()); | ||
// encode the verification flow id in the query parameters | ||
var parameters = $"flow={verificationFlow.Id}&message={flow.Ui.Messages}"; | ||
|
||
var baseUrl = new Uri(Request.Path).Segments; | ||
//Navigation.NavigateTo(baseUrl); | ||
} | ||
catch (Exception exception) | ||
{ | ||
logger.LogError(exception.Message); | ||
// restart flow | ||
return Redirect("login"); | ||
} | ||
|
||
return View("Login", flow); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using KratosSelfService.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Net.Http.Headers; | ||
using Ory.Kratos.Client.Client; | ||
using Ory.Kratos.Client.Model; | ||
|
||
namespace KratosSelfService.Controllers; | ||
|
||
public class LogoutController(ILogger<LogoutController> logger, ApiService api) : Controller | ||
{ | ||
[HttpGet("logout")] | ||
public async Task<IActionResult> Logout() | ||
{ | ||
KratosLogoutFlow flow; | ||
try | ||
{ | ||
flow = await api.Frontend.CreateBrowserLogoutFlowAsync(Request.Headers.Cookie); | ||
} | ||
catch (ApiException exception) | ||
{ | ||
Console.WriteLine(exception.Message); | ||
throw; | ||
} | ||
|
||
return Redirect(flow.LogoutUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using KratosSelfService.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Net.Http.Headers; | ||
using Ory.Kratos.Client.Client; | ||
using Ory.Kratos.Client.Model; | ||
|
||
namespace KratosSelfService.Controllers; | ||
|
||
public class RecoveryController(ILogger<RecoveryController> logger, ApiService api) : Controller | ||
{ | ||
[HttpGet("recovery")] | ||
public async Task<IActionResult> Recovery([FromQuery(Name = "flow")] string? flowId) | ||
{ | ||
if (flowId == null) | ||
{ | ||
return Redirect(api.GetUrlForFlow("recovery")); | ||
} | ||
|
||
KratosRecoveryFlow flow; | ||
try | ||
{ | ||
flow = await api.Frontend.GetRecoveryFlowAsync(flowId, Request.Headers.Cookie); | ||
} | ||
catch (ApiException exception) | ||
{ | ||
logger.LogError(exception.Message); | ||
// restart flow | ||
return Redirect("recovery"); | ||
} | ||
|
||
return View("Recovery", flow); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using KratosSelfService.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Net.Http.Headers; | ||
using Ory.Kratos.Client.Client; | ||
using Ory.Kratos.Client.Model; | ||
|
||
namespace KratosSelfService.Controllers; | ||
|
||
public class RegistrationController(ILogger<RegistrationController> logger, ApiService api) : Controller | ||
{ | ||
[HttpGet("registration")] | ||
public async Task<IActionResult> Registration([FromQuery(Name = "flow")] string? flowId) | ||
{ | ||
if (flowId == null) | ||
{ | ||
// initiate flow | ||
var url = api.GetUrlForFlow("registration"); | ||
return Redirect(url); | ||
} | ||
|
||
KratosRegistrationFlow flow; | ||
try | ||
{ | ||
flow = await api.Frontend.GetRegistrationFlowAsync(flowId, Request.Headers.Cookie); | ||
} | ||
catch (ApiException exception) | ||
{ | ||
logger.LogError(exception.Message); | ||
// restart flow | ||
return Redirect("registration"); | ||
} | ||
|
||
return View("Registration", flow); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using KratosSelfService.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Net.Http.Headers; | ||
using Ory.Kratos.Client.Client; | ||
using Ory.Kratos.Client.Model; | ||
|
||
namespace KratosSelfService.Controllers; | ||
|
||
public class VerificationController(ILogger<VerificationController> logger, ApiService api) : Controller | ||
{ | ||
[HttpGet("verification")] | ||
public async Task<IActionResult> Verification([FromQuery(Name = "flow")] string? flowId) | ||
{ | ||
if (flowId == null) | ||
{ | ||
// initiate flow | ||
var url = api.GetUrlForFlow("verification"); | ||
return Redirect(url); | ||
} | ||
|
||
KratosVerificationFlow flow; | ||
try | ||
{ | ||
flow = await api.Frontend.GetVerificationFlowAsync(flowId, Request.Headers.Cookie); | ||
} | ||
catch (ApiException exception) | ||
{ | ||
Console.WriteLine(exception.Message); | ||
throw; | ||
} | ||
|
||
return View("Verification", flow); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.