summaryrefslogtreecommitdiff
path: root/Services
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2023-09-13 16:01:02 +1000
committerJake Mannens <jake@asger.xyz>2023-09-13 16:01:02 +1000
commite6e43b943143d55581ef442b61ed6cbdbb40c642 (patch)
tree82dc5ba12d2761baf8b9290804d3481cdf4eb4cb /Services
parentbd46d1ff8f2bbe43a92e935aafadc1a63b3a1a5b (diff)
Added logon page
Diffstat (limited to 'Services')
-rw-r--r--Services/GlobalUserService.cs7
-rw-r--r--Services/UserService.cs42
2 files changed, 48 insertions, 1 deletions
diff --git a/Services/GlobalUserService.cs b/Services/GlobalUserService.cs
new file mode 100644
index 0000000..adafce2
--- /dev/null
+++ b/Services/GlobalUserService.cs
@@ -0,0 +1,7 @@
+namespace HyperBooru.Services;
+
+public interface IGlobalUserService {
+}
+
+public class GlobalUserService : IGlobalUserService {
+}
diff --git a/Services/UserService.cs b/Services/UserService.cs
index d2abea3..db62553 100644
--- a/Services/UserService.cs
+++ b/Services/UserService.cs
@@ -1,9 +1,17 @@
-namespace HyperBooru.Services;
+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<bool> ShowNsfwChanged;
+
+ public bool Login(string username, string password);
+ public void Logout();
}
public class UserService : IUserService {
@@ -18,4 +26,36 @@ public class UserService : IUserService {
public event EventHandler<bool> 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() {
+ }
}