dev: add can iterate check

This commit is contained in:
KernelDeimos 2024-10-25 14:27:42 -04:00
parent b98c5a349e
commit f3a9e784a3
2 changed files with 17 additions and 1 deletions

View File

@ -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.');

View File

@ -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,
};