forked from CodeBeamOrg/UltimateAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountStatusDialog.razor
More file actions
93 lines (83 loc) · 3.34 KB
/
AccountStatusDialog.razor
File metadata and controls
93 lines (83 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
@using CodeBeam.UltimateAuth.Core.Contracts
@using CodeBeam.UltimateAuth.Users.Contracts
@inject IUAuthClient UAuthClient
@inject ISnackbar Snackbar
@inject IDialogService DialogService
<MudDialog Class="mud-width-full" ContentClass="uauth-dialog">
<TitleContent>
<MudText>Identifier Management</MudText>
<MudText Typo="Typo.subtitle2" Color="Color.Primary">User: @AuthState?.Identity?.DisplayName</MudText>
</TitleContent>
<DialogContent>
<MudStack Class="mud-width-full">
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.NearbyOff" OnClick="SuspendAccountAsync">
Suspend Account
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="DeleteAccountAsync">
Delete Account
</MudButton>
</MudStack>
</DialogContent>
</MudDialog>
@code {
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = default!;
[Parameter]
public UAuthState AuthState { get; set; } = default!;
private async Task SuspendAccountAsync()
{
var info = await DialogService.ShowMessageBoxAsync(
title: "Are You Sure",
markupMessage: (MarkupString)
"""
You are going to suspend your account.<br/><br/>
You can still active your account later.
""",
yesText: "Suspend", noText: "Cancel",
options: new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, BackgroundClass = "uauth-blur-slight" });
if (info != true)
{
Snackbar.Add("Suspend process cancelled", Severity.Info);
return;
}
ChangeUserStatusSelfRequest request = new() { NewStatus = SelfUserStatus.SelfSuspended };
var result = await UAuthClient.Users.ChangeStatusSelfAsync(request);
if (result.IsSuccess)
{
Snackbar.Add("Your account suspended successfully.", Severity.Success);
MudDialog.Close();
}
else
{
Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "Delete failed.", Severity.Error);
}
}
private async Task DeleteAccountAsync()
{
var info = await DialogService.ShowMessageBoxAsync(
title: "Are You Sure",
markupMessage: (MarkupString)
"""
You are going to delete your account.<br/><br/>
This action can't be undone.<br/><br/>
(Actually it is, admin can handle soft deleted accounts.)
""",
yesText: "Delete", noText: "Cancel",
options: new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, BackgroundClass = "uauth-blur-slight" });
if (info != true)
{
Snackbar.Add("Deletion cancelled", Severity.Info);
return;
}
var result = await UAuthClient.Users.DeleteMeAsync();
if (result.IsSuccess)
{
Snackbar.Add("Your account deleted successfully.", Severity.Success);
MudDialog.Close();
}
else
{
Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "Delete failed.", Severity.Error);
}
}
}