mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Merge pull request #71 from BinaryAlley/bugfix/fix-redirection-after-authentication
Fixes redirection after authentication
This commit is contained in:
3 files changed
+8
-5
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="Username">The username used to authenticate.</param>
|
||||||
/// <param name="Password">The password 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="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}")]
|
[DebuggerDisplay("Username: {Username}")]
|
||||||
public record LoginRequestModel(
|
public record LoginRequestModel(
|
||||||
string? Username = null,
|
string? Username = null,
|
||||||
string? Password = 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.
|
/// Logs in an account.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">User credentials used for login.</param>
|
/// <param name="data">User credentials used for login.</param>
|
||||||
/// <param name="returnUrl">The url to return to, after login (if any).</param>
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
[HttpPost("login")]
|
[HttpPost("login")]
|
||||||
public async Task<IActionResult> Login([FromBody] LoginRequestModel data, string? returnUrl = null)
|
public async Task<IActionResult> Login([FromBody] LoginRequestModel data)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -158,7 +157,7 @@ public class AuthController : Controller
|
|||||||
ClaimsIdentity claimsIdentity = new(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
ClaimsIdentity claimsIdentity = new(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
||||||
// return success status and redirect URL
|
// 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)
|
catch (ApiException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
document.getElementById('login-form').addEventListener('submit', async (event) => {
|
document.getElementById('login-form').addEventListener('submit', async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = event.target;
|
const form = event.target;
|
||||||
|
const returnUrlInput = form.querySelector('[name="ReturnUrl"]');
|
||||||
const txtUsername = form.querySelector('[name="Username"]');
|
const txtUsername = form.querySelector('[name="Username"]');
|
||||||
const txtPassword = form.querySelector('[name="Password"]');
|
const txtPassword = form.querySelector('[name="Password"]');
|
||||||
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
||||||
@@ -67,7 +68,8 @@
|
|||||||
const formData = {
|
const formData = {
|
||||||
Username: txtUsername.value,
|
Username: txtUsername.value,
|
||||||
Password: txtPassword.value,
|
Password: txtPassword.value,
|
||||||
TotpCode: txtTotpCode.value
|
TotpCode: txtTotpCode.value,
|
||||||
|
ReturnUrl: returnUrlInput.value
|
||||||
};
|
};
|
||||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("Login", "Auth")', formData);
|
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("Login", "Auth")', formData);
|
||||||
if (data && data.isTotpRequired === true) {
|
if (data && data.isTotpRequired === true) {
|
||||||
|
|||||||
Reference in new issue
Block a user