我正在使用FriendlyFormPlugin,但想要检索作为request.params的一部分输入的用户名,但当我检查时它不再在那里。这样,如果密码不正确,我可以设置用户名的默认值。谢谢
发布于 2010-04-17 08:07:30
我认为您需要做的是在设置中间件时设置一个post登录处理程序操作。在该操作中,您可以检查参数、设置会话变量等。我必须连接到此处,以便为用户创建登录失败的消息。我在登录表单上检查'login_failed‘参数。
def post_login(self):
""" Handle logic post a user's login
I want to create a login_handler that's redirected to after login. This would
check
- if user was logged in, if not then send back to login
- if user is admin, go to job list
- adjust the max age on the existing cookie to XX remember me timeframe
"""
if auth.check(not_anonymous()):
log.debug('checked auth')
else:
# login failed, redirect back to login
log.debug('failed auth')
redirect_to(controller="root", action="login", login_failed=True)
# expire this cookie into the future
ck = request.cookies['authtkt']
response.set_cookie('authtkt', ck,
max_age=60*60*24*7,
path='/'
)
redirect_to(controller="job", action="list")作为对更多细节的回应,太大了,无法作为另一条评论添加:
所以我有一些你可以看的东西。首先,这是我的文档,我将其作为repoze 'summary‘来帮助向其他开发人员解释这些东西是如何工作的/使用的术语:
http://72.14.191.199/docs/morpylons/auth_overview.html
我开始使用的是repoze sql快速入门插件:http://code.gustavonarea.net/repoze.what-quickstart/
然后,我删除了他们的setup_sql_auth,并根据我们自己的需要对其进行了修改,因为我们在应用程序中同时进行SQL和LDAP身份验证。去看看setup_sql_auth的插件源代码,仔细看看,直到你真正理解它在做什么。
既然你问了中间件的配置...
app = setup_morpace_auth(app, User, Group, Permission, meta.Session,
post_login_url='/root/post_login',
post_logout_url='/login',
log_level='debug',
log_file='stdout'
)https://stackoverflow.com/questions/2656374
复制相似问题