Skip to content

Commit

Permalink
Upgraded MudBlazor Templates to .NET 9
Browse files Browse the repository at this point in the history
  • Loading branch information
jperson2000 committed Nov 15, 2024
1 parent 02309da commit 3cb4418
Show file tree
Hide file tree
Showing 36 changed files with 118 additions and 547 deletions.
2 changes: 1 addition & 1 deletion src/MudBlazor.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- Keep package type as 'Template' to show the package as a template package on nuget.org and make your template available in dotnet new search.-->
<PackageType>Template</PackageType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
Expand Down
2 changes: 1 addition & 1 deletion src/mudblazor/.template.config/dotnetcli.host.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/dotnetcli.host",
"$schema": "https://json.schemastore.org/dotnetcli.host",
"symbolInfo": {
"skipRestore": {
"longName": "no-restore",
Expand Down
2 changes: 1 addition & 1 deletion src/mudblazor/.template.config/ide.host.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/ide.host",
"$schema": "https://json.schemastore.org/ide.host",
"order": 610,
"icon": "icon.png",
"disableHttpsSymbol": "NoHttps",
Expand Down
45 changes: 13 additions & 32 deletions src/mudblazor/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"650B3CE7-2E93-4CC4-9F46-466686815EAA",
"53bc9b9d-9d6a-45d4-8429-2a2761773502"
],
"identity": "MudBlazorWebApp.CSharp.8.0",
"identity": "MudBlazorWebApp.CSharp.10.0",
"thirdPartyNotices": "",
"preferNameDirectory": true,
"primaryOutputs": [
Expand Down Expand Up @@ -52,13 +52,7 @@
"**/wwwroot/bootstrap/**"
],
"modifiers": [
{
"condition": "(!IndividualLocalAuth)",
"exclude": [
"**/wwwroot/bootstrap/**"
]
},
{
{
"condition": "(!UseWebAssembly)",
"exclude": [
"MudBlazor.Template.Client/**",
Expand All @@ -73,6 +67,7 @@
"rename": {
"MudBlazor.Template/Components/Layout/": "./MudBlazor.Template.Client/Layout/",
"MudBlazor.Template/Components/Pages/Home.razor": "./MudBlazor.Template.Client/Pages/Home.razor",
"MudBlazor.Template/Components/Pages/Weather.razor": "./MudBlazor.Template.Client/Pages/Weather.razor",
"MudBlazor.Template/Components/Routes.razor": "./MudBlazor.Template.Client/Routes.razor"
}
},
Expand All @@ -94,10 +89,9 @@
}
},
{
"condition": "(UseWebAssembly || (!UseWebAssembly && !UseServer))",
"condition": "(!(UseServer && !UseWebAssembly))",
"exclude": [
"MudBlazor.Template/Components/Pages/Counter.razor",
"MudBlazor.Template/Components/Pages/Weather.razor"
"MudBlazor.Template/Components/Pages/Counter.razor"
]
},
{
Expand Down Expand Up @@ -130,7 +124,6 @@
"exclude": [
"MudBlazor.Template/Components/Account/**",
"MudBlazor.Template/Data/**",
"MudBlazor.Template.Client/PersistentAuthenticationStateProvider.cs",
"MudBlazor.Template.Client/UserInfo.cs",
"MudBlazor.Template.Client/Pages/Auth.razor"
]
Expand All @@ -148,24 +141,12 @@
]
},
{
"condition": "(!(IndividualLocalAuth && UseServer && UseWebAssembly))",
"exclude": [
"MudBlazor.Template/Components/Account/PersistingRevalidatingAuthenticationStateProvider.cs"
]
},
{
"condition": "(!(IndividualLocalAuth && UseServer && !UseWebAssembly))",
"condition": "(!(IndividualLocalAuth && UseServer))",
"exclude": [
"MudBlazor.Template/Components/Account/IdentityRevalidatingAuthenticationStateProvider.cs"
]
},
{
"condition": "(!(IndividualLocalAuth && !UseServer && UseWebAssembly))",
"exclude": [
"MudBlazor.Template/Components/Account/PersistingServerAuthenticationStateProvider.cs"
]
},
{
{
"condition": "(IndividualLocalAuth && UseLocalDB && UseWebAssembly)",
"rename": {
"MudBlazor.Template/Data/SqlServer/": "MudBlazor.Template/Data/Migrations/"
Expand Down Expand Up @@ -217,12 +198,12 @@
"datatype": "choice",
"choices": [
{
"choice": "net8.0",
"description": "Target net8.0"
"choice": "net10.0",
"description": "Target net10.0"
}
],
"replaces": "net8.0",
"defaultValue": "net8.0"
"replaces": "net10.0",
"defaultValue": "net10.0"
},
"HostIdentifier": {
"type": "bind",
Expand Down Expand Up @@ -364,7 +345,7 @@
"type": "parameter",
"datatype": "choice",
"defaultValue": "InteractiveGlobal",
"displayName": "_Interactivity location",
"displayName": "Interactivity _location",
"description": "Chooses which components will have interactive rendering enabled",
"isEnabled": "(InteractivityPlatform != \"None\")",
"choices": [
Expand Down Expand Up @@ -392,7 +373,7 @@
"type": "parameter",
"datatype": "bool",
"defaultValue": "true",
"displayName": "_Include sample pages",
"displayName": "Include _sample pages",
"description": "Configures whether to add sample pages and styling to demonstrate basic usage patterns."
},
"Empty": {
Expand Down

This file was deleted.

77 changes: 0 additions & 77 deletions src/mudblazor/MudBlazor.Template.Client/Pages/Weather.razor

This file was deleted.

This file was deleted.

10 changes: 2 additions & 8 deletions src/mudblazor/MudBlazor.Template.Client/Program.Main.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#if (IndividualLocalAuth)
using MudBlazor.Template.Client;
using Microsoft.AspNetCore.Components.Authorization;
#endif
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor.Services;

Expand All @@ -12,16 +8,14 @@ class Program
static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddMudServices();

#if (IndividualLocalAuth)
builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddSingleton<AuthenticationStateProvider, PersistentAuthenticationStateProvider>();
#endif
builder.Services.AddAuthenticationStateDeserialization();

#endif
await builder.Build().RunAsync();
}
}
7 changes: 1 addition & 6 deletions src/mudblazor/MudBlazor.Template.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#if (IndividualLocalAuth)
using MudBlazor.Template.Client;
using Microsoft.AspNetCore.Components.Authorization;
#endif
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor.Services;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddMudServices();

#if (IndividualLocalAuth)
builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddSingleton<AuthenticationStateProvider, PersistentAuthenticationStateProvider>();
builder.Services.AddAuthenticationStateDeserialization();

#endif
await builder.Build().RunAsync();
9 changes: 0 additions & 9 deletions src/mudblazor/MudBlazor.Template.Client/UserInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static IEndpointConventionBuilder MapAdditionalIdentityEndpoints(this IEn

accountGroup.MapPost("/Logout", async (
ClaimsPrincipal user,
SignInManager<ApplicationUser> signInManager,
[FromServices] SignInManager<ApplicationUser> signInManager,
[FromForm] string returnUrl) =>
{
await signInManager.SignOutAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" role="alert" />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" class="form-control" autocomplete="email" placeholder="Please enter your email." />
<label for="email" class="form-label">Email</label>
<InputText @bind-Value="Input.Email" id="Input.Email" class="form-control" autocomplete="email" placeholder="Please enter your email." />
<label for="Input.Email" class="form-label">Email</label>
<ValidationMessage For="() => Input.Email" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Register</button>
Expand All @@ -48,7 +48,7 @@
public const string LoginCallbackAction = "LoginCallback";

private string? message;
private ExternalLoginInfo externalLoginInfo = default!;
private ExternalLoginInfo? externalLoginInfo;

[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
Expand All @@ -65,7 +65,7 @@
[SupplyParameterFromQuery]
private string? Action { get; set; }

private string? ProviderDisplayName => externalLoginInfo.ProviderDisplayName;
private string? ProviderDisplayName => externalLoginInfo?.ProviderDisplayName;

protected override async Task OnInitializedAsync()
{
Expand Down Expand Up @@ -98,6 +98,11 @@

private async Task OnLoginCallbackAsync()
{
if (externalLoginInfo is null)
{
RedirectManager.RedirectToWithStatus("Account/Login", "Error loading external login information.", HttpContext);
}

// Sign in the user with this external login provider if the user already has a login.
var result = await SignInManager.ExternalLoginSignInAsync(
externalLoginInfo.LoginProvider,
Expand Down Expand Up @@ -127,6 +132,11 @@

private async Task OnValidSubmitAsync()
{
if (externalLoginInfo is null)
{
RedirectManager.RedirectToWithStatus("Account/Login", "Error loading external login information during confirmation.", HttpContext);
}

var emailStore = GetEmailStore();
var user = CreateUser();

Expand Down
Loading

0 comments on commit 3cb4418

Please sign in to comment.