apostrophe-cms - 如何编辑 url 以注销 ApostropheCMS
问题描述
我正在研究一种将 OAuth2 登录到 ApostropheCMS 的特定策略。登录系统后,我需要通过允许我执行 OAuth2 流程的身份服务器的 url 关闭会话。
不要使用http://localhost:3000/logout,而是使用 http ://localhost:port/auth/oauth2/logout。但我找不到使用 ApostropheCMS 中的注销链接编辑 url 的位置。
解决方案
我相信您是说您不需要复制注销功能(您已经这样做了),您需要更改管理栏中的注销链接。幸运的是,有一个好方法可以做到这一点。
像大多数模块一样,该apostrophe-login
模块在一个名为addAdminBarItems
. 该方法如下所示:
self.addAdminBarItems = function() {
var items = [];
var key;
if (self.options.resetKnownPassword) {
key = self.__meta.name + '-reset-known-password';
self.apos.adminBar.add(key, 'Change Password', null);
items.push(key);
}
key = self.__meta.name + '-logout';
self.apos.adminBar.add(key, 'Log Out', null, { last: true, href: '/logout' });
items.push(key);
if (items.length > 1) {
self.apos.adminBar.group({
label: 'Account',
items: items,
last: true
});
}
};
我们可以覆盖它以满足我们的需要。
lib/modules/apostrophe-login/index.js
在项目级别创建。不要从 node_modules 复制和粘贴整个内容,这不是必需的,我们在这里覆盖了一种方法。Apostrophe 将自动看到这一点并将我们的更改应用于原始文件。
文件如下所示:
// in lib/modules/apostrophe-login/index.js of your project
module.exports = {
construct: function(self, options) {
self.addAdminBarItems = function() {
key = self.__meta.name + '-logout';
self.apos.adminBar.add(key, 'Log Out', null, { last: true, href: '/anywhere/you/want/it/to/go' });
};
}
};
这将替换我们需要更改的方法,而不会更改任何其他内容。
推荐阅读
- debugging - VS 2017 - 开始和结束调试非常慢
- python - python中的系列数据结构是可迭代的吗?
- php - 在相关选择中显示选项计数
- c# - 如何在数据列上方写工作表名称
- react-native - React-Native 与网站交互,例如网页上的单击按钮、选择复选框等
- python - 在 Python 中使用 turtle 模块生成嵌套图像的问题
- corda - 如何从corda中的RPC客户端访问引用的对象?
- hibernate - 休眠:无一例外地坚持@OneToMany(其中子实体插入未在showsql中打印)
- java - 使用 Android java 在 WhatsApp 上自动发送消息?
- java - 使用 jgit 从旧提交创建新提交?