X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fsignup.ts;h=8fa81e601d7a712e314dd036a2151648ee8f8353;hb=2539932e16129992a2c0889b4ff527c265a8e2c7;hp=5eb56b3cf6c2779e065b90edbc89aef45a360721;hpb=6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/signup.ts b/server/helpers/signup.ts index 5eb56b3cf..8fa81e601 100644 --- a/server/helpers/signup.ts +++ b/server/helpers/signup.ts @@ -1,27 +1,29 @@ -import { UserModel } from '../models/account/user' +import { UserModel } from '../models/user/user' import * as ipaddr from 'ipaddr.js' import { CONFIG } from '../initializers/config' const isCidr = require('is-cidr') -async function isSignupAllowed () { +async function isSignupAllowed (): Promise<{ allowed: boolean, errorMessage?: string }> { if (CONFIG.SIGNUP.ENABLED === false) { - return false + return { allowed: false } } // No limit and signup is enabled if (CONFIG.SIGNUP.LIMIT === -1) { - return true + return { allowed: true } } const totalUsers = await UserModel.countTotal() - return totalUsers < CONFIG.SIGNUP.LIMIT + return { allowed: totalUsers < CONFIG.SIGNUP.LIMIT } } function isSignupAllowedForCurrentIP (ip: string) { + if (!ip) return false + const addr = ipaddr.parse(ip) - let excludeList = [ 'blacklist' ] + const excludeList = [ 'blacklist' ] let matched = '' // if there is a valid, non-empty whitelist, we exclude all unknown adresses too