Skip to content

Commit 81a74cf

Browse files
committed
Improve Blazor WASM Sample
1 parent 1027651 commit 81a74cf

File tree

82 files changed

+4386
-1653
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4386
-1653
lines changed
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
@namespace CodeBeam.UltimateAuth.Sample
22
@inherits ComponentBase
33

4-
<svg xmlns="http://www.w3.org/2000/svg"
5-
viewBox="0 0 200 240"
6-
width="@Size"
7-
height="@Size"
8-
style="@BuildStyle()"
9-
class="@Class">
4+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 240" width="@Size" height="@Size" style="@BuildStyle()" class="@Class">
105

116
@if (Variant == UAuthLogoVariant.Brand)
127
{
138
<path fill="@ShieldColor"
14-
d="M32.39,14.07H167.61c11.27,0,18,6.76,18,18V133.52
15-
c0,22.54-58.59,69.87-85.64,92.41
16-
-27-22.54-85.64-69.87-85.64-92.41V32.1
17-
C14.36,20.83,21.12,14.07,32.39,14.07Z" />
9+
d="M32.39,14.07H167.61c11.27,0,18,6.76,18,18V133.52c0,22.54-58.59,69.87-85.64,92.41-27-22.54-85.64-69.87-85.64-92.41V32.1C14.36,20.83,21.12,14.07,32.39,14.07Z" />
1810

19-
<path fill="@KeyColor"
20-
fill-rule="evenodd"
21-
d="@KeyPath" />
11+
<path fill="@KeyColor" fill-rule="evenodd" d="@KeyPath" />
2212
}
2313
else
2414
{
25-
<path d="M32.39,14.07H167.61c11.27,0,18,6.76,18,18V133.52
26-
c0,22.54-58.59,69.87-85.64,92.41
27-
-27-22.54-85.64-69.87-85.64-92.41V32.1
28-
C14.36,20.83,21.12,14.07,32.39,14.07Z" />
15+
<path d="M32.39,14.07H167.61c11.27,0,18,6.76,18,18V133.52c0,22.54-58.59,69.87-85.64,92.41-27-22.54-85.64-69.87-85.64-92.41V32.1C14.36,20.83,21.12,14.07,32.39,14.07Z" />
2916

30-
<path fill-rule="evenodd"
31-
d="@KeyPath" />
17+
<path fill-rule="evenodd" d="@KeyPath" />
3218
}
3319
</svg>

samples/blazor-server/CodeBeam.UltimateAuth.Sample.BlazorServer/Components/Dialogs/AccountStatusDialog.razor

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@inject ISnackbar Snackbar
55
@inject IDialogService DialogService
66

