node.js - nodejs - 如何使用 Node 验证码模块?

标签 node.js captcha

我已经从以下链接安装了 node-captcha nodejs 模块...

https://github.com/napa3um/node-captcha

网站给出的例子如下...

...
var captcha = require('captcha');
...
app.configure(function(){
...
    app.use(app.router);
    app.use(captcha('/captcha.jpg')); // url for captcha jpeg
    app.use(express.static(__dirname + '/public'));
...

app 对象在 express 中使用,但我没有使用 express。

我一直在尝试通过在“http.createServer”函数中调用“captcha('/captcha.jpg')”来让验证码正常工作,但没有任何反应。

我真的很困惑如何使用这个模块。

最佳答案

设法编写了一个使用该模块的脚本。

另外 req.session.captcha = text 应该在模块的 captcha.js 文件中注释掉,否则会抛出错误。注释掉该代码确实意味着它应该被替换为将验证码文本存储到 session 中的一行。

var http = require('http'), url = require('url'), captcha = require('captcha');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});

    var path = url.parse(req.url).pathname;
    switch (path) {
    case '/':
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write('<img src="/captcha.jpg" />');
        res.end();
        break;
    case '/captcha.jpg':
        captcha('/captcha.jpg')(req, res, 'noCaptcha');
        break;
}
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

noCaptcha = function() {
    console.log('No captcha available');
};

关于node.js - nodejs - 如何使用 Node 验证码模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9487844/

相关文章:

javascript - 如何在 fetch api 调用中处理 json 以外的值

javascript - NodeJs : How to tell that a message sent from a worker to the master is an Error

python - django-recaptcha 不验证输入

mysql - 在 sequelize 中聚合来自嵌套模型的数据

node.js - Nodemailer 的邮件在 Azure 服务器上无法工作

python - 验证码识别准确率低

javascript - 如何制作一个 ajax 验证码并通过 url 进行确认?

python - 在 Selenium 中提取隐藏元素

Node.js API REST 安全性

wordpress - Woocommerce Checkout 不适用于 WooCommerce 插件的无验证码 reCAPTCHA