aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/Pages
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-12-22 14:44:26 +0100
committerivarlovlie <git@ivarlovlie.no>2022-12-22 14:44:26 +0100
commit58ef5833b3f77f321c587dd86448c888029016ce (patch)
treefe5e6f47781573cc1fb5938f9b8cd8b51022946a /code/api/Pages
parent82ade3c31fb17b662feec59e9e654ceb66edbb7a (diff)
downloadstorage-58ef5833b3f77f321c587dd86448c888029016ce.tar.xz
storage-58ef5833b3f77f321c587dd86448c888029016ce.zip
feat: Many things
- Working Login/Logout - Groundwork for web components - Loading web-components with version tag - Load temporal-polyfill globally
Diffstat (limited to 'code/api/Pages')
-rw-r--r--code/api/Pages/BasePageModel.cs17
-rw-r--r--code/api/Pages/Home.cshtml4
-rw-r--r--code/api/Pages/Home.cshtml.cs9
-rw-r--r--code/api/Pages/Login.cshtml.cs2
-rw-r--r--code/api/Pages/_Layout.cshtml18
5 files changed, 40 insertions, 10 deletions
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 @@
<h1>Welcome</h1>
-<pre>
-Id: @(HttpContext.User.FindFirst("AppClaims.USER_ID").Value)
-</pre> \ No newline at end of file
+<button class="do-logout">Logout</button> \ 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 @@
<title>@ViewData["Title"] - Storage</title>
</head>
<body>
+@if (User.Identity?.IsAuthenticated ?? false) {
+ <header>
+ <nav>
+ <div class="left">
+ <a href="/home">Home</a>
+ </div>
+ <div class="right">
+ <profile-modal/>
+ </div>
+ </nav>
+ </header>
+}
@RenderBody()
+<script src="~/scripts/module.mjs" asp-append-version="true" type="module"></script>
+<script src="~/scripts/helpers.js" asp-append-version="true"></script>
<script src="~/scripts/base.js" asp-append-version="true"></script>
+@if (User.Identity?.IsAuthenticated ?? false) {
+ <script src="~/scripts/logged-in-base.js" asp-append-version="true"></script>
+ <script src="~/scripts/components/index.js" asp-append-version="true"></script>
+}
@await RenderSectionAsync("Scripts", false)
</body>
</html> \ No newline at end of file