def forget_password(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = ForgetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).first() if user: token = generate_token(user, operation=Operations.RESET_PASSWORD) send_reset_password_email(user=user, token=token) flash('Password reset email sent, check your inbox.', 'info') return redirect(url_for('.login')) flash('Invalid email.', 'warning') return redirect(url_for('.forget_password')) return render_template('auth/reset_password.html')
def forget_password(): if current_user.is_authenticated: return redirect(url_for("main.index")) form = ForgetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).first() if user: token = generate_token(user=user, operation=Operations.RESET_PASSWORD) send_reset_password_email(user=user, token=token) flash("Password rest email sent, check your inbox.", "info") return redirect(url_for("auth.login")) flash("Invalid Email", "warning") return redirect(url_for("auth.forget_password")) return render_template("auth/reset_password.html", form=form)
def forget_password(): """ 忘记密码 """ logger.info('url = ' + str(request.url)) # 如果已经登录,则跳转到主页 # 该功能只适用于登录记不起密码时使用 if current_user.is_authenticated: return redirect(url_for('main.index')) form = ForgetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).first() if user: token = generate_token(user=user, operation=Operations.RESET_PASSWORD) # 重置密码 send_reset_password_email(user=user, token=token) flash('邮件已发送,请登录邮箱点击链接重置密码!', 'info') return redirect(url_for('.login')) flash('无效邮箱,请重新输入!', 'warning') return redirect(url_for('.forget_password')) return render_template('auth/reset_password.html', form=form)