【问题标题】:nodejs - How to use node-captcha module?nodejs - 如何使用 node-captcha 模块?
【发布时间】:2012-03-04 01:27:43
【问题描述】:

我已经从以下链接安装了 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')”来让验证码工作,但没有任何反应。

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

【问题讨论】:

    标签: node.js captcha


    【解决方案1】:

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

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

    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');
    };
    

    【讨论】:

      猜你喜欢
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 2020-08-06
      • 2014-08-04
      • 2013-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多