+ // Special treatment coming from a plugin
+ if (res.locals.bypassLogin && res.locals.bypassLogin.bypass === true) {
+ const obj = res.locals.bypassLogin
+ logger.info('Bypassing oauth login by plugin %s.', obj.pluginName)
+
+ let user = await UserModel.loadByEmail(obj.user.email)
+ if (!user) user = await createUserFromExternal(obj.pluginName, obj.user)
+
+ // Cannot create a user
+ if (!user) throw new AccessDeniedError('Cannot create such user: an actor with that name already exists.')
+
+ // If the user does not belongs to a plugin, it was created before its installation
+ // Then we just go through a regular login process
+ if (user.pluginAuth !== null) {
+ // This user does not belong to this plugin, skip it
+ if (user.pluginAuth !== obj.pluginName) return null
+
+ return user
+ }
+ }
+
+ logger.debug('Getting User (username/email: ' + usernameOrEmail + ', password: ******).')
+
+ const user = await UserModel.loadByUsernameOrEmail(usernameOrEmail)
+ // If we don't find the user, or if the user belongs to a plugin
+ if (!user || user.pluginAuth !== null || !password) return null