Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Jan 10, 2024
1 parent 0ccc6d4 commit 133ddcd
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 54 deletions.
6 changes: 2 additions & 4 deletions KratosSelfService/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<IActionResult> Login(

Console.WriteLine(cookie);
}
if (Request.Headers.Cookie.Any(s => s.Contains("ory_kratos_session=")))
if (Request.Headers.Cookie.Any(s => s?.Contains("ory_kratos_session=") ?? false))
return Redirect("logout");
// initiate flow
return Redirect(GetInitFlowUrl(aal, refresh, returnTo, organization, loginChallenge));
Expand Down Expand Up @@ -122,16 +122,14 @@ private async Task<IActionResult> RedirectToVerificationFlow(KratosLoginFlow flo
.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());
Response.Headers.Append(HeaderNames.SetCookie, response.Headers[HeaderNames.SetCookie].ToString());
// encode the verification flow id in the query parameters
var paramDict = new Dictionary<string, string?>
{
["flow"] = verificationFlow.Id,
["message"] = flow.Ui.Messages.ToString()
};
var parameters = paramDict.EncodeQueryString();
var segments = new Uri(Request.Path).Segments;
var baseUrl = string.Join("/", segments[..^1]);

var url = $"{Request.PathBase}/verification?{parameters}";
return Redirect(url);
Expand Down
2 changes: 1 addition & 1 deletion KratosSelfService/Extensions/TraitsExt.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json.Linq;

namespace OryAdmin.Extensions;
namespace KratosSelfService.Extensions;

public static class TraitsExt
{
Expand Down
3 changes: 1 addition & 2 deletions KratosSelfService/OryElementsTranslator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Globalization;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json.Linq;
using Ory.Kratos.Client.Model;

Expand Down
6 changes: 3 additions & 3 deletions KratosSelfService/ViewComponents/KratosUiComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace KratosSelfService.ViewComponents;

public class KratosUiComponent : ViewComponent
{
public async Task<ViewViewComponentResult> InvokeAsync(KratosUiArgs args)
public Task<ViewViewComponentResult> InvokeAsync(KratosUiArgs args)
{
var nodeGroups = new Dictionary<KratosUiNode.GroupEnum, List<KratosUiNode>>();
foreach (var node in args.ui.Nodes)
Expand All @@ -22,11 +22,11 @@ public async Task<ViewViewComponentResult> InvokeAsync(KratosUiArgs args)
foreach (var hiddenGroup in args.hiddenGroups ?? [])
nodeGroups.Remove(hiddenGroup);

return View("Default", new KratosUiModel(
return Task.FromResult(View("Default", new KratosUiModel(
args.ui,
args.flowType,
nodeGroups,
defaultGroup,
args.forgotPasswordUrl));
args.forgotPasswordUrl)));
}
}
24 changes: 12 additions & 12 deletions KratosSelfService/ViewComponents/KratosUiNodeComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace KratosSelfService.ViewComponents;

public class KratosUiNodeComponent : ViewComponent
{
public async Task<ViewViewComponentResult> InvokeAsync(KratosUiNodeArgs args)
public Task<ViewViewComponentResult> InvokeAsync(KratosUiNodeArgs args)
{
switch (args.node.Type)
{
case KratosUiNode.TypeEnum.Text:
return View("Text", args);
return Task.FromResult(View("Text", args));
case KratosUiNode.TypeEnum.Input:
switch (args.node.Attributes.GetKratosUiNodeInputAttributes().Type)
{
Expand All @@ -25,29 +25,29 @@ public async Task<ViewViewComponentResult> InvokeAsync(KratosUiNodeArgs args)
case KratosUiNodeInputAttributes.TypeEnum.DatetimeLocal:
case KratosUiNodeInputAttributes.TypeEnum.Date:
case KratosUiNodeInputAttributes.TypeEnum.Url:
return View("InputField", args);
return Task.FromResult(View("InputField", args));
case KratosUiNodeInputAttributes.TypeEnum.Checkbox:
return View("InputCheckbox", args);
return Task.FromResult(View("InputCheckbox", args));
case KratosUiNodeInputAttributes.TypeEnum.Submit:
var inputAttr = args.node.Attributes.GetKratosUiNodeInputAttributes();
if (args.FlowType != FlowType.Settings
&& inputAttr.Type == KratosUiNodeInputAttributes.TypeEnum.Submit
&& inputAttr.Name == "provider")
return View("InputSubmitOidc", args);
return View("InputSubmit", args);
return Task.FromResult(View("InputSubmitOidc", args));
return Task.FromResult(View("InputSubmit", args));
case KratosUiNodeInputAttributes.TypeEnum.Button:
return View("InputButton", args);
return Task.FromResult(View("InputButton", args));
default:
return View("InputDefault", args);
return Task.FromResult(View("InputDefault", args));
}
case KratosUiNode.TypeEnum.Img:
return View("Image", args);
return Task.FromResult(View("Image", args));
case KratosUiNode.TypeEnum.A:
return View("Anchor", args);
return Task.FromResult(View("Anchor", args));
case KratosUiNode.TypeEnum.Script:
return View("Script", args);
return Task.FromResult(View("Script", args));
default:
return View("Default", args);
return Task.FromResult(View("Default", args));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace KratosSelfService.ViewComponents;

public class KratosUiTextMessageComponent(IOryElementsTranslator oryTranslator) : ViewComponent
{
public async Task<ViewViewComponentResult> InvokeAsync(KratosUiText uiText)
public Task<ViewViewComponentResult> InvokeAsync(KratosUiText uiText)
{
var content = oryTranslator.ForUiText(uiText);
var model = new KratosUiTextMessageModel(uiText, content!, GetCssClass(uiText.Type));
return View("Default", model);
return Task.FromResult(View("Default", model));
}

private static string GetCssClass(KratosUiText.TypeEnum type)
Expand Down
4 changes: 2 additions & 2 deletions KratosSelfService/ViewComponents/KratosUiTextMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace KratosSelfService.ViewComponents;

public class KratosUiTextMessages : ViewComponent
{
public async Task<ViewViewComponentResult> InvokeAsync(List<KratosUiText>? model)
public Task<ViewViewComponentResult> InvokeAsync(List<KratosUiText>? model)
{
return View("Default", model);
return Task.FromResult(View("Default", model));
}
}
2 changes: 1 addition & 1 deletion KratosSelfService/Views/Home/Profile.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@using Newtonsoft.Json.Linq
@using OryAdmin.Extensions
@using KratosSelfService.Extensions
@model ProfileModel
@{
ViewData["Title"] = CustomTranslator.Get("profile.title");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model KratosUiModel

@foreach (var (group, nodes) in Model.nodeGroups)
@foreach (var (_, nodes) in Model.nodeGroups)
{
<form class="mb-3" action="@Model.ui.Action" method="@Model.ui.Method">
@foreach (var node in Model.defaultGroup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

@{
var attributes = Model.node.Attributes.GetKratosUiNodeInputAttributes();
var uiText = attributes.Label ?? Model.node.Meta.Label;
}

<div class="column is-half">
Expand Down
3 changes: 1 addition & 2 deletions OryAdmin/Components/Pages/Identities/Messages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@page "/identities/messages"
@rendermode InteractiveServer
@inject NavigationManager nav

<PageTitle>Message Log | OryAdmin</PageTitle>

Expand Down Expand Up @@ -28,7 +27,7 @@ else
</tr>
</thead>
<tbody>
@foreach (var message in _messages!)
@foreach (var message in _messages)
{
<tr>
<td>
Expand Down
9 changes: 1 addition & 8 deletions OryAdmin/Components/Pages/Identities/Messages/Index.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Ory.Kratos.Client.Model;
using OryAdmin.Services;

Expand All @@ -8,13 +7,12 @@ namespace OryAdmin.Components.Pages.Identities.Messages;
public partial class Index : ComponentBase
{
private bool _isLoading = true;
private List<KratosMessage> _messages;
private List<KratosMessage>? _messages;

[SupplyParameterFromQuery(Name = "page")]
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
private int PageNr { get; set; } = 1;

[Inject] private IdentitySchemaService SchemaService { get; set; } = default!;
[Inject] private ApiService ApiService { get; set; } = default!;

protected override async Task OnInitializedAsync()
Expand All @@ -24,9 +22,4 @@ protected override async Task OnInitializedAsync()

_isLoading = false;
}

private void RefreshPage(MouseEventArgs arg)
{
nav.Refresh(true);
}
}
3 changes: 1 addition & 2 deletions OryAdmin/Components/Pages/Identities/Schemas/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public partial class Index
private string? SchemaId { get; set; }

[Inject] private ApiService ApiService { get; set; } = default!;
[Inject] private IdentitySchemaService SchemaService { get; set; } = default!;

protected override async Task OnInitializedAsync()
{
Expand All @@ -33,6 +32,6 @@ protected override async Task OnInitializedAsync()

protected override void OnParametersSet()
{
_selectedSchema = _schemas?.First(schema => schema.Id == SchemaId);
_selectedSchema = _schemas?.FirstOrDefault(schema => schema.Id == SchemaId);
}
}
9 changes: 0 additions & 9 deletions OryAdmin/Components/Pages/Identities/Users/Edit.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ protected override async Task OnInitializedAsync()
_isLoading = false;
}

private void Cancel()
{
nav.NavigateTo($"identities/users/{UserId}");
}

private async Task SubmitForm()
{
var updateBody = new KratosUpdateIdentityBody(traits: _json, schemaId: _identity!.SchemaId);
Expand All @@ -46,8 +41,4 @@ private async Task SubmitForm()

nav.NavigateTo($"identities/users/{UserId}");
}

private void UpdateValue(JSchema schema, ChangeEventArgs args)
{
}
}
1 change: 0 additions & 1 deletion OryAdmin/Components/Pages/Identities/Users/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public partial class Index
// ReSharper disable once UnusedAutoPropertyAccessor.Local
private int PageNr { get; set; }

[Inject] private IdentitySchemaService SchemaService { get; set; } = default!;
[Inject] private ApiService ApiService { get; set; } = default!;

protected override async Task OnInitializedAsync()
Expand Down
1 change: 0 additions & 1 deletion OryAdmin/Components/Pages/Identities/Users/Sessions.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@page "/identities/users/{UserId}/sessions"
@using UAParser
@rendermode InteractiveServer
@inject NavigationManager nav

<PageTitle>View Identity | OryAdmin</PageTitle>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public partial class Sessions
private bool _showDeleteSessionsModal;
[Parameter] public string? UserId { get; set; }
[Inject] private ApiService ApiService { get; set; } = default!;
[Inject] private EnvService EnvService { get; set; } = default!;

protected override async Task OnInitializedAsync()
{
Expand Down
1 change: 0 additions & 1 deletion OryAdmin/Components/Pages/OAuth2/Clients/Create.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@page "/oauth2/clients/create"
@rendermode InteractiveServer
@inject NavigationManager nav

<PageTitle>Create Client | OryAdmin</PageTitle>

Expand Down

0 comments on commit 133ddcd

Please sign in to comment.