45 lines
2.2 KiB
JavaScript
45 lines
2.2 KiB
JavaScript
/*Canopy - The next generation of stoner streaming software
|
|
Copyright (C) 2024-2025 Rainbownapkin and the TTN Community
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|
|
|
//NPM Imports
|
|
const { check, body, checkSchema, checkExact} = require('express-validator');
|
|
|
|
//local imports
|
|
const {isRank} = require('./permissionsValidator');
|
|
|
|
module.exports = {
|
|
user: (field = 'user') => check(field).escape().trim().isAlphanumeric().isLength({min: 1, max: 22}),
|
|
|
|
//Password security requirements may change over time, therefore we should only validate against strongPassword() when creating new accounts
|
|
//that way we don't break old ones upon change
|
|
pass: (field = 'pass') => body(field).notEmpty().escape().trim(),
|
|
securePass: (field) => module.exports.pass(field).isStrongPassword({minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1}),
|
|
|
|
email: (field = 'email') => body(field).optional().isEmail().normalizeEmail(),
|
|
|
|
img: (field = 'img') => body(field).optional().isURL({require_tld: false, require_host: false}).trim(),
|
|
|
|
//Length check before escaping to keep symbols from throwing the count
|
|
pronouns: (field = 'pronouns') => body(field).optional().trim().isLength({min: 0, max: 15}).escape(),
|
|
|
|
signature: (field = 'signature') => body(field).optional().trim().isLength({min: 1, max: 25}).escape(),
|
|
|
|
bio: (field = 'bio') => body(field).optional().trim().isLength({min: 1, max: 1000}).escape(),
|
|
|
|
rank: (field = 'rank') => body(field).escape().trim().custom(isRank),
|
|
|
|
securityToken: (field = 'token') => check(field).escape().trim().isHexadecimal().isLength({min:32, max:32})
|
|
} |