def reset_password_request(): """Respond to existing user's request to reset their password.""" if not current_user.is_anonymous: return redirect(url_for("main.index")) form = RequestResetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: token = user.generate_password_reset_token() reset_link = url_for("account.reset_password", token=token, _external=True) user.__dict__.pop("storage_files") get_queue().enqueue( send_email, recipient=user.email, subject="Reset Your Password", template="account/email/reset_password", user=user, reset_link=reset_link, next=request.args.get("next"), ) flash( "A password reset link has been sent to {}.".format( form.email.data), "warning", ) return redirect(url_for("account.login")) return render_template("account/reset_password.html", form=form)
def reset_password_request(): """Respond to existing user's request to reset their password.""" if not current_user.is_anonymous: return redirect(url_for('main.index')) form = RequestResetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: token = user.generate_password_reset_token() reset_link = url_for( 'account.reset_password', token=token, _external=True) get_queue().enqueue( send_email, recipient=user.email, subject='Reset Your Password', template='account/email/reset_password', user=user, reset_link=reset_link, next=request.args.get('next')) flash('A password reset link has been sent to {}.'.format( form.email.data), 'warning') return redirect(url_for('account.login')) return render_template('account/reset_password.html', form=form)