diff --git a/source/docq/manage_users.py b/source/docq/manage_users.py index 7ea0a97b..492b0109 100644 --- a/source/docq/manage_users.py +++ b/source/docq/manage_users.py @@ -357,7 +357,7 @@ def rnd(): _fullname = fullname if fullname else username first_name = _fullname.split(" ")[0] - personal_org_name = f"{first_name} Personal Org {rnd()}" # org names much be unique + personal_org_name = f"{first_name} Personal Org {rnd()}" # org names must be unique log.debug("Creating personal org: %s", personal_org_name) manage_organisations._create_organisation_sql(cursor, personal_org_name) @@ -385,13 +385,12 @@ def rnd(): return user_id -def verify_user(id_: int) -> bool: +def set_user_as_verified(id_: int) -> bool: """Verify a user.""" log.debug("Verifying user: %d", id_) with closing( sqlite3.connect(get_sqlite_system_file(), detect_types=sqlite3.PARSE_DECLTYPES) ) as connection, closing(connection.cursor()) as cursor: - cursor.execute( "UPDATE users SET verified = ?, updated_at = ? WHERE id = ?", ( @@ -413,9 +412,7 @@ def check_account_activated(username: str) -> bool: Returns: bool: True if the user's account is activated, False otherwise. """ - with closing( - sqlite3.connect(get_sqlite_system_file(), detect_types=sqlite3.PARSE_DECLTYPES) - ) as connection: + with closing(sqlite3.connect(get_sqlite_system_file(), detect_types=sqlite3.PARSE_DECLTYPES)) as connection: return ( connection.execute( "SELECT id FROM users WHERE username = ? AND verified = ?", diff --git a/web/utils/handlers.py b/web/utils/handlers.py index 9237ebe7..5605b34c 100644 --- a/web/utils/handlers.py +++ b/web/utils/handlers.py @@ -266,7 +266,7 @@ def list_users_by_current_org(username_match: str = None) -> list[tuple]: def handle_check_user_exists(username: str) -> bool: """Check if a user with a given username (email) exists.""" - return ( manage_users.get_user(username=username) is not None ) + return manage_users.get_user(username=username) is not None def handle_user_signup() -> bool: @@ -283,7 +283,9 @@ def handle_user_signup() -> bool: ) if user_id: send_verification_email(username, fullname, user_id) - validator.success("A verification email has been sent to your email address. Please verify your email before logging in.") + validator.success( + "A verification email has been sent to your email address. Please verify your email before logging in." + ) log.info("User signup result: %s", user_id) return True except Exception as e: @@ -327,7 +329,7 @@ def handle_verify_email() -> bool: decoded = unquote_plus(base64.b64decode(user_info).decode("utf-8")) user_id, timestamp, hash_ = decoded.split("::") if _verify_timestamp(timestamp) and _verify_hash(user_id, timestamp, hash_): - manage_users.verify_user(int(user_id)) + manage_users.set_user_as_verified(int(user_id)) return True return False @@ -337,7 +339,7 @@ def handle_check_account_activated(username: str) -> bool: return manage_users.check_account_activated(username) -def handle_check_mailer_ready () -> bool: +def handle_check_mailer_ready() -> bool: """Check if the mailer is ready.""" return mailer_ready()