From 58ef5833b3f77f321c587dd86448c888029016ce Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Thu, 22 Dec 2022 14:44:26 +0100 Subject: feat: Many things - Working Login/Logout - Groundwork for web components - Loading web-components with version tag - Load temporal-polyfill globally --- code/api/Pages/BasePageModel.cs | 17 +++++++++++++++++ code/api/Pages/Home.cshtml | 4 +--- code/api/Pages/Home.cshtml.cs | 9 +++------ code/api/Pages/Login.cshtml.cs | 2 +- code/api/Pages/_Layout.cshtml | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 code/api/Pages/BasePageModel.cs (limited to 'code/api/Pages') diff --git a/code/api/Pages/BasePageModel.cs b/code/api/Pages/BasePageModel.cs new file mode 100644 index 0000000..7858dc4 --- /dev/null +++ b/code/api/Pages/BasePageModel.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc.Filters; + +namespace I2R.Storage.Api.Pages; + +public class BasePageModel : PageModel +{ + public LoggedInUserModel LoggedInUser => new(User); + public bool IsAutenticated => User.Identity?.IsAuthenticated ?? false; + + public override void OnPageHandlerExecuting(PageHandlerExecutingContext context) { + if (!context.HttpContext.User.Identity?.IsAuthenticated ?? true) { + context.Result = new RedirectResult("/login"); + } + + base.OnPageHandlerExecuting(context); + } +} \ No newline at end of file diff --git a/code/api/Pages/Home.cshtml b/code/api/Pages/Home.cshtml index 457ba2f..b7c07c2 100644 --- a/code/api/Pages/Home.cshtml +++ b/code/api/Pages/Home.cshtml @@ -7,6 +7,4 @@

Welcome

-
-Id: @(HttpContext.User.FindFirst("AppClaims.USER_ID").Value)
-
\ No newline at end of file + \ No newline at end of file diff --git a/code/api/Pages/Home.cshtml.cs b/code/api/Pages/Home.cshtml.cs index 0fa9aca..0d8bcd6 100644 --- a/code/api/Pages/Home.cshtml.cs +++ b/code/api/Pages/Home.cshtml.cs @@ -1,10 +1,7 @@ -using Microsoft.AspNetCore.Mvc.RazorPages; - namespace I2R.Storage.Api.Pages; -public class Home : PageModel +public class Home : BasePageModel { - public void OnGet() { - - } + public Home() : base() { } + public void OnGet() { } } \ No newline at end of file diff --git a/code/api/Pages/Login.cshtml.cs b/code/api/Pages/Login.cshtml.cs index 7d97ff1..90948b6 100644 --- a/code/api/Pages/Login.cshtml.cs +++ b/code/api/Pages/Login.cshtml.cs @@ -3,7 +3,7 @@ namespace I2R.Storage.Api.Pages; public class Login : PageModel { public ActionResult OnGet() { - if (User.Identity.IsAuthenticated) { + if (User.Identity?.IsAuthenticated ?? false) { return Redirect("/home"); } diff --git a/code/api/Pages/_Layout.cshtml b/code/api/Pages/_Layout.cshtml index 022e41e..d587a07 100644 --- a/code/api/Pages/_Layout.cshtml +++ b/code/api/Pages/_Layout.cshtml @@ -9,8 +9,26 @@ @ViewData["Title"] - Storage +@if (User.Identity?.IsAuthenticated ?? false) { +
+ +
+} @RenderBody() + + +@if (User.Identity?.IsAuthenticated ?? false) { + + +} @await RenderSectionAsync("Scripts", false) \ No newline at end of file -- cgit v1.3