本文整理汇总了Python中app.users.models.User.from_auth_token方法的典型用法代码示例。如果您正苦于以下问题:Python User.from_auth_token方法的具体用法?Python User.from_auth_token怎么用?Python User.from_auth_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.from_auth_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reset_password
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import from_auth_token [as 别名]
def reset_password():
""" Display a password reset form. Usual entry point is via a link sent
to the user after pressing 'forgot password'.
A `User` auth token is required for both 'GET' (via `?token=`) and 'POST'
(via hidden field on the form, which is populated from the 'GET')
If the token is missing or invalid in either case, we redirect back to
the login screen.
The token expires after `app.config['PASSWORD_RESET_SECONDS']` or once
the user successfully logs in.
"""
form = ResetPasswordForm(request.form)
token = request.args.get('token')
if token:
form.token.data = token
else:
token = request.form.get('token')
if not token:
flash(_('Bad token.'))
return redirect(url_for('users.login'))
user = User.from_auth_token(
token, max_age=app.config['PASSWORD_RESET_SECONDS']
)
if not user:
flash(_('Bad token.'))
return redirect(url_for('users.login'))
if form.validate_on_submit():
new_password = generate_password_hash(form.password.data)
user.password = new_password
db.session.add(user)
db.session.commit()
login_user(user, remember=True)
flash(_('Your password has been changed.'))
return redirect(url_for('home'))
return render_template('users/reset_password.html', form=form)