-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Open
Feature
Copy link
Labels
Pillar: Complete Blazor WebPriority:1Work that is critical for the release, but we could probably ship withoutWork that is critical for the release, but we could probably ship withoutarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing one
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
I need to work with page in interactive mode, and after that submit to handle it with access to HttpContext.
I expect that model will be filled by [SupplyParameterFromForm] RegisterInputModel Model
after i submit form with javascript interop and invoke a function submit()
.
But in Server interactive mode the hidden value <input type="hidden" name="_handler" value="{FormName}" />
is removed.
My temporary working soution is:
<EditForm Model="Input" method="post" OnValidSubmit="LoginUser" FormName="login">
@if(HttpContext == null)
{
<input type="hidden" name="_handler" value="login" />
}
@* form code and markup *@
<div class="buttons">
<BButton Class="is-solid primary-button is-fullwidth raised" Type="submit">Login</BButton>
</div>
</EditForm>
@code {
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
[SupplyParameterFromForm]
private LoginInputModel Input { get; set; } = new();
[SupplyParameterFromQuery]
private string? ReturnUrl { get; set; }
protected override async Task OnInitializedAsync()
{
if (HttpContext != null && HttpMethods.IsGet(HttpContext.Request.Method))
{
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
}
}
public async Task LoginUser()
{
if(HttpContext == null)
{
// interactive logic
var ref1 = await Js.InvokeAsync<IJSObjectReference>("document.getElementById", "login-form");
await ref1.InvokeVoidAsync("parentNode.submit");
return;
}
// server submit logic
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
Logger.LogInformation("User logged in.");
RedirectManager.RedirectTo(ReturnUrl);
}
else if (result.RequiresTwoFactor)
{
RedirectManager.RedirectTo(
"Account/LoginWith2fa",
new() { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe });
}
else if (result.IsLockedOut)
{
Logger.LogWarning("User account locked out.");
RedirectManager.RedirectTo("Account/Lockout");
}else
{
AppStore.State.NotAuthorizedModel = new () { Message = "Other error" };
}
}
}
Describe the solution you'd like
solution 1: Do not remove hidden field _handler
with FormName
value and in interactive mode.
solution 2: Provide some API in EditContext
to call submit with reload page.
Additional context
Sorry for my English...
Dryvnt, jcob-ross, flatproject, boukenka, likquietlyy and 5 more
Metadata
Metadata
Assignees
Labels
Pillar: Complete Blazor WebPriority:1Work that is critical for the release, but we could probably ship withoutWork that is critical for the release, but we could probably ship withoutarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing one