Skip to content

Commit

Permalink
refactor: rename verify user function
Browse files Browse the repository at this point in the history
  • Loading branch information
janaka committed Oct 21, 2023
1 parent 8390960 commit 7d4211e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 3 additions & 6 deletions source/docq/manage_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 = ?",
(
Expand All @@ -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 = ?",
Expand Down
10 changes: 6 additions & 4 deletions web/utils/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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()

Expand Down

0 comments on commit 7d4211e

Please sign in to comment.