node.js - Etherpad:连接身份验证的最佳方式

标签 node.js express etherpad

我正在为 etherpad 制作一个插件,用于检查用户是否经过身份验证。如果不是,则显示只读。我到目前为止:

var eejs = require('ep_etherpad-lite/node/eejs');
var readOnlyManager = require("ep_etherpad-lite/node/db/ReadOnlyManager");

exports.route = function(hook_name, args, cb){
    args.app.get('/p/:pad', function(req, res){
        if(req.params.pad.indexOf('r.') === 0){
            res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {req: req}));
        } else {
            if(req.session.user){
                res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {req: req}));
            } else {
                readOnlyManager.getReadOnlyId(req.params.pad, function(err, readonlyID){
                    res.redirect('/p/'+readonlyID);
                });
            }
        }
    });
}

exports.logout = function(hook_name, args, cb){
    args.app.get('/logout', function(req, res){
      req.session.destroy(function(){
        res.redirect('/');
      });
    });
}

但我无法使用帖子路由来让我自己的用户登录。我怎样才能根据请求进行一般身份验证,比如说当我访问/login 时?

最佳答案

我在 Etherpad 中编写了很多身份验证机制,但那是几年前的事了,我不知道从那以后它发生了多少变化。

您需要的 API 端点以及有关身份验证如何工作的文档可在 Etherpad documentation 中找到。特别是身份验证在 authentication documentation 中讨论.

很难从你的问题中看出,但看起来你想在/login 有某种登录页面?如果是这样,请查看 Etherpad 如何实现基本身份验证,并通过在/login 创建新的快速端点来调整它

有各种插件(包括我开发的插件)可用于创建新的快速端点,an example is available in the ep_email_notifications Etherpad plugin

我从你的问题中得到了正确的答案吗?

关于node.js - Etherpad:连接身份验证的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20818727/

相关文章:

javascript - 如何使用 express 作为直通代理?

keyboard-shortcuts - 在 Etherpad 中,除了粗体、斜体和下划线(罢工、项目符号……)之外,还有其他操作的快捷方式吗?

mongodb - 如何在 Node.js 中使用 Mongoose 进行分页?

node.js - 如何在node js和sequelize之外使用promise返回数据?

javascript - Node JS Post 请求导致 Heroku 严重错误请求超时 (503)

node.js - Mongoose 查询以增加项目数组中的字段(如果存在),否则将其添加到文档中(很难表述此标题)

javascript - 如何检查数组是否包含 PUG 模板中的字符串

javascript - 如何让 Express 路由默认需要身份验证?

php - 使用什么来代替 EtherPad?使用 php 和 mySql

javascript - 如何将光标置于 MathQuill (0.10) 字段以便可以立即键入进行编辑?