0

im using FriendlyFormPlugin, but would like to retrieve the username that was input as part of the request.params, but its no longer there when i check. this way i can set the default for username if the password is incorrect. thanks

4

1 回答 1

3

我认为您需要做的是在设置中间件时设置登录后处理程序操作。然后,在该操作中,您可以检查参数、设置会话变量等。我必须在这里挂钩,以便向用户创建他们登录失败的消息。我检查登录表单上的“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“摘要”,以帮助向其他开发人员解释这些东西是如何工作的/使用的术语:

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'
                      )
于 2010-04-17T00:07:29.640 回答