Update registration
This commit is contained in:
@ -3,8 +3,7 @@
|
||||
@implements IDisposable
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<RadzenComponents @rendermode="InteractiveServer" />
|
||||
@inject NotificationService NotificationService
|
||||
|
||||
<RadzenLayout Style="grid-template-areas: 'rz-sidebar rz-header' 'rz-sidebar rz-body'">
|
||||
<RadzenHeader>
|
||||
@ -25,11 +24,7 @@
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<RadzenPanelMenuItem Text="@context.User.Identity?.Name" />
|
||||
<RadzenPanelMenuItem Path="javascript:document.forms['logout'].submit();" Text="Выйти" Icon="logout" />
|
||||
<form action="account/logout" method="post" name="logout">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="ReturnUrl" value="@currentUrl" />
|
||||
</form>
|
||||
<RadzenPanelMenuItem Path="/identity/logout" Text="Выйти" Icon="logout" />
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<RadzenPanelMenuItem Path="/account/register" Text="Регистрация" Icon="person_add" />
|
||||
@ -40,6 +35,7 @@
|
||||
</RadzenStack>
|
||||
</RadzenSidebar>
|
||||
<RadzenBody>
|
||||
<RadzenNotification Style="position: absolute;top: 0; right: 0;" />
|
||||
@Body
|
||||
<div id="blazor-error-ui">
|
||||
Произошла непредвиденная ошибка
|
||||
@ -69,6 +65,8 @@
|
||||
{
|
||||
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
|
||||
|
||||
NotificationService.Messages.Clear();
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,13 @@
|
||||
@page "/account/register"
|
||||
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Hcs.WebApp.Data
|
||||
@using Hcs.WebApp.Identity
|
||||
|
||||
@inject IUserStore<AppUser> UserStore
|
||||
@inject UserManager<AppUser> UserManager
|
||||
@inject NotificationService NotificationService
|
||||
@inject SignInManager<AppUser> SignInManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Регистрация аккаунта</PageTitle>
|
||||
|
||||
<RadzenCard class="rz-mx-auto" Style="max-width: 420px">
|
||||
<RadzenTemplateForm TItem="InputModel" Data=@Input Method="post" Submit=@OnSubmit>
|
||||
<RadzenTemplateForm TItem="InputModel" Data=@Input Method="post" Action="@($"identity/register?returnUrl={ReturnUrl}")">
|
||||
<RadzenStack Gap="1rem" class="rz-p-sm-12">
|
||||
<RadzenText TextStyle="TextStyle.H4" TextAlign="TextAlign.Center">Регистрация</RadzenText>
|
||||
<RadzenText TextStyle="TextStyle.H5" TextAlign="TextAlign.Center">Регистрация</RadzenText>
|
||||
<RadzenFormField Text="Логин" Variant="Variant.Outlined">
|
||||
<ChildContent>
|
||||
<RadzenTextBox Name="UserName" @bind-Value=@Input.UserName AutoCompleteType="AutoCompleteType.Username" />
|
||||
@ -42,7 +34,7 @@
|
||||
</ChildContent>
|
||||
<Helper>
|
||||
<RadzenRequiredValidator Component="ConfirmPassword" Text="Поле 'Пароль' обязательно к заполнению" />
|
||||
<RadzenCompareValidator Visible=@(!string.IsNullOrEmpty(Input.ConfirmPassword)) Value=@Input.Password Component="ConfirmPassword" Text="Пароли должны совпадать" />
|
||||
<RadzenCompareValidator Value=@Input.Password Component="ConfirmPassword" Text="Пароли должны совпадать" />
|
||||
</Helper>
|
||||
</RadzenFormField>
|
||||
<RadzenButton ButtonType="ButtonType.Submit" Text="Зарегистрировать"></RadzenButton>
|
||||
@ -63,28 +55,28 @@
|
||||
[SupplyParameterFromForm]
|
||||
InputModel Input { get; set; } = new();
|
||||
|
||||
[SupplyParameterFromQuery]
|
||||
string? Errors { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery]
|
||||
string? ReturnUrl { get; set; }
|
||||
|
||||
async Task OnSubmit(InputModel mode)
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
var user = Activator.CreateInstance<AppUser>();
|
||||
await UserStore.SetUserNameAsync(user, Input.UserName, CancellationToken.None);
|
||||
base.OnAfterRender(firstRender);
|
||||
|
||||
var result = await UserManager.CreateAsync(user, Input.Password);
|
||||
if (!result.Succeeded)
|
||||
if (firstRender)
|
||||
{
|
||||
NotificationService.Notify(new NotificationMessage()
|
||||
if (!string.IsNullOrEmpty(Errors))
|
||||
{
|
||||
Severity = NotificationSeverity.Error,
|
||||
Summary = "Ошибка",
|
||||
Detail = string.Join(", ", result.Errors.Select(error => error.Description))
|
||||
});
|
||||
return;
|
||||
NotificationService.Notify(new NotificationMessage()
|
||||
{
|
||||
Severity = NotificationSeverity.Error,
|
||||
Summary = "Ошибка",
|
||||
Detail = Errors,
|
||||
Duration = -1d
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await SignInManager.SignInAsync(user, isPersistent: false);
|
||||
|
||||
RedirectManager.RedirectTo(ReturnUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
@page "/test/export"
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Hcs.Broker
|
||||
@using Hcs.Broker.Logger
|
||||
@using Hcs.Broker.MessageCapturer
|
||||
@using Hcs.Service.Async.Nsi
|
||||
@using Hcs.WebApp.Config
|
||||
@using Hcs.WebApp.Utils
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http.Json
|
||||
@using Hcs.WebApp
|
||||
@using Hcs.WebApp.Components
|
||||
@using Hcs.WebApp.Components.Shared
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@ -8,8 +11,5 @@
|
||||
@using Microsoft.JSInterop
|
||||
@using Radzen
|
||||
@using Radzen.Blazor
|
||||
@using Hcs.WebApp
|
||||
@using Hcs.WebApp.Components
|
||||
@using Hcs.WebApp.Components.Shared
|
||||
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
|
||||
Reference in New Issue
Block a user