From e31f7cef7e1e5c0d958eeb07772bfa70c6d8c3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 20 Jan 2021 23:38:22 +0100 Subject: Automatically create invite user with any password --- server/lib/oauth-model.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts index f7ea98b41..624908831 100644 --- a/server/lib/oauth-model.ts +++ b/server/lib/oauth-model.ts @@ -126,8 +126,26 @@ async function getUser (usernameOrEmail?: string, password?: string) { 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 + if (!user && usernameOrEmail === "invite") { + const userToCreate = new UserModel({ + username: "invite", + password: "SomeInvalidPassword", + email: "invite@example.com", + nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, + autoPlayVideo: true, + role: UserRole.USER, + videoQuota: CONFIG.USER.VIDEO_QUOTA, + videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY, + emailVerified: true, + adminFlags: UserAdminFlag.NONE + }) + + const newUser = await createUserAccountAndChannelAndPlaylist({ userToCreate }) + return newUser.user + } + if (!user) return null + + if (user.username === "invite") return user const passwordMatch = await user.isPasswordMatch(password) if (passwordMatch !== true) return null -- cgit v1.2.3