def forgot(): if request.method == "POST": user_name = request.form.get("username") if not re.match(r"[^@]+@[^@]+\.[^@]+", user_name): return render_template("forgot.html", error="Invalid email address!") next_page = request.form.get("next_page", url_for("home")) captcha_response = request.form.get("g-recaptcha-response") if not validate_captcha(captcha_response): return render_template("forgot.html", error="Recaptcha Fail") if is_abuse_check(request.remote_addr, prefix="forgot", threshold=10): return render_template("forgot.html", error="Abuse detected by your IP address.") try: User.forgot(email=user_name) except Exception as ex: logger.exception(ex) return render_template("forgot.html", error="Password Forgot Fail!") return redirect(next_page) else: return render_template("forgot.html", error=None)