Skip to content

Commit

Permalink
#1 switching kaptcha for node-captcha-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Apr 14, 2023
1 parent 972dbb1 commit c1cbdde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions app/controllers/contact.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var brisk = require("brisk"),
kaptcha = require("kaptcha"),
captcha = require("node-captcha-generator"),
Parent = brisk.getBaseController("main"),
Mailer = require("../../index").getHelper("mailer");

Expand All @@ -25,17 +25,18 @@ var controller = Parent.extend({
captcha: function(req, res){

// initiate new capcha
var captcha = kaptcha.generateCode();
var img = kaptcha.generateImage(req, res, { width: 100, height: 30, text: captcha });
var img = new captcha({ length:5, size:{ width: 450, height: 200 }});

// only allow upto 100 simultaneous captchas (to preserve memory)
//if( captchas.length > 100 ) captchas.shift();
if( captchas.length > 100 ) captchas.shift();

// add first param in the list of captcha's
//captchas.push( data[0] );
// add string param in the list of captcha's
captchas.push( img.value );

// return the second param (image blob)
res.end( img );
// return the image blob (base64)
img.toBase64(function(err, data){
res.end( data );
});

},

Expand All @@ -45,7 +46,7 @@ var controller = Parent.extend({
switch( req.method ){
case "POST":
// verify captcha
var valid = (req.session.captcha == req.body.captcha); //verifyCaptcha( req.body );
var valid = verifyCaptcha( req.body ); // (req.session.captcha == req.body.captcha);
// exit now
if( !valid ) {
this._onError(req, res);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"brisk": "1.x.x",
"kaptcha": "1.x.x",
"node-captcha-generator": "0.x.x",
"hbs": "4.0.4",
"nodemailer": "6.2.1",
"nodemailer-ses-transport": "1.5.1"
Expand Down

0 comments on commit c1cbdde

Please sign in to comment.