ckan - Requiring Login on CKAN
问题描述
We are looking to require all users log in before using CKAN. Ideally, the way it would work is that a non-authenticated user would automatically be redirected to a custom log in form, which does not expose the rest of the site
We've tried creating a plugin with the below code, while it will get some pages to throw a 403 error, we can not get a redirect to work
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
def site_read(context, data_dict=None):
# Get the user name of the logged-in user.
user_name = context['user']
# If they're not a logged in user, don't allow them to see content
if user_name is None:
return {'success': False,
'msg': 'Must be logged in to view site'}
else:
flash("You need to login first")
return redirect('http://www.google.com')
class DrexeluhcPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IAuthFunctions)
def get_auth_functions(self):
return {'site_read': site_read}
解决方案
I'm afraid you can't do a redirect in an auth function - you return {'success': True} or {'success': False}. Only a controller/view can initiate a redirect.
Another way to implement a login form would be to do something like ckanext-ldap does to override the template to CKAN's login form, and use parts of IAuthenticator. There are no doubt other examples of using IAuthenticator too.
推荐阅读
- javascript - 动态创建对象字面量
- vue.js - Nuxt如何覆盖页面的全局css
- swift - 如何将 CMSampleBuffer 转换为原始帧(比如 UYVY)?
- c# - 为什么在不等待的方法上使用 async 修饰符时编译器不会出错?
- python-3.x - Frappe Framework ERPNEXT:如何在 localhost 上启用 CORS
- flutter - 在 Ubuntu 上构建 Flutter 引擎
- progressive-web-apps - Blazor PWA 的问题
- swiftui - 如何以编程方式显示 SwiftUI 覆盖?
- vue.js - 谷歌地图在 Vue 模态中显示灰色框
- xcode - XCode & SPM - 动态解决包依赖