added alphabet setting
This commit is contained in:
parent
ceb8642365
commit
044f4094f0
|
@ -10,4 +10,6 @@ APP_PORT=3000
|
||||||
CAPTCHA_SOURCE_URL=https://example.com
|
CAPTCHA_SOURCE_URL=https://example.com
|
||||||
DATA_DIR=/opt/captcha_aggregator
|
DATA_DIR=/opt/captcha_aggregator
|
||||||
ADMIN_TOKEN=GENERATE_A_STRONG_TOKEN_HERE
|
ADMIN_TOKEN=GENERATE_A_STRONG_TOKEN_HERE
|
||||||
SECRET=GENERATE_A_STRONG_SECRET_HERE
|
SECRET=GENERATE_A_STRONG_SECRET_HERE
|
||||||
|
#Allowed symbols. Must be a regex
|
||||||
|
ALPHABET="[123456789ABCDEFGHIJKLMNPQRSTUVWXZY]"
|
|
@ -16,7 +16,8 @@ const config = {
|
||||||
captcha_source_url: process.env.CAPTCHA_SOURCE_URL,
|
captcha_source_url: process.env.CAPTCHA_SOURCE_URL,
|
||||||
data_dir: process.env.DATA_DIR,
|
data_dir: process.env.DATA_DIR,
|
||||||
admin_token: process.env.ADMIN_TOKEN,
|
admin_token: process.env.ADMIN_TOKEN,
|
||||||
secret: process.env.SECRET
|
secret: process.env.SECRET,
|
||||||
|
alphabet: process.env.ALPHABET
|
||||||
}
|
}
|
||||||
|
|
||||||
export default config;
|
export default config;
|
|
@ -1,11 +1,19 @@
|
||||||
import CaptchaService from "../services/captcha.js";
|
import CaptchaService from "../services/captcha.js";
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
|
import config from '../config.js';
|
||||||
|
|
||||||
class CaptchaController {
|
class CaptchaController {
|
||||||
async submit(req, res) {
|
async submit(req, res) {
|
||||||
const {image, solution} = req.body;
|
const {image, solution} = req.body;
|
||||||
if (!image) return res.status(400).send({"message":"You must send image blob"});
|
if (!image) return res.status(400).send({"message":"You must send image blob"});
|
||||||
if (!solution || solution.length != 6) return res.status(400).send({"message":"You must send a valid solution"});
|
if (!solution || solution.length != 6) return res.status(400).send({"message":"You must send a valid solution"});
|
||||||
|
for (let i = 0; i < solution.length; i ++) {
|
||||||
|
let char = solution[i];
|
||||||
|
if (!char.match(config.alphabet)) {
|
||||||
|
console.log("Illegal symbol: " + char);
|
||||||
|
return res.status(400).send({"message": `Illegal symbol ${char} at position ${i + 1}`});
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await CaptchaService.new(image, solution, jwt.decode(req.token).id);
|
await CaptchaService.new(image, solution, jwt.decode(req.token).id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue