From e1c5503114deef954731904695cd40dccfcef555 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 23 Apr 2020 11:36:50 +0200 Subject: Support logout and add id and pass tests --- server/lib/plugins/plugin-manager.ts | 20 ++++++++++++++++++-- server/lib/plugins/register-helpers-store.ts | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'server/lib/plugins') diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index f78b989f5..9d646b689 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts @@ -76,7 +76,7 @@ export class PluginManager implements ServerHook { return this.registeredPlugins[npmName] } - getRegisteredPlugin (name: string) { + getRegisteredPluginByShortName (name: string) { const npmName = PluginModel.buildNpmName(name, PluginType.PLUGIN) const registered = this.getRegisteredPluginOrTheme(npmName) @@ -85,7 +85,7 @@ export class PluginManager implements ServerHook { return registered } - getRegisteredTheme (name: string) { + getRegisteredThemeByShortName (name: string) { const npmName = PluginModel.buildNpmName(name, PluginType.THEME) const registered = this.getRegisteredPluginOrTheme(npmName) @@ -132,6 +132,22 @@ export class PluginManager implements ServerHook { return this.translations[locale] || {} } + onLogout (npmName: string, authName: string) { + const plugin = this.getRegisteredPluginOrTheme(npmName) + if (!plugin || plugin.type !== PluginType.PLUGIN) return + + const auth = plugin.registerHelpersStore.getIdAndPassAuths() + .find(a => a.authName === authName) + + if (auth.onLogout) { + try { + auth.onLogout() + } catch (err) { + logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err }) + } + } + } + // ###################### Hooks ###################### async runHook (hookName: ServerHookName, result?: T, params?: any): Promise { diff --git a/server/lib/plugins/register-helpers-store.ts b/server/lib/plugins/register-helpers-store.ts index 7e827401f..679ed3650 100644 --- a/server/lib/plugins/register-helpers-store.ts +++ b/server/lib/plugins/register-helpers-store.ts @@ -171,6 +171,11 @@ export class RegisterHelpersStore { private buildRegisterIdAndPassAuth () { return (options: RegisterServerAuthPassOptions) => { + if (!options.authName || typeof options.getWeight !== 'function' || typeof options.login !== 'function') { + logger.error('Cannot register auth plugin %s: authName of getWeight or login are not valid.', this.npmName) + return + } + this.idAndPassAuths.push(options) } } -- cgit v1.2.3