Cleaned up validators and browser-side ajax utils
This commit is contained in:
parent
8a4a21cff0
commit
cf55be21eb
8 changed files with 79 additions and 35 deletions
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
const { Router } = require('express');
|
||||
|
||||
//local imports
|
||||
const {accountValidator} = require("../../utils/validators");
|
||||
const accountValidator = require("../../validators/accountValidator");
|
||||
const loginController = require("../../controllers/api/account/loginController");
|
||||
const logoutController = require("../../controllers/api/account/logoutController");
|
||||
const registerController = require("../../controllers/api/account/registerController");
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const { Router } = require('express');
|
|||
|
||||
|
||||
//local imports
|
||||
const {accountValidator} = require("../../utils/validators");
|
||||
const accountValidator = require("../../validators/accountValidator");
|
||||
const permissionSchema = require("../../schemas/permissionSchema");
|
||||
const listUsersController = require("../../controllers/api/admin/listUsersController");
|
||||
const listChannelsController = require("../../controllers/api/admin/listChannelsController");
|
||||
|
|
@ -29,7 +29,7 @@ const changeRankController = require("../../controllers/api/admin/changeRankCont
|
|||
const router = Router();
|
||||
|
||||
//Use authentication middleware
|
||||
router.use(permissionSchema.reqPermCheck("adminPanel"))
|
||||
router.use(permissionSchema.reqPermCheck("adminAPI"));
|
||||
|
||||
//routing functions
|
||||
router.get('/listUsers', listUsersController.get);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const { Router } = require('express');
|
|||
|
||||
//local imports
|
||||
const permissionSchema = require("../../schemas/permissionSchema");
|
||||
const {channelValidator} = require("../../utils/validators");
|
||||
const channelValidator = require("../../validators/channelValidator");
|
||||
const registerController = require("../../controllers/api/channel/registerController");
|
||||
const listController = require("../../controllers/api/channel/listController");
|
||||
const settingsController = require("../../controllers/api/channel/settingsController");
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@ const permissionSchema = new mongoose.Schema({
|
|||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
adminAPI: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
registerChannel: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ function isRank(value){
|
|||
return rankVal != -1;
|
||||
}
|
||||
|
||||
module.exports.accountValidator = {
|
||||
module.exports = {
|
||||
user: (field = 'user') => body(field).escape().trim().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) => this.accountValidator.pass(field).isStrongPassword({minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1}),
|
||||
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(),
|
||||
|
||||
|
|
@ -43,19 +43,4 @@ module.exports.accountValidator = {
|
|||
bio: (field = 'bio') => body(field).optional().escape().trim().isLength({min: 1, max: 1000}),
|
||||
|
||||
rank: (field = 'rank') => body(field).escape().trim().custom(isRank)
|
||||
}
|
||||
|
||||
module.exports.channelValidator = {
|
||||
name: (field = 'name') => check(field).escape().trim().isLength({min: 1, max: 50}),
|
||||
|
||||
description: (field = 'description') => body(field).escape().trim().isLength({min: 1, max: 1000}),
|
||||
|
||||
thumbnail: (field = 'thumbnail') => this.accountValidator.img(field),
|
||||
|
||||
settingsMap: () => checkExact(checkSchema({
|
||||
'settingsMap.hidden': {
|
||||
optional: true,
|
||||
isBoolean: true,
|
||||
}
|
||||
}))
|
||||
}
|
||||
36
src/validators/channelValidator.js
Normal file
36
src/validators/channelValidator.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*Canopy - The next generation of stoner streaming software
|
||||
Copyright (C) 2024 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 accountValidator = require('./accountValidator');
|
||||
|
||||
module.exports = {
|
||||
name: (field = 'name') => check(field).escape().trim().isLength({min: 1, max: 50}),
|
||||
|
||||
description: (field = 'description') => body(field).escape().trim().isLength({min: 1, max: 1000}),
|
||||
|
||||
thumbnail: (field = 'thumbnail') => accountValidator.img(field),
|
||||
|
||||
settingsMap: () => checkExact(checkSchema({
|
||||
'settingsMap.hidden': {
|
||||
optional: true,
|
||||
isBoolean: true,
|
||||
}
|
||||
}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue