1
0
Fork 0
mirror of https://github.com/miawinter98/just-short-it.git synced 2024-09-20 01:39:00 +00:00

added: base layout and authorization to razor components

This commit is contained in:
Mia Rose Winter 2023-11-18 14:04:51 +01:00
parent dee6653214
commit 9284a8ddfd
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
9 changed files with 58 additions and 8 deletions

View file

@ -18,7 +18,9 @@
</head> </head>
<body> <body>
<Routes /> <Routes />
<script src="_framework/blazor.web.js"></script> <script src="_framework/blazor.web.js"></script>
</body> </body>

View file

@ -1,3 +1,11 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
@Body @using JustShortIt.Components.Partials
<HeaderPartial />
<main class="flex-1 container mx-auto px-8 py-8 grid">
@Body
</main>
<FooterPartial />

View file

@ -0,0 +1,8 @@
<footer class="footer footer-center py-10 bg-primary text-secondary-content">
<aside class="">
<p>
<a class="hover:link" href="https://github.com/miawinter98/just-short-it" target="_blank">Just Short it!</a>
by <a class="hover:link" href="https://miawinter.de/" target="_blank">Mia Winter</a>.
</p>
</aside>
</footer>

View file

@ -0,0 +1,15 @@
<header>
<nav class="navbar bg-primary text-primary-content p-0 min-h-0" aria-label="main navigation">
<div class="flex-1">
<a class="btn btn-ghost rounded-none px-6" href="https://github.com/miawinter98/just-short-it" target="_blank">
<figure>
<img class="w-8 h-8" src="/img/jsi-logo.png" width="400" alt="" />
</figure>
Just Short It!
</a>
</div>
<div class="flex-none mr-6">
<LoginPartial />
</div>
</nav>
</header>

View file

@ -0,0 +1,9 @@
<AuthorizeView>
<Authorized>
<span class="mx-3">@(context.User.Identity?.Name ?? "err_username_unknown")</span>
<a class="btn btn-link text-secondary-content" href="/Logout">Logout</a>
</Authorized>
<NotAuthorized>
<a class="hover:link text-secondary-content" href="/Login">Login</a>
</NotAuthorized>
</AuthorizeView>

View file

@ -1,6 +1,8 @@
<Router AppAssembly="@typeof(Program).Assembly"> <CascadingAuthenticationState>
<Found Context="routeData"> <Router AppAssembly="@typeof(Program).Assembly">
<RouteView RouteData="@routeData" DefaultLayout="typeof(Layout.MainLayout)" /> <Found Context="routeData">
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> <AuthorizeRouteView RouteData="@routeData" DefaultLayout="typeof(Layout.MainLayout)" />
</Found> <FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Router> </Found>
</Router>
</CascadingAuthenticationState>

View file

@ -3,6 +3,7 @@
@using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Authorization
@using static Microsoft.AspNetCore.Components.Web.RenderMode @using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop @using Microsoft.JSInterop

View file

@ -9,6 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="StackExchange.Redis" Version="2.7.4" /> <PackageReference Include="StackExchange.Redis" Version="2.7.4" />

View file

@ -2,6 +2,8 @@
using JustShortIt.Model; using JustShortIt.Model;
using JustShortIt.Service; using JustShortIt.Service;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables("JSI_"); builder.Configuration.AddEnvironmentVariables("JSI_");
@ -43,7 +45,7 @@
} }
// Add Authentication // Add Authentication
builder.Services.AddSingleton(_ => new AuthenticationService(user)); builder.Services.AddScoped(_ => new AuthenticationService(user));
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => { builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => {
options.ExpireTimeSpan = TimeSpan.FromHours(24); options.ExpireTimeSpan = TimeSpan.FromHours(24);
options.SlidingExpiration = true; options.SlidingExpiration = true;
@ -51,6 +53,8 @@
options.LoginPath = "/Login"; options.LoginPath = "/Login";
options.LogoutPath = "/Logout"; options.LogoutPath = "/Logout";
}); });
builder.Services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();
builder.Services.AddCascadingAuthenticationState();
var app = builder.Build(); var app = builder.Build();