feat: add user management, refs NOISSUE

This commit is contained in:
2025-05-17 22:17:09 +02:00
parent 6b9c383697
commit efbbc915e5
17 changed files with 908 additions and 97 deletions

View File

@@ -0,0 +1,40 @@
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication;
public class AuthController : Controller
{
[HttpPost]
public async Task<IActionResult> Login(string username, string password)
{
var ldapService = HttpContext.RequestServices.GetService<LdapAuthenticationService>();
if (ldapService.Authenticate(username, password))
{
var claims = new[] { new Claim(ClaimTypes.Name, username) };
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignInAsync(new ClaimsPrincipal(identity));
return RedirectToSamePageIfPossible();
}
ViewBag.Error = "Invalid credentials";
return RedirectToSamePageIfPossible();
}
[HttpPost]
public async Task<IActionResult> Logout()
{
await HttpContext.SignOutAsync();
return RedirectToSamePageIfPossible();
}
private IActionResult RedirectToSamePageIfPossible()
{
if (Request.Headers.ContainsKey("Referer"))
{
return Redirect(Request.Headers["Referer"].ToString());
}
return RedirectToPage("/");
}
}