mirror of
https://github.com/miawinter98/just-short-it.git
synced 2024-11-21 15:59:55 +00:00
added: base layout and authorization to razor components
This commit is contained in:
parent
dee6653214
commit
9284a8ddfd
|
@ -18,7 +18,9 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<Routes />
|
||||
|
||||
<script src="_framework/blazor.web.js"></script>
|
||||
</body>
|
||||
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
@inherits LayoutComponentBase
|
||||
|
||||
@Body
|
||||
@using JustShortIt.Components.Partials
|
||||
|
||||
<HeaderPartial />
|
||||
|
||||
<main class="flex-1 container mx-auto px-8 py-8 grid">
|
||||
@Body
|
||||
</main>
|
||||
|
||||
<FooterPartial />
|
||||
|
|
8
Components/Partials/FooterPartial.razor
Normal file
8
Components/Partials/FooterPartial.razor
Normal 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>
|
15
Components/Partials/HeaderPartial.razor
Normal file
15
Components/Partials/HeaderPartial.razor
Normal 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>
|
9
Components/Partials/LoginPartial.razor
Normal file
9
Components/Partials/LoginPartial.razor
Normal 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>
|
|
@ -1,6 +1,8 @@
|
|||
<Router AppAssembly="@typeof(Program).Assembly">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="typeof(Layout.MainLayout)" />
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
</Found>
|
||||
</Router>
|
||||
<CascadingAuthenticationState>
|
||||
<Router AppAssembly="@typeof(Program).Assembly">
|
||||
<Found Context="routeData">
|
||||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="typeof(Layout.MainLayout)" />
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
</Found>
|
||||
</Router>
|
||||
</CascadingAuthenticationState>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||
@using Microsoft.JSInterop
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" 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="StackExchange.Redis" Version="2.7.4" />
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
using JustShortIt.Model;
|
||||
using JustShortIt.Service;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Server;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration.AddEnvironmentVariables("JSI_");
|
||||
|
@ -43,7 +45,7 @@
|
|||
}
|
||||
|
||||
// Add Authentication
|
||||
builder.Services.AddSingleton(_ => new AuthenticationService(user));
|
||||
builder.Services.AddScoped(_ => new AuthenticationService(user));
|
||||
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => {
|
||||
options.ExpireTimeSpan = TimeSpan.FromHours(24);
|
||||
options.SlidingExpiration = true;
|
||||
|
@ -51,6 +53,8 @@
|
|||
options.LoginPath = "/Login";
|
||||
options.LogoutPath = "/Logout";
|
||||
});
|
||||
builder.Services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();
|
||||
builder.Services.AddCascadingAuthenticationState();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
Loading…
Reference in a new issue