本文整理汇总了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}
示例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}