From cd39f7b2c66f487a45291375786256dafcc037dc Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 25 Nov 2021 01:49:14 +0000 Subject: [PATCH] Fix verification email not being sent by set password --- app/blueprints/users/account.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/blueprints/users/account.py b/app/blueprints/users/account.py index e175f8f5..cd885b20 100644 --- a/app/blueprints/users/account.py +++ b/app/blueprints/users/account.py @@ -259,13 +259,25 @@ def handle_set_password(form): flash("That email address has been unsubscribed/blacklisted, and cannot be used", "danger") return - token = randomString(32) + user_by_email = User.query.filter_by(email=form.email.data).first() + if user_by_email: + send_anon_email.delay(form.email.data, "Email already in use", + "We were unable to create the account as the email is already in use by {}. Try a different email address.".format( + user_by_email.display_name)) + else: + token = randomString(32) - ver = UserEmailVerification() - ver.user = current_user - ver.token = token - ver.email = newEmail - db.session.add(ver) + ver = UserEmailVerification() + ver.user = current_user + ver.token = token + ver.email = newEmail + db.session.add(ver) + db.session.commit() + + send_verify_email.delay(form.email.data, token) + + flash("Your password has been changed successfully.", "success") + return redirect(url_for("flatpage", path="email_sent")) db.session.commit() flash("Your password has been changed successfully.", "success")