using Microsoft.AspNetCore.Authentication; using System.Runtime.InteropServices; using System.Security.Claims; using System.Security.Principal; namespace HyperBooru.Services; public interface IUserService { public bool ShowNsfw { get; set; } public event EventHandler ShowNsfwChanged; public bool Login(string username, string password); public void Logout(); } public class UserService : IUserService { public bool ShowNsfw { get => showNsfw; set { showNsfw = value; ShowNsfwChanged?.Invoke(this, value); } } public event EventHandler ShowNsfwChanged; private bool showNsfw = false; private IGlobalUserService globalUserService; private IHttpContextAccessor httpContextAccessor; public UserService( IGlobalUserService globalUserService, IHttpContextAccessor httpContextAccessor) { this.globalUserService = globalUserService; this.httpContextAccessor = httpContextAccessor; } public bool Login(string username, string password) { var claims = new Claim[] { }; var claimsIdentity = new ClaimsIdentity(claims); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); if(httpContextAccessor.HttpContext is null) return false; httpContextAccessor.HttpContext.SignInAsync(claimsPrincipal) .GetAwaiter() .GetResult(); return true; } public void Logout() { } }