From fb74f01609b84f1b276df4085bf3827240dc32da Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Mon, 5 Feb 2024 08:44:49 -0700 Subject: [PATCH] added redirectURL --- Controllers/LoginController.cs | 4 ++-- Middleware/Authen.cs | 8 +++++++- Views/Login/Index.cshtml | 8 +++++++- Views/Shared/401.cshtml | 9 ++++++++- wwwroot/js/login.js | 8 +++++++- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Controllers/LoginController.cs b/Controllers/LoginController.cs index 1358dd3..80121fb 100644 --- a/Controllers/LoginController.cs +++ b/Controllers/LoginController.cs @@ -26,9 +26,9 @@ namespace CarCareTracker.Controllers _logger = logger; _loginLogic = loginLogic; } - public IActionResult Index() + public IActionResult Index(string redirectURL = "") { - return View(); + return View(model: redirectURL); } public IActionResult Registration() { diff --git a/Middleware/Authen.cs b/Middleware/Authen.cs index 9de2ddd..7c7b5dc 100644 --- a/Middleware/Authen.cs +++ b/Middleware/Authen.cs @@ -157,7 +157,13 @@ namespace CarCareTracker.Middleware return Task.CompletedTask; } } - Response.Redirect("/Login/Index"); + if (Request.Path.Value == "/Vehicle/Index" && Request.QueryString.HasValue) + { + Response.Redirect($"/Login/Index?redirectURL={Request.Path.Value}{Request.QueryString.Value}"); + } else + { + Response.Redirect("/Login/Index"); + } return Task.CompletedTask; } protected override Task HandleForbiddenAsync(AuthenticationProperties properties) diff --git a/Views/Login/Index.cshtml b/Views/Login/Index.cshtml index b7b1e42..6923a41 100644 --- a/Views/Login/Index.cshtml +++ b/Views/Login/Index.cshtml @@ -1,5 +1,6 @@ @using CarCareTracker.Helper @inject IConfigHelper config +@model string @{ var logoUrl = config.GetLogoUrl(); } @@ -36,4 +37,9 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/Views/Shared/401.cshtml b/Views/Shared/401.cshtml index 6a9e903..8b70feb 100644 --- a/Views/Shared/401.cshtml +++ b/Views/Shared/401.cshtml @@ -1 +1,8 @@ -

Access Denied

\ No newline at end of file +
+
+ +
+
+

Access Denied

+
+
\ No newline at end of file diff --git a/wwwroot/js/login.js b/wwwroot/js/login.js index f88daf9..15ddf9a 100644 --- a/wwwroot/js/login.js +++ b/wwwroot/js/login.js @@ -4,7 +4,13 @@ var isPersistent = $("#inputPersistent").is(":checked"); $.post('/Login/Login', {userName: userName, password: userPassword, isPersistent: isPersistent}, function (data) { if (data) { - window.location.href = '/Home'; + //check for redirectURL + var redirectURL = getRedirectURL().url; + if (redirectURL.trim() != "") { + window.location.href = redirectURL; + } else { + window.location.href = '/Home'; + } } else { errorToast("Invalid Login Credentials, please try again."); }