Add registration form first iteration
This commit is contained in:
@ -16,9 +16,9 @@
|
|||||||
<RadzenSidebar @bind-Expanded="@sidebarExpanded">
|
<RadzenSidebar @bind-Expanded="@sidebarExpanded">
|
||||||
<RadzenStack Style="height: 100%" JustifyContent="JustifyContent.SpaceBetween">
|
<RadzenStack Style="height: 100%" JustifyContent="JustifyContent.SpaceBetween">
|
||||||
<RadzenPanelMenu>
|
<RadzenPanelMenu>
|
||||||
<RadzenPanelMenuItem Click="@(() => NavigationManager.NavigateTo("/"))" Text="Главная" Icon="home" />
|
<RadzenPanelMenuItem Path="/" Text="Главная" Icon="home" />
|
||||||
<RadzenPanelMenuItem Text="Тестирование" Icon="simulation">
|
<RadzenPanelMenuItem Text="Тестирование" Icon="simulation">
|
||||||
<RadzenPanelMenuItem Click="@(() => NavigationManager.NavigateTo("/test/export"))" Text="Экспорт" Icon="arrow_outward" />
|
<RadzenPanelMenuItem Path="/test/export" Text="Экспорт" Icon="arrow_outward" />
|
||||||
</RadzenPanelMenuItem>
|
</RadzenPanelMenuItem>
|
||||||
</RadzenPanelMenu>
|
</RadzenPanelMenu>
|
||||||
<RadzenPanelMenu>
|
<RadzenPanelMenu>
|
||||||
@ -32,8 +32,8 @@
|
|||||||
</form>
|
</form>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
<RadzenPanelMenuItem Click="@(() => NavigationManager.NavigateTo("/account/register"))" Text="Регистрация" Icon="person_add" />
|
<RadzenPanelMenuItem Path="/account/register" Text="Регистрация" Icon="person_add" />
|
||||||
<RadzenPanelMenuItem Click="@(() => NavigationManager.NavigateTo("/account/login"))" Text="Вход" Icon="login" />
|
<RadzenPanelMenuItem Path="/account/login" Text="Вход" Icon="login" />
|
||||||
</NotAuthorized>
|
</NotAuthorized>
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
</RadzenPanelMenu>
|
</RadzenPanelMenu>
|
||||||
@ -41,7 +41,6 @@
|
|||||||
</RadzenSidebar>
|
</RadzenSidebar>
|
||||||
<RadzenBody>
|
<RadzenBody>
|
||||||
@Body
|
@Body
|
||||||
|
|
||||||
<div id="blazor-error-ui">
|
<div id="blazor-error-ui">
|
||||||
Произошла непредвиденная ошибка
|
Произошла непредвиденная ошибка
|
||||||
<a href="" class="reload">Перезагрузить</a>
|
<a href="" class="reload">Перезагрузить</a>
|
||||||
|
|||||||
90
Hcs.WebApp/Components/Pages/Account/Register.razor
Normal file
90
Hcs.WebApp/Components/Pages/Account/Register.razor
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
@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>
|
||||||
|
<RadzenStack Gap="1rem" class="rz-p-sm-12">
|
||||||
|
<RadzenText TextStyle="TextStyle.H4" TextAlign="TextAlign.Center">Регистрация</RadzenText>
|
||||||
|
<RadzenFormField Text="Логин" Variant="Variant.Outlined">
|
||||||
|
<ChildContent>
|
||||||
|
<RadzenTextBox Name="UserName" @bind-Value=@Input.UserName AutoCompleteType="AutoCompleteType.Username" />
|
||||||
|
</ChildContent>
|
||||||
|
<Helper>
|
||||||
|
<RadzenRequiredValidator Component="UserName" Text="Поле 'Логин' обязательно к заполнению" />
|
||||||
|
<RadzenLengthValidator Component="UserName" Min="6" Text="Длина поля 'Логин' должна быть не меньше 6" />
|
||||||
|
<RadzenLengthValidator Component="UserName" Max="30" Text="Длина поля 'Логин' должна быть не больше 30" />
|
||||||
|
</Helper>
|
||||||
|
</RadzenFormField>
|
||||||
|
<RadzenFormField Text="Пароль" Variant="Variant.Outlined">
|
||||||
|
<ChildContent>
|
||||||
|
<RadzenPassword Name="Password" @bind-Value=@Input.Password AutoCompleteType="AutoCompleteType.NewPassword" />
|
||||||
|
</ChildContent>
|
||||||
|
<Helper>
|
||||||
|
<RadzenRequiredValidator Component="Password" Text="Поле 'Пароль' обязательно к заполнению" />
|
||||||
|
<RadzenLengthValidator Component="Password" Min="6" Text="Длина поля 'Пароль' должна быть не меньше 6" />
|
||||||
|
<RadzenLengthValidator Component="Password" Max="100" Text="Длина поля 'Пароль' должна быть не больше 100" />
|
||||||
|
</Helper>
|
||||||
|
</RadzenFormField>
|
||||||
|
<RadzenFormField Text="Повторите пароль" Variant="Variant.Outlined">
|
||||||
|
<ChildContent>
|
||||||
|
<RadzenPassword Name="ConfirmPassword" @bind-Value=@Input.ConfirmPassword AutoCompleteType="AutoCompleteType.NewPassword" />
|
||||||
|
</ChildContent>
|
||||||
|
<Helper>
|
||||||
|
<RadzenRequiredValidator Component="ConfirmPassword" Text="Поле 'Пароль' обязательно к заполнению" />
|
||||||
|
<RadzenCompareValidator Visible=@(!string.IsNullOrEmpty(Input.ConfirmPassword)) Value=@Input.Password Component="ConfirmPassword" Text="Пароли должны совпадать" />
|
||||||
|
</Helper>
|
||||||
|
</RadzenFormField>
|
||||||
|
<RadzenButton ButtonType="ButtonType.Submit" Text="Зарегистрировать"></RadzenButton>
|
||||||
|
</RadzenStack>
|
||||||
|
</RadzenTemplateForm>
|
||||||
|
</RadzenCard>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
sealed class InputModel
|
||||||
|
{
|
||||||
|
public string UserName { get; set; } = "";
|
||||||
|
|
||||||
|
public string Password { get; set; } = "";
|
||||||
|
|
||||||
|
public string ConfirmPassword { get; set; } = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
[SupplyParameterFromForm]
|
||||||
|
InputModel Input { get; set; } = new();
|
||||||
|
|
||||||
|
[SupplyParameterFromQuery]
|
||||||
|
string? ReturnUrl { get; set; }
|
||||||
|
|
||||||
|
async Task OnSubmit(InputModel mode)
|
||||||
|
{
|
||||||
|
var user = Activator.CreateInstance<AppUser>();
|
||||||
|
await UserStore.SetUserNameAsync(user, Input.UserName, CancellationToken.None);
|
||||||
|
|
||||||
|
var result = await UserManager.CreateAsync(user, Input.Password);
|
||||||
|
if (!result.Succeeded)
|
||||||
|
{
|
||||||
|
NotificationService.Notify(new NotificationMessage()
|
||||||
|
{
|
||||||
|
Severity = NotificationSeverity.Error,
|
||||||
|
Summary = "Ошибка",
|
||||||
|
Detail = string.Join(", ", result.Errors.Select(error => error.Description))
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await SignInManager.SignInAsync(user, isPersistent: false);
|
||||||
|
|
||||||
|
RedirectManager.RedirectTo(ReturnUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,7 +5,6 @@
|
|||||||
<PageTitle>Ошибка</PageTitle>
|
<PageTitle>Ошибка</PageTitle>
|
||||||
|
|
||||||
<h2 class="text-danger">При выполнении запроса возникла ошибка</h2>
|
<h2 class="text-danger">При выполнении запроса возникла ошибка</h2>
|
||||||
|
|
||||||
@if (ShowRequestId)
|
@if (ShowRequestId)
|
||||||
{
|
{
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
@using Hcs.Broker.Logger
|
@using Hcs.Broker.Logger
|
||||||
@using Hcs.Broker.MessageCapturer
|
@using Hcs.Broker.MessageCapturer
|
||||||
@using Hcs.Service.Async.Nsi
|
@using Hcs.Service.Async.Nsi
|
||||||
@using Hcs.WebApp.Components.Shared
|
|
||||||
@using Hcs.WebApp.Config
|
@using Hcs.WebApp.Config
|
||||||
@using Hcs.WebApp.Utils
|
@using Hcs.WebApp.Utils
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
@using Radzen
|
@using System.Text.Json
|
||||||
@using System.Text.Json
|
|
||||||
@using System.Diagnostics.CodeAnalysis
|
@using System.Diagnostics.CodeAnalysis
|
||||||
|
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
|
|||||||
Reference in New Issue
Block a user