mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 21:01:10 +00:00
Fixes redirection after authentication
This commit is contained in:
1 parent
5751d3a2f0
commit
805b5deb40
3 files changed
+9
-6
No files matched your search
@@ -10,9 +10,11 @@ namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
/// <param name="Username">The username used to authenticate.</param>
|
||||
/// <param name="Password">The password used to authenticate.</param>
|
||||
/// <param name="TotpCode">The TOTP (Time-Based One-Time Password) code used for two-factor authentication.</param>
|
||||
/// <param name="ReturnUrl">The URL to return to, after login.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
public record LoginRequestModel(
|
||||
string? Username = null,
|
||||
string? Password = null,
|
||||
string? TotpCode = null
|
||||
string? TotpCode = null,
|
||||
string? ReturnUrl = null
|
||||
);
|
||||
@@ -129,11 +129,10 @@ public class AuthController : Controller
|
||||
/// Logs in an account.
|
||||
/// </summary>
|
||||
/// <param name="data">User credentials used for login.</param>
|
||||
/// <param name="returnUrl">The url to return to, after login (if any).</param>
|
||||
[AllowAnonymous]
|
||||
[ValidateAntiForgeryToken]
|
||||
[HttpPost("login")]
|
||||
public async Task<IActionResult> Login([FromBody] LoginRequestModel data, string? returnUrl = null)
|
||||
public async Task<IActionResult> Login([FromBody] LoginRequestModel data)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -158,7 +157,7 @@ public class AuthController : Controller
|
||||
ClaimsIdentity claimsIdentity = new(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
||||
// return success status and redirect URL
|
||||
return Json(new { success = true, data = string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl) ? Url.Content("~/") : Url.Content(returnUrl) });
|
||||
return Json(new { success = true, data = string.IsNullOrEmpty(data.ReturnUrl) || !Url.IsLocalUrl(data.ReturnUrl) ? Url.Content("~/") : Url.Content(data.ReturnUrl) });
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
|
||||
@@ -54,9 +54,10 @@
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" defer>
|
||||
document.getElementById('login-form').addEventListener('submit', async (event) => {
|
||||
document.getElementById('login-form').addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const returnUrlInput = form.querySelector('[name="ReturnUrl"]');
|
||||
const txtUsername = form.querySelector('[name="Username"]');
|
||||
const txtPassword = form.querySelector('[name="Password"]');
|
||||
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
||||
@@ -67,7 +68,8 @@
|
||||
const formData = {
|
||||
Username: txtUsername.value,
|
||||
Password: txtPassword.value,
|
||||
TotpCode: txtTotpCode.value
|
||||
TotpCode: txtTotpCode.value,
|
||||
ReturnUrl: returnUrlInput.value
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("Login", "Auth")', formData);
|
||||
if (data && data.isTotpRequired === true) {
|
||||
|
||||
Reference in new issue
Block a user