本文整理匯總了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)