当前位置: 首页>>代码示例>>Python>>正文


Python Form.errors['old_password']方法代码示例

本文整理汇总了Python中pyramid_simpleform.Form.errors['old_password']方法的典型用法代码示例。如果您正苦于以下问题:Python Form.errors['old_password']方法的具体用法?Python Form.errors['old_password']怎么用?Python Form.errors['old_password']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid_simpleform.Form的用法示例。


在下文中一共展示了Form.errors['old_password']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: change_password

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors['old_password'] [as 别名]
def change_password(request):
    """Change user password."""
    
    # Unpack.
    user = request.user
    notify = request.registry.notify
    
    # Validate the request.
    form = Form(request, schema=schema.ChangePassword,
            defaults={'failed': False})
    location = get_redirect_location(request)
    if request.method == 'POST':
        if form.validate():
            d = form.data
            user = model.authenticate(user.username, d['old_password'])
            if user:
                # Save new password to the db.
                user.password = model.encrypt(d['new_password'])
                model.save(user)
                # Notify that the password changed.
                notify(events.UserChangedPassword(request, user))
                # Log the user out, so that a change of password will lock out
                # someone who has compromised the existing password.
                headers = forget(request)
                # Notify that the user is logged out.
                notify(events.UserLoggedOut(request, request.user))
                # Redirect.
                return HTTPFound(location=location, headers=headers)
            else:
                form.errors['old_password'] = 'Wrong current password.'

    form.data['next'] = location
    return {'renderer': FormRenderer(form), 'user': request.user}
开发者ID:robertlagrant,项目名称:pyramid_simpleauth,代码行数:35,代码来源:view.py

示例2: change_password

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors['old_password'] [as 别名]
def change_password(request):
    """Change user password."""
    form = Form(request, schema=schema.ChangePassword,
                defaults={'failed': False})
    user = request.user
    location = get_redirect_location(request)
    if request.method == 'POST':
        if form.validate():
            d = form.data
            user = model.authenticate(user.username, d['old_password'])
            if user:
                # Save new password to the db
                user.password = model.encrypt(d['new_password'])
                model.save(user)
                request.registry.notify(
                        events.UserChangedPassword(request, user))
                return HTTPFound(location=location)
            else:
                form.errors['old_password'] = 'Wrong current password.'

    form.data['next'] = location
    return {'renderer': FormRenderer(form), 'user': request.user}
开发者ID:altanawealth,项目名称:pyramid_simpleauth,代码行数:24,代码来源:view.py


注:本文中的pyramid_simpleform.Form.errors['old_password']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。