]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/signup.ts
Add test on AP hooks
[github/Chocobozzz/PeerTube.git] / server / lib / signup.ts
index 3c1397a1287681c90458ee20041905eee0402f8e..f19232621aa4e792db390d769cd11c2cb508ee4b 100644 (file)
@@ -4,11 +4,24 @@ import { UserModel } from '../models/user/user'
 
 const isCidr = require('is-cidr')
 
-async function isSignupAllowed (): Promise<{ allowed: boolean, errorMessage?: string }> {
+export type SignupMode = 'direct-registration' | 'request-registration'
+
+async function isSignupAllowed (options: {
+  signupMode: SignupMode
+
+  ip: string // For plugins
+  body?: any
+}): Promise<{ allowed: boolean, errorMessage?: string }> {
+  const { signupMode } = options
+
   if (CONFIG.SIGNUP.ENABLED === false) {
     return { allowed: false }
   }
 
+  if (signupMode === 'direct-registration' && CONFIG.SIGNUP.REQUIRES_APPROVAL === true) {
+    return { allowed: false }
+  }
+
   // No limit and signup is enabled
   if (CONFIG.SIGNUP.LIMIT === -1) {
     return { allowed: true }
@@ -26,7 +39,7 @@ function isSignupAllowedForCurrentIP (ip: string) {
   const excludeList = [ 'blacklist' ]
   let matched = ''
 
-  // if there is a valid, non-empty whitelist, we exclude all unknown adresses too
+  // if there is a valid, non-empty whitelist, we exclude all unknown addresses too
   if (CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr(cidr)).length > 0) {
     excludeList.push('unknown')
   }