mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
dev: add can iterate check
This commit is contained in:
parent
b98c5a349e
commit
f3a9e784a3
@ -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.');
|
||||
|
@ -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,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user