def forget_password(): if current_user.is_authenticated: return redirect(url_for('main.index.html')) 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.CONFIRM) send_rest_password_email(user=user, token=token) flash('Password reset emails sent, check you inbox.', 'info') return redirect(url_for('.login')) flash('Invalid emails.', 'warning') return redirect(url_for('.forget_password')) return render_template('auth/reset_password.html', form=form)
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 reset email sent, check you 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(): 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)
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)