diff --git a/src/backend/src/routers/signup.js b/src/backend/src/routers/signup.js index 4aa7fa6c..06f7905e 100644 --- a/src/backend/src/routers/signup.js +++ b/src/backend/src/routers/signup.js @@ -24,6 +24,7 @@ const config = require('../config'); const eggspress = require('../api/eggspress'); const { Context } = require('../util/context'); const { DB_WRITE } = require('../services/database/consts'); +const { can } = require('../util/langutil'); // -----------------------------------------------------------------------// // POST /signup @@ -146,7 +147,7 @@ module.exports = eggspress(['/signup'], { const svc_cleanEmail = req.services.get('clean-email'); const clean_email = svc_cleanEmail.clean(req.body.email); - if ( config.blocked_email_domains ) { + if ( can(config.blocked_email_domains, 'iterate') ) { for ( const suffix of config.blocked_email_domains ) { if ( clean_email.endsWith(suffix) ) { return res.status(400).send('This email domain is not allowed.'); diff --git a/src/backend/src/util/langutil.js b/src/backend/src/util/langutil.js index ceea451f..443dc2f1 100644 --- a/src/backend/src/util/langutil.js +++ b/src/backend/src/util/langutil.js @@ -28,7 +28,22 @@ const whatis = thing => { const nou = v => v === null || v === undefined; +const can = (v, ...checking) => { + if ( nou(v) ) return false; + const capabilities = {}; + if ( v[Symbol.iterator] ) { + capabilities['iterate'] = true; + } + for ( const to_check of checking ) { + if ( ! capabilities[to_check] ) { + return false; + } + } + return true; +} + module.exports = { whatis, nou, + can, };