Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Application.Common.Exceptions;
using Application.Common.Interfaces.Services;
using Application.Contract.Account.Commands;
using Application.Contract.Identity;
using Domain.Entities;
using MediatR;
using Microsoft.AspNetCore.Identity;
Expand All @@ -23,6 +24,9 @@ public async Task<Unit> Handle(DeleteMyAccountCommand request, CancellationToken

var user = await userManager.FindByNameAsync(userName)
?? throw new NotFoundException("Пользователь не найден.");

if (await userManager.IsInRoleAsync(user, ApplicationRoles.SuperAdmin))
throw new ForbiddenException("Нельзя удалить аккаунт супер-администратора.");

var res = await userManager.DeleteAsync(user);
res.ThrowBadRequestIfError();
Expand Down
15 changes: 11 additions & 4 deletions src/Client/Client/Pages/Clients/Account.razor
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ else
{
<MudDivider Class="my-2"/>
<MudText Typo="Typo.body2">
Мы отправим письмо с кодом подтверждения на <b>@_email.NewEmail</b>. Подтвердите адрес — и он
Мы отправим письмо с кодом подтверждения на <b>@_email.NewEmail</b>. Подтвердите
адрес — и он
будет добавлен к вашему аккаунту.
</MudText>

Expand Down Expand Up @@ -236,7 +237,8 @@ else
{
<MudDivider Class="my-2"/>
<MudText Typo="Typo.body2">
Мы отправим SMS с кодом подтверждения на <b>+7-@_phone</b>. Подтвердите номер — и он будет
Мы отправим SMS с кодом подтверждения на <b>+7-@_phone</b>. Подтвердите номер — и он
будет
добавлен к вашему аккаунту.
</MudText>

Expand Down Expand Up @@ -322,18 +324,23 @@ else
<MudPaper Class="pa-3" Elevation="5">
<MudStack AlignItems="AlignItems.Center" Spacing="2">
<MudText Typo="Typo.h6" Align="Align.Center">Сессии</MudText>

<MudGrid Class="w-100">
<MudItem xs="12" sm="6" Class="minw0">
<MudButton Color="Color.Error"
Variant="Variant.Filled"
Size="Size.Medium"
FullWidth="true"
StartIcon="@Icons.Material.Filled.DeleteForever"
Disabled="_deletingAccount"
Disabled="@(_deletingAccount || _isSuperAdmin)"
OnClick="@ConfirmDeleteAccount">
Удалить аккаунт
</MudButton>
@if (_isSuperAdmin)
{
<MudText Typo="Typo.caption" Color="Color.Warning">
Учетная запись супер-администратора не может быть удалена.
</MudText>
}
</MudItem>

<MudItem xs="12" sm="6" Class="minw0">
Expand Down
7 changes: 6 additions & 1 deletion src/Client/Client/Pages/Clients/Account.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.RegularExpressions;
using Application.Contract.Account.Commands;
using Application.Contract.Account.Responses;
using Application.Contract.Identity;
using Application.Contract.Verification.Commands;
using Client.Infrastructure.Auth;
using Client.Infrastructure.Services.Verification;
Expand Down Expand Up @@ -48,7 +49,8 @@ public partial class Account
// Подсказки/прогресс по отправке кодов
private bool _promptEmailConfirm, _promptPhoneConfirm;
private bool _sendingEmailCode, _sendingPhoneCode;

private bool _isSuperAdmin;

protected override async Task OnInitializedAsync()
{
var myAccountResponse = await AccountService.GetAsync();
Expand All @@ -59,6 +61,9 @@ protected override async Task OnInitializedAsync()
}

_account = myAccountResponse;

var auth = await AuthState.GetAuthenticationStateAsync();
_isSuperAdmin = auth.User.IsInRole(ApplicationRoles.SuperAdmin);

// Уже заполненные значения в TextField-ах
_profile.Name = myAccountResponse.Name;
Expand Down
Loading