Added 'altcha' captcha system for account and channel creation.

This commit is contained in:
rainbow napkin 2024-12-26 06:09:49 -05:00
parent 60801f0dc2
commit e0f53df176
20 changed files with 326 additions and 55 deletions

View file

@ -20,6 +20,7 @@ const {validationResult, matchedData} = require('express-validator');
//local imports
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils');
const {userModel} = require('../../../schemas/userSchema');
const altchaUtils = require('../../../utils/altchaUtils');
const channelModel = require('../../../schemas/channel/channelSchema');
//api account functions
@ -32,6 +33,15 @@ module.exports.post = async function(req, res){
if(validResult.isEmpty()){
//Set channel object from sanatized/validated data, and get user document from session data
const channel = matchedData(req);
//Verify Altcha Payload
const verified = await altchaUtils.verify(req.body.verification);
//If altcha verification failed
if(!verified){
return errorHandler(res, 'Altcha verification failed, Please refresh the page!', 'unauthorized');
}
//Find current user
const userDB = await userModel.findOne({user: req.session.user.user});
//register new channel with requesting user as owner