From 8c355b82df02bc650c5ba101d838121f485e8581 Mon Sep 17 00:00:00 2001 From: ivar Date: Thu, 4 Dec 2025 23:30:39 +0100 Subject: Improve login experience --- api/WhatApi/Endpoints/GetLoginPageEndpoint.cs | 6 ++++-- api/WhatApi/Endpoints/GetMapPageEndpoint.cs | 2 +- api/WhatApi/Endpoints/GetUploadPageEndpoint.cs | 2 +- api/WhatApi/Endpoints/LoginEndpoint.cs | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'api/WhatApi/Endpoints') diff --git a/api/WhatApi/Endpoints/GetLoginPageEndpoint.cs b/api/WhatApi/Endpoints/GetLoginPageEndpoint.cs index dd17669..8b07a0e 100644 --- a/api/WhatApi/Endpoints/GetLoginPageEndpoint.cs +++ b/api/WhatApi/Endpoints/GetLoginPageEndpoint.cs @@ -6,7 +6,9 @@ public class GetLoginPageEndpoint : BaseEndpoint { [AllowAnonymous] [HttpGet("~/login")] - public ActionResult Handle() { - return Content(TemplateFulfiller.WebLoginPage(), "text/html"); + public ActionResult Handle(string? error = null) { + return Content(TemplateFulfiller.WebLoginPage(new TemplateFulfiller.WebLoginModel() { + Error = error ?? string.Empty + }), "text/html"); } } \ No newline at end of file diff --git a/api/WhatApi/Endpoints/GetMapPageEndpoint.cs b/api/WhatApi/Endpoints/GetMapPageEndpoint.cs index 833a98c..bafad6a 100644 --- a/api/WhatApi/Endpoints/GetMapPageEndpoint.cs +++ b/api/WhatApi/Endpoints/GetMapPageEndpoint.cs @@ -6,7 +6,7 @@ public class GetMapPageEndpoint : BaseEndpoint { [HttpGet("~/map")] - public ActionResult GetMapPage() { + public ActionResult Handle() { return Content(TemplateFulfiller.WebMapPage(), "text/html"); } } \ No newline at end of file diff --git a/api/WhatApi/Endpoints/GetUploadPageEndpoint.cs b/api/WhatApi/Endpoints/GetUploadPageEndpoint.cs index ea14819..309fa49 100644 --- a/api/WhatApi/Endpoints/GetUploadPageEndpoint.cs +++ b/api/WhatApi/Endpoints/GetUploadPageEndpoint.cs @@ -6,7 +6,7 @@ public class GetUploadPageEndpoint : BaseEndpoint { [HttpGet("~/upload")] - public ActionResult GetMapPage() { + public ActionResult Handle() { return Content(TemplateFulfiller.WebUploadPage(), "text/html"); } } \ No newline at end of file diff --git a/api/WhatApi/Endpoints/LoginEndpoint.cs b/api/WhatApi/Endpoints/LoginEndpoint.cs index cb76696..470ef34 100644 --- a/api/WhatApi/Endpoints/LoginEndpoint.cs +++ b/api/WhatApi/Endpoints/LoginEndpoint.cs @@ -17,10 +17,10 @@ public class LoginEndpoint(AppDatabase db, IConfiguration configuration) : BaseE [HttpPost("~/login")] public async Task HandleAsync([FromForm] LoginRequest login, CancellationToken ct = default) { var user = await db.Users.FirstOrDefaultAsync(c => c.Name == login.Username, ct); - if (user?.PasswordHash is null) return Unauthorized(); + if (user?.PasswordHash is null) return Redirect("/login?error=Ukjent bruker/passord"); var verificationResult = PasswordHasher.VerifyHashedPassword(user.PasswordHash, login.Password); - if (verificationResult == PasswordVerificationResult.Failed) return Unauthorized(); + if (verificationResult == PasswordVerificationResult.Failed) return Redirect("/login?error=Ukjent bruker/passord"); var tokenEntropy = configuration.GetValue(Constants.Env.TokenEntropy); -- cgit v1.3