diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-09-29 05:01:45 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-09-29 05:33:04 +1000 |
| commit | 76e4bf609c3d196bd20619188a317fca66f4a04a (patch) | |
| tree | 8d6544efc82782f2417f39f31fd05aa76e68316e /PrincipalProviders | |
| parent | bedcb6b176130fc2c6bd4657c8af4d407b64c970 (diff) | |
Separated Principal and LocalPrincipal types
Diffstat (limited to 'PrincipalProviders')
| -rw-r--r-- | PrincipalProviders/LocalPrincipalProvider.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/PrincipalProviders/LocalPrincipalProvider.cs b/PrincipalProviders/LocalPrincipalProvider.cs new file mode 100644 index 0000000..7bee800 --- /dev/null +++ b/PrincipalProviders/LocalPrincipalProvider.cs @@ -0,0 +1,49 @@ +using HyperBooru.Services; +using Microsoft.EntityFrameworkCore; + +namespace HyperBooru.PrincipalProviders; + +public class LocalPrincipalProvider : PrincipalProvider { + private IDbContextFactory<HBContext> dbFactory; + + public LocalPrincipalProvider(IDbContextFactory<HBContext> dbFactory) => + this.dbFactory = dbFactory; + + public override Principal? GetPrincipal(string name) { + using var db = dbFactory.CreateDbContext(); + + LocalPrincipal? principal = db.Principals.FirstOrDefault(p => p.Name == name); + if(principal is null) + return null; + + return principal; + } + + public override User? GetUser(string name) { + using var db = dbFactory.CreateDbContext(); + + LocalUser? user = db.Users.FirstOrDefault(p => p.Name == name); + if(user is null) + return null; + + return user; + } + + public override Group? GetGroup(string name) { + using var db = dbFactory.CreateDbContext(); + + LocalGroup? group = db.Groups.FirstOrDefault(p => p.Name == name); + if(group is null) + return null; + + return group; + } + + public override Group[] GetGroups(Principal principal, bool recurse) { + throw new NotImplementedException(); + } + + public override bool ValidatePassword(User principal, string password) { + throw new NotImplementedException(); + } +} |