7-
<MudDialog Class="mud-width-full" ContentClass="uauth-dialog">
7+
<MudDialog Class="mud-width-full">
88
<TitleContent>
99
<MudText>Identifier Management</MudText>
1010
<MudText Typo="Typo.subtitle2" Color="Color.Primary">User: @AuthState?.Identity?.DisplayName</MudText>
@@ -21,73 +21,3 @@
2121
</MudStack>
2222
</DialogContent>
2323
</MudDialog>
24-
25-
@code {
26-
[CascadingParameter]
27-
private IMudDialogInstance MudDialog { get; set; } = default!;
28-
29-
[Parameter]
30-
public UAuthState AuthState { get; set; } = default!;
31-
32-
private async Task SuspendAccountAsync()
33-
{
34-
var info = await DialogService.ShowMessageBoxAsync(
35-
title: "Are You Sure",
36-
markupMessage: (MarkupString)
37-
"""
38-
You are going to suspend your account.<br/><br/>
39-
You can still active your account later.
40-
""",
41-
yesText: "Suspend", noText: "Cancel",
42-
options: new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, BackgroundClass = "uauth-blur-slight" });
43-
44-
if (info != true)
45-
{
46-
Snackbar.Add("Suspend process cancelled", Severity.Info);
47-
return;
48-
}
49-
50-
ChangeUserStatusSelfRequest request = new() { NewStatus = SelfUserStatus.SelfSuspended };
51-
var result = await UAuthClient.Users.ChangeStatusSelfAsync(request);
52-
if (result.IsSuccess)
53-
{
54-
Snackbar.Add("Your account suspended successfully.", Severity.Success);
55-
MudDialog.Close();
56-
}
57-
else
58-
{
59-
Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "Delete failed.", Severity.Error);
60-
}
61-
}
62-
63-
private async Task DeleteAccountAsync()
64-
{
65-
var info = await DialogService.ShowMessageBoxAsync(
66-
title: "Are You Sure",
67-
markupMessage: (MarkupString)
68-
"""
69-
You are going to delete your account.<br/><br/>
70-
This action can't be undone.<br/><br/>
71-
(Actually it is, admin can handle soft deleted accounts.)
72-
""",
73-
yesText: "Delete", noText: "Cancel",
74-
options: new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, BackgroundClass = "uauth-blur-slight" });
75-
76-
if (info != true)
77-
{
78-
Snackbar.Add("Deletion cancelled", Severity.Info);
79-
return;
80-
}
81-
82-
var result = await UAuthClient.Users.DeleteMeAsync();
83-
if (result.IsSuccess)
84-
{
85-
Snackbar.Add("Your account deleted successfully.", Severity.Success);
86-
MudDialog.Close();
87-
}
88-
else
89-
{
90-
Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "Delete failed.", Severity.Error);
91-
}
92-
}
93-
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using CodeBeam.UltimateAuth.Client;
2+
using CodeBeam.UltimateAuth.Users.Contracts;
3+
using Microsoft.AspNetCore.Components;
4+
using MudBlazor;
5+
6+
namespace CodeBeam.UltimateAuth.Sample.BlazorServer.Components.Dialogs;
7+
8+
public partial class AccountStatusDialog
9+
{
10+
[CascadingParameter]
11+
private IMudDialogInstance MudDialog { get; set; } = default!;
12+
13+
[Parameter]
14+
public UAuthState AuthState { get; set; } = default!;
15+
16+
private async Task SuspendAccountAsync()
17+
{
18+
var info = await DialogService.ShowMessageBoxAsync(
19+
title: "Are You Sure",
20+
markupMessage: (MarkupString)
21+
"""
22+
You are going to suspend your account.<br/><br/>
23+
You can still active your account later.
24+
""",
25+
yesText: "Suspend", noText: "Cancel",
26+
options: new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, BackgroundClass = "uauth-blur-slight" });
27+
28+
if (info != true)
29+
{
30+
Snackbar.Add("Suspend process cancelled.", Severity.Info);
31+
return;
32+
}
33+
34+
ChangeUserStatusSelfRequest request = new() { NewStatus = SelfUserStatus.SelfSuspended };
35+
var result = await UAuthClient.Users.ChangeStatusSelfAsync(request);
36+
if (result.IsSuccess)
37+
{
38+
Snackbar.Add("Your account suspended successfully.", Severity.Success);
39+
MudDialog.Close();
40+
}
41+
else
42+
{
43+
Snackbar.Add(result?.GetErrorText ?? "Delete failed.", Severity.Error);
44+
}
45+
}
46+
47+
private async Task DeleteAccountAsync()
48+
{
49+
var info = await DialogService.ShowMessageBoxAsync(
50+
title: "Are You Sure",
51+
markupMessage: (MarkupString)
52+
"""
53+
You are going to delete your account.<br/><br/>
54+
This action can't be undone.<br/><br/>
55+
(Actually it is, admin can handle soft deleted accounts.)
56+
""",
57+
yesText: "Delete", noText: "Cancel",
58+
options: new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, BackgroundClass = "uauth-blur-slight" });
59+
60+
if (info != true)
61+
{
62+
Snackbar.Add("Deletion cancelled.", Severity.Info);
63+
return;
64+
}
65+
66+
var result = await UAuthClient.Users.DeleteMeAsync();
67+
if (result.IsSuccess)
68+
{
69+
Snackbar.Add("Your account deleted successfully.", Severity.Success);
70+
MudDialog.Close();
71+
}
72+
else
73+
{
74+
Snackbar.Add(result?.GetErrorText ?? "Delete failed.", Severity.Error);
75+
}
76+
}
77+
}

samples/blazor-server/CodeBeam.UltimateAuth.Sample.BlazorServer/Components/Dialogs/CreateUserDialog.razor

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
</TitleContent>
1010

1111
<DialogContent>
12-
<MudForm @ref="_form">
12+
<MudForm @ref="_form" OnEnterPressed="CreateUserAsync">
1313
<MudStack Spacing="2">
1414
<MudTextField @bind-Value="_username" Label="Username" Variant="Variant.Outlined" Required="true" />
1515
<MudTextField @bind-Value="_email" Label="Email" Variant="Variant.Outlined" Required="true" />
1616
<MudPasswordField @bind-Value="_password" Label="Password" Variant="Variant.Outlined" Required="true" />
17-
<MudPasswordField @bind-Value="_passwordCheck" Label="Password (Again)" Variant="Variant.Outlined" Required="true" Validation="@(() => PasswordMatch(_password))" />
17+
<MudPasswordField @bind-Value="_passwordCheck" Label="Password (Again)" Variant="Variant.Outlined" Required="true" Immediate="true" Validation="@(new Func<string, string>(PasswordMatch))" />
1818
<MudTextField @bind-Value="_displayName" Label="Display Name" Variant="Variant.Outlined" />
1919
</MudStack>
2020
</MudForm>
@@ -25,52 +25,3 @@
2525
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="CreateUserAsync">Create</MudButton>
2626
</DialogActions>
2727
</MudDialog>
28-
29-
@code {
30-
private MudForm _form = null!;
31-
private string? _username;
32-
private string? _email;
33-
private string? _password;
34-
private string? _passwordCheck;
35-
private string? _displayName;
36-
37-
[CascadingParameter]
38-
private IMudDialogInstance MudDialog { get; set; } = default!;
39-
40-
private async Task CreateUserAsync()
41-
{
42-
await _form.Validate();
43-
44-
if (!_form.IsValid)
45-
return;
46-
47-
if (_password != _passwordCheck)
48-
{
49-
Snackbar.Add("Passwords do not match", Severity.Error);
50-
return;
51-
}
52-
53-
var request = new CreateUserRequest
54-
{
55-
UserName = _username,
56-
Email = _email,
57-
DisplayName = _displayName,
58-
Password = _password
59-
};
60-
61-
var result = await UAuthClient.Users.CreateAdminAsync(request);
62-
63-
if (!result.IsSuccess)
64-
{
65-
Snackbar.Add(result.GetErrorText ?? "User creation failed", Severity.Error);
66-
return;
67-
}
68-
69-
Snackbar.Add("User created successfully", Severity.Success);
70-
MudDialog.Close(DialogResult.Ok(true));
71-
}
72-
73-
private string PasswordMatch(string? arg) => _password != arg ? "Passwords don't match" : string.Empty;
74-
75-
private void Cancel() => MudDialog.Cancel();
76-
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using CodeBeam.UltimateAuth.Users.Contracts;
2+
using Microsoft.AspNetCore.Components;
3+
using MudBlazor;
4+
5+
namespace CodeBeam.UltimateAuth.Sample.BlazorServer.Components.Dialogs;
6+
7+
public partial class CreateUserDialog
8+
{
9+
private MudForm _form = null!;
10+
private string? _username;
11+
private string? _email;
12+
private string? _password;
13+
private string? _passwordCheck;
14+
private string? _displayName;
15+
16+
[CascadingParameter]
17+
private IMudDialogInstance MudDialog { get; set; } = default!;
18+
19+
private async Task CreateUserAsync()
20+
{
21+
await _form.Validate();
22+
23+
if (!_form.IsValid)
24+
return;
25+
26+
if (_password != _passwordCheck)
27+
{
28+
Snackbar.Add("Passwords don't match.", Severity.Error);
29+
return;
30+
}
31+
32+
var request = new CreateUserRequest
33+
{
34+
UserName = _username,
35+
Email = _email,
36+
DisplayName = _displayName,
37+
Password = _password
38+
};
39+
40+
var result = await UAuthClient.Users.CreateAdminAsync(request);
41+
42+
if (!result.IsSuccess)
43+
{
44+
Snackbar.Add(result.GetErrorText ?? "User creation failed.", Severity.Error);
45+
return;
46+
}
47+
48+
Snackbar.Add("User created successfully", Severity.Success);
49+
MudDialog.Close(DialogResult.Ok(true));
50+
}
51+
52+
private string PasswordMatch(string? arg) => _password != arg ? "Passwords don't match." : string.Empty;
53+
54+
private void Cancel() => MudDialog.Cancel();
55+
}

0 commit comments

Comments
 (0)