Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
Changed template based on the new net 6.0 minimal templates
Browse files Browse the repository at this point in the history
  • Loading branch information
stavroskasidis committed Dec 3, 2021
1 parent 7eb45e8 commit ab85e36
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 73 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,5 @@ ASALocalRun/
# BeatPulse healthcheck temp database
healthchecksdb
**/data.db
/template/BlazorWithIdentity.Server/data.db-shm
/template/BlazorWithIdentity.Server/data.db-wal
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions template/BlazorWithIdentity.Client/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@page "/counter"
@attribute [Authorize]

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p>Current count: @currentCount</p>
Expand Down
2 changes: 2 additions & 0 deletions template/BlazorWithIdentity.Client/Pages/FetchData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
@using BlazorWithIdentity.Shared
@inject HttpClient Http

<PageTitle>Weather forecast</PageTitle>

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>
Expand Down
2 changes: 2 additions & 0 deletions template/BlazorWithIdentity.Client/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@page "/"
@attribute [Authorize]

<PageTitle>Index</PageTitle>

<AuthorizeView>
<Authorized>
<h1>Hello @context.User.Identity.Name !!</h1>
Expand Down
2 changes: 2 additions & 0 deletions template/BlazorWithIdentity.Client/Pages/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
@inject NavigationManager navigationManager
@inject IdentityAuthenticationStateProvider authStateProvider

<PageTitle>Login</PageTitle>

<h1 class="h2 font-weight-normal login-title">
Blazor with Identity Sample
</h1>
Expand Down
2 changes: 2 additions & 0 deletions template/BlazorWithIdentity.Client/Pages/Register.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
@inject NavigationManager navigationManager
@inject IdentityAuthenticationStateProvider authStateProvider

<PageTitle>Register</PageTitle>

<h1 class="h2 font-weight-normal login-title">
Blazor with Identity Sample
</h1>
Expand Down
39 changes: 13 additions & 26 deletions template/BlazorWithIdentity.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
using BlazorWithIdentity.Client.Services.Contracts;
using BlazorWithIdentity.Client;
using BlazorWithIdentity.Client.Services.Contracts;
using BlazorWithIdentity.Client.Services.Implementations;
using BlazorWithIdentity.Client.States;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace BlazorWithIdentity.Client
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddOptions();
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<IdentityAuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(s => s.GetRequiredService<IdentityAuthenticationStateProvider>());
builder.Services.AddScoped<IAuthorizeApi, AuthorizeApi>();
builder.Services.AddOptions();
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<IdentityAuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(s => s.GetRequiredService<IdentityAuthenticationStateProvider>());
builder.Services.AddScoped<IAuthorizeApi, AuthorizeApi>();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

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


var host = builder.Build();
await host.RunAsync();
}
}
}
await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"BlazorWithIdentity": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BlazorWithIdentity": {
"commandName": "Project",
"dotnetRunMessages": "true",
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorWithIdentity.Server.Controllers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using BlazorWithIdentity.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorWithIdentity.Server.Controllers
{
Expand Down
100 changes: 78 additions & 22 deletions template/BlazorWithIdentity.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace BlazorWithIdentity.Server
using BlazorWithIdentity.Server.Data;
using BlazorWithIdentity.Server.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite("Filename=data.db"));

builder.Services.AddIdentity<ApplicationUser, IdentityRole<Guid>>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();

builder.Services.Configure<IdentityOptions>(options =>
{
// Password settings
options.Password.RequireDigit = true;
options.Password.RequiredLength = 6;
options.Password.RequireNonAlphanumeric = true;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = false;

// Lockout settings
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
options.Lockout.MaxFailedAccessAttempts = 10;
options.Lockout.AllowedForNewUsers = true;

// User settings
options.User.RequireUniqueEmail = false;
});

builder.Services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = true;
options.Events.OnRedirectToLogin = context =>
{
context.Response.StatusCode = 401;
return Task.CompletedTask;
};
});


builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
public class Program
using (var serviceScope = app.Services.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
//Note: Microsoft recommends to NOT migrate your database at Startup.
//You should consider your migration strategy according to the guidelines
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
}

app.UseWebAssemblyDebugging();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseBlazorFrameworkFiles();
app.UseStaticFiles();

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

app.MapRazorPages();
app.MapControllers();
app.MapFallbackToFile("index.html");

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"BlazorWithIdentity.Server": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BlazorWithIdentity.Server": {
"commandName": "Project",
"dotnetRunMessages": "true",
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
"Microsoft.AspNetCore": "Warning"
}
}
}
3 changes: 1 addition & 2 deletions template/BlazorWithIdentity.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
Expand Down
Binary file removed template/BlazorWithIdentity.Server/data.db
Binary file not shown.
2 changes: 1 addition & 1 deletion templatepack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<PackageType>Template</PackageType>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageProjectUrl>https://github.com/stavroskasidis/BlazorWithIdentity</PackageProjectUrl>
Expand Down

0 comments on commit ab85e36

Please sign in to comment.