+async function getUser (usernameOrEmail?: string, password?: string) {
+ const res: express.Response = this.request.res
+
+ // 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
+ }
+ }
+