BUGFIX: Reset password now only sends email to accounts which exist within the database

This commit is contained in:
JustIceO7
2025-03-07 01:18:05 +00:00
parent 1173896710
commit 4b9c1196d4
3 changed files with 19 additions and 5 deletions

View File

@@ -53,7 +53,7 @@ const ForgotPasswordForm: React.FC<SubmitProps> = ({ onSubmit }) => {
if (!response.ok) {
const data = await response.json();
throw new Error(
data.message || "An error has occurred while resetting"
data.error || "An error has occurred while resetting"
);
} else {
confirmPasswordReset();

View File

@@ -3,7 +3,7 @@ from utils.user_utils import *
from utils.auth import *
from utils.utils import get_category_id
from blueprints.middleware import login_required
from utils.email import send_email, forgot_password_body, newsletter_conf, remove_from_newsletter
from utils.email import send_email, forgot_password_body, newsletter_conf, remove_from_newsletter, email_exists
from utils.path_manager import PathManager
from celery_tasks.streaming import convert_image_to_png
import redis
@@ -195,8 +195,11 @@ def user_forgot_password(email):
"""
Initializes the function to handle password reset
"""
exists = email_exists(email)
if(exists):
send_email(email, lambda: forgot_password_body(email))
return email
return jsonify({"error":"email not found"}), 404
@user_bp.route("/send_newsletter/<string:email>", methods=["POST"])
def send_newsletter(email):

View File

@@ -202,3 +202,14 @@ def remove_from_newsletter(email):
DELETE FROM newsletter
WHERE email = ?;
""", (email,))
def email_exists(email):
"""
Returns whether email exists within database
"""
with Database() as db:
data = db.fetchone("""
SELECT * FROM users
WHERE email = ?
""", (email,))
return bool(data)