本文整理汇总了Python中h.accounts.models.User.generate_random_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.generate_random_password方法的具体用法?Python User.generate_random_password怎么用?Python User.generate_random_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h.accounts.models.User
的用法示例。
在下文中一共展示了User.generate_random_password方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disable_user
# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import generate_random_password [as 别名]
def disable_user(self):
"""Disable the user by setting a random password."""
err, appstruct = validate_form(self.form, self.request.POST.items())
if err is not None:
return err
username = appstruct['username']
pwd = appstruct['pwd']
# Password check
user = User.get_user(username, pwd)
if user:
# TODO: maybe have an explicit disabled flag in the status
user.password = User.generate_random_password()
self.request.session.flash(_('Account disabled.'), 'success')
return {}
else:
return dict(errors={'pwd': _('Invalid password')}, code=401)
示例2: disable_user
# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import generate_random_password [as 别名]
def disable_user(self):
"""Disable the user by setting a random password."""
if self.request.authenticated_userid is None:
return httpexceptions.HTTPUnauthorized()
err, appstruct = validate_form(self.form, self.request.POST.items())
if err is not None:
return err
user = User.get_by_userid(
self.request.domain, self.request.authenticated_userid)
if User.validate_user(user, appstruct['pwd']): # Password check.
# TODO: maybe have an explicit disabled flag in the status
user.password = User.generate_random_password()
self.request.session.flash(_('Account disabled.'), 'success')
return {}
else:
return dict(errors={'pwd': _('Invalid password')}, code=401)