From 055cfb11a9d688dbc2dce5c164d1f0b311918378 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Apr 2020 10:19:14 +0200 Subject: Add plugin auth migrations --- server/lib/auth.ts | 40 +++++++++++++++------------- server/lib/plugins/register-helpers-store.ts | 2 ++ 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'server/lib') diff --git a/server/lib/auth.ts b/server/lib/auth.ts index c2a6fcaff..c47ec62d0 100644 --- a/server/lib/auth.ts +++ b/server/lib/auth.ts @@ -126,26 +126,30 @@ async function proxifyPasswordGrant (req: express.Request, res: express.Response authOptions.authName, pluginAuth.npmName, loginOptions.id, authOptions.getWeight() ) - const loginResult = await authOptions.login(loginOptions) - if (loginResult) { - logger.info( - 'Login success with auth method %s of plugin %s for %s.', - authOptions.authName, pluginAuth.npmName, loginOptions.id - ) - - res.locals.bypassLogin = { - bypass: true, - pluginName: pluginAuth.npmName, - authName: authOptions.authName, - user: { - username: loginResult.username, - email: loginResult.email, - role: loginResult.role || UserRole.USER, - displayName: loginResult.displayName || loginResult.username + try { + const loginResult = await authOptions.login(loginOptions) + if (loginResult) { + logger.info( + 'Login success with auth method %s of plugin %s for %s.', + authOptions.authName, pluginAuth.npmName, loginOptions.id + ) + + res.locals.bypassLogin = { + bypass: true, + pluginName: pluginAuth.npmName, + authName: authOptions.authName, + user: { + username: loginResult.username, + email: loginResult.email, + role: loginResult.role || UserRole.USER, + displayName: loginResult.displayName || loginResult.username + } } - } - return + return + } + } catch (err) { + logger.error('Error in auth method %s of plugin %s', authOptions.authName, pluginAuth.npmName, { err }) } } } diff --git a/server/lib/plugins/register-helpers-store.ts b/server/lib/plugins/register-helpers-store.ts index 679ed3650..687974ccf 100644 --- a/server/lib/plugins/register-helpers-store.ts +++ b/server/lib/plugins/register-helpers-store.ts @@ -198,6 +198,8 @@ export class RegisterHelpersStore { return { getSetting: (name: string) => PluginModel.getSetting(this.plugin.name, this.plugin.type, name), + getSettings: (names: string[]) => PluginModel.getSettings(this.plugin.name, this.plugin.type, names), + setSetting: (name: string, value: string) => PluginModel.setSetting(this.plugin.name, this.plugin.type, name, value) } } -- cgit v1.2.3