From eba3bd6a5a58194ea562f102b52d4f153469aed7 Mon Sep 17 00:00:00 2001 From: forest Date: Tue, 29 Dec 2020 19:03:37 -0600 Subject: [PATCH] fixing bugs with email ignore case feature --- capsulflask/auth.py | 10 +++++----- capsulflask/db_model.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/capsulflask/auth.py b/capsulflask/auth.py index 5815fce..a98a286 100644 --- a/capsulflask/auth.py +++ b/capsulflask/auth.py @@ -50,15 +50,15 @@ def login(): errors.append("too many logins. please use one of the existing login links that have been emailed to you") else: link = f"{current_app.config['BASE_URL']}/auth/magic/{token}" - + message = (f"Navigate to {link} to log into Capsul.\n" "\nIf you didn't request this, ignore this message.") if len(ignoreCaseMatches) > 0: - joinedMatches = " or ".join(ignoreCaseMatches) - message = (f"You tried to log in as '{email}', but that account doesn't exist yet. " - "If you would like to create a new account for '{email}', click here {link} " - "If you meant to log in as {joinedMatches}, please return to capsul.org " + joinedMatches = " or ".join(map(lambda x: f"'{x}'", ignoreCaseMatches)) + message = (f"You tried to log in as '{email}', but that account doesn't exist yet. \n" + f"If you would like to create a new account for '{email}', click here {link} \n\n" + f"If you meant to log in as {joinedMatches}, please return to https://capsul.org \n" "and log in again with the correct (case-sensitive) email address.") current_app.config["FLASK_MAIL_INSTANCE"].send( diff --git a/capsulflask/db_model.py b/capsulflask/db_model.py index 737db1f..bcf1611 100644 --- a/capsulflask/db_model.py +++ b/capsulflask/db_model.py @@ -15,8 +15,8 @@ class DBModel: everLoggedIn = len(self.cursor.fetchall()) ignoreCaseMatches = [] if everLoggedIn == 0: - self.cursor.execute("SELECT email FROM accounts WHERE lower_case_email = %s", (email.lower(), )) - ignoreCaseMatches = self.cursor.fetchall() + self.cursor.execute("SELECT email FROM accounts WHERE lower_case_email = %s AND email != %s", (email.lower(), email)) + ignoreCaseMatches = list(map(lambda x: x[0], self.cursor.fetchall())) if hasExactMatch == 0: self.cursor.execute("INSERT INTO accounts (email, lower_case_email) VALUES (%s, %s)", (email, email.lower()))