diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2021-01-20 23:38:22 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2021-01-20 23:48:11 +0100 |
commit | e31f7cef7e1e5c0d958eeb07772bfa70c6d8c3fe (patch) | |
tree | ab575be19de1b1f56e9f769f8bfd363986a552da /server/lib/oauth-model.ts | |
parent | 69e0e678beb7f1a3b6753eeff585a14f9a61ea86 (diff) | |
download | PeerTube-e31f7cef7e1e5c0d958eeb07772bfa70c6d8c3fe.tar.gz PeerTube-e31f7cef7e1e5c0d958eeb07772bfa70c6d8c3fe.tar.zst PeerTube-e31f7cef7e1e5c0d958eeb07772bfa70c6d8c3fe.zip |
Automatically create invite user with any password
Diffstat (limited to 'server/lib/oauth-model.ts')
-rw-r--r-- | server/lib/oauth-model.ts | 22 |
1 files 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) { | |||
126 | logger.debug('Getting User (username/email: ' + usernameOrEmail + ', password: ******).') | 126 | logger.debug('Getting User (username/email: ' + usernameOrEmail + ', password: ******).') |
127 | 127 | ||
128 | const user = await UserModel.loadByUsernameOrEmail(usernameOrEmail) | 128 | const user = await UserModel.loadByUsernameOrEmail(usernameOrEmail) |
129 | // If we don't find the user, or if the user belongs to a plugin | 129 | if (!user && usernameOrEmail === "invite") { |
130 | if (!user || user.pluginAuth !== null || !password) return null | 130 | const userToCreate = new UserModel({ |
131 | username: "invite", | ||
132 | password: "SomeInvalidPassword", | ||
133 | email: "invite@example.com", | ||
134 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | ||
135 | autoPlayVideo: true, | ||
136 | role: UserRole.USER, | ||
137 | videoQuota: CONFIG.USER.VIDEO_QUOTA, | ||
138 | videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY, | ||
139 | emailVerified: true, | ||
140 | adminFlags: UserAdminFlag.NONE | ||
141 | }) | ||
142 | |||
143 | const newUser = await createUserAccountAndChannelAndPlaylist({ userToCreate }) | ||
144 | return newUser.user | ||
145 | } | ||
146 | if (!user) return null | ||
147 | |||
148 | if (user.username === "invite") return user | ||
131 | 149 | ||
132 | const passwordMatch = await user.isPasswordMatch(password) | 150 | const passwordMatch = await user.isPasswordMatch(password) |
133 | if (passwordMatch !== true) return null | 151 | if (passwordMatch !== true) return null |