diff options
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Accounts/src/AccountsEntryPoint.cs')
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.Accounts/src/AccountsEntryPoint.cs | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Accounts/src/AccountsEntryPoint.cs b/plugins/VNLib.Plugins.Essentials.Accounts/src/AccountsEntryPoint.cs index f4401a9..005953f 100644 --- a/plugins/VNLib.Plugins.Essentials.Accounts/src/AccountsEntryPoint.cs +++ b/plugins/VNLib.Plugins.Essentials.Accounts/src/AccountsEntryPoint.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Accounts @@ -25,14 +25,17 @@ using System; using System.Linq; using System.Collections.Generic; +using System.ComponentModel.Design; using VNLib.Utils.Memory; using VNLib.Utils.Logging; +using VNLib.Plugins.Attributes; using VNLib.Plugins.Essentials.Users; using VNLib.Plugins.Essentials.Accounts.Endpoints; using VNLib.Plugins.Extensions.Loading; using VNLib.Plugins.Extensions.Loading.Users; using VNLib.Plugins.Extensions.Loading.Routing; +using VNLib.Plugins.Essentials.Accounts.SecurityProvider; namespace VNLib.Plugins.Essentials.Accounts { @@ -41,34 +44,44 @@ namespace VNLib.Plugins.Essentials.Accounts public override string PluginName => "Essentials.Accounts"; - protected override void OnLoad() + private IAccountSecurityProvider? _securityProvider; + + [ServiceConfigurator] + public void ConfigureServices(IServiceContainer services) { - try + //Export the build in security provider + if (_securityProvider != null) { - //Route endpoints - this.Route<LoginEndpoint>(); + services.AddService(typeof(IAccountSecurityProvider), _securityProvider); + } + } - this.Route<LogoutEndpoint>(); + protected override void OnLoad() + { + //Route endpoints + this.Route<LoginEndpoint>(); - this.Route<KeepAliveEndpoint>(); + this.Route<LogoutEndpoint>(); - this.Route<ProfileEndpoint>(); + this.Route<KeepAliveEndpoint>(); - this.Route<PasswordChangeEndpoint>(); + this.Route<ProfileEndpoint>(); - this.Route<MFAEndpoint>(); + this.Route<PasswordChangeEndpoint>(); - //Write loaded to log - Log.Information("Plugin loaded"); - } - catch (KeyNotFoundException knf) - { - Log.Error("Missing required account configuration variables {mess}", knf.Message); - } - catch (UriFormatException uri) + this.Route<MFAEndpoint>(); + + //Only export the account security service if the configuration element is defined + if (this.HasConfigForType<AccountSecProvider>()) { - Log.Error("Invalid endpoint URI {message}", uri.Message); + //Inint the security provider + _securityProvider = this.GetOrCreateSingleton<AccountSecProvider>(); + + Log.Information("Configuring the account security provider service"); } + + //Write loaded to log + Log.Information("Plugin loaded"); } @@ -88,8 +101,8 @@ namespace VNLib.Plugins.Essentials.Accounts } try { - IUserManager Users = this.GetUserManager(); - PasswordHashing Passwords = this.GetPasswords(); + IUserManager Users = this.GetOrCreateSingleton<UserManager>(); + IPasswordHashingProvider Passwords = this.GetPasswords(); //get args as a list List<string> args = cmd.Split(' ').ToList(); |