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 }
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')
}