I'm trying to add the ability to reset a user's password with a password reset link with Flask but whenever I go to test out the functionality of this feature, I'm met with ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it.
Here's the revelant snippets of code from my app.py and init.py. If this isn't enough to solve the problem, just let me know what else you need to see.
app.py
def send_reset_email(user):
token = user.get_reset_token()
msg = Message('Password Reset Request')
msg.sender = 'noreply@demo.com'
msg.recipients = [user.email]
msg.body = f"""
To reset your password, visit the following link: {url_for('reset_token', token=token, _external=True)}.
If you did not make this request, then ignore this email and no changes will be made.
"""
mail.send(msg)
@app.route("/reset_password", methods=['GET', 'POST'])
def reset_password():
if current_user.is_authenticated:
return redirect(url_for('home'))
form = RequestResetForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
send_reset_email(user)
flash('An email has been set with instructions to reset your password.', 'info')
return redirect(url_for('login'))
return render_template('reset_request.html', title='Reset Password', form=form)
init.py
app = Flask(__name__)
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'
mail = Mail()
mail.init_app(app)
app.config['SECRET_KEY'] = 'f645748071241866b90c405a391033ac'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = os.environ.get('EMAIL_USER')
app.config['MAIL_PASSWORD'] = os.environ.get('EMAIL_USER')
app.config['MAIL_SUPPRESS_SEND'] = False