added authentication, adjusted controller names

This commit is contained in:
Ryan Peters
2023-05-10 16:22:51 -04:00
parent 7657169e1e
commit 89a8b1a28b
7 changed files with 92 additions and 5 deletions

View File

@ -1,5 +1,6 @@
using BinaryDad.Notes;
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Authentication.Cookies;
var builder = WebApplication.CreateBuilder(args);
@ -8,6 +9,16 @@ builder.Services.AddControllersWithViews();
builder.Services.AddSignalR();
builder.Services.AddSingleton<INoteService, FileNoteService>();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
});
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o =>
{
o.LoginPath = "/login";
});
var app = builder.Build();
// Configure the HTTP request pipeline.
@ -19,12 +30,12 @@ if (!app.Environment.IsDevelopment())
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
pattern: "{controller=Note}/{action=Index}/{id?}");
app.MapHub<NoteHub>("/noteHub");