]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Automatically create invite user with any password
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 20 Jan 2021 22:38:22 +0000 (23:38 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 20 Jan 2021 22:48:11 +0000 (23:48 +0100)
server/lib/oauth-model.ts

index f7ea98b4174cee8854dd827e55319a8b19daff36..624908831f716b250dcacd46e3688fb49a7e2c3e 100644 (file)
@@ -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