defreset_password(data=None): if data isnotNone: try: name = unserialize(data, max_age=1800) except (BadTimeSignature, SignatureExpired): return render_template( "reset_password.html", errors=["Your link has expired"] ) except (BadSignature, TypeError, base64.binascii.Error): return render_template( "reset_password.html", errors=["Your reset token is invalid"] )
if request.method == "GET": return render_template("reset_password.html", mode="set") if request.method == "POST": user = Users.query.filter_by(name=name).first_or_404() user.password = request.form["password"].strip() db.session.commit() log( "logins", format="[{date}] {ip} - successful password reset for {name}", name=name, ) db.session.close() return redirect(url_for("auth.login"))
if request.method == "POST": email_address = request.form["email"].strip() team = Users.query.filter_by(email=email_address).first()
get_errors()
if config.can_send_mail() isFalse: return render_template( "reset_password.html", errors=["Email could not be sent due to server misconfiguration"], )
ifnot team: return render_template( "reset_password.html", errors=[ "If that account exists you will receive an email, please check your inbox" ], )
email.forgot_password(email_address, team.name)
return render_template( "reset_password.html", errors=[ "If that account exists you will receive an email, please check your inbox" ], ) return render_template("reset_password.html")
defforgot_password(email, team_name): token = serialize(team_name) text = """Did you initiate a password reset? Click the following link to reset your password: {0}/{1} """.format( url_for("auth.reset_password", _external=True), token )