summaryrefslogtreecommitdiff
path: root/Biz/PodcastItLater/Core.py
diff options
context:
space:
mode:
Diffstat (limited to 'Biz/PodcastItLater/Core.py')
-rw-r--r--Biz/PodcastItLater/Core.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/Biz/PodcastItLater/Core.py b/Biz/PodcastItLater/Core.py
index 0ca945c..b7b6ed9 100644
--- a/Biz/PodcastItLater/Core.py
+++ b/Biz/PodcastItLater/Core.py
@@ -576,13 +576,21 @@ class Database: # noqa: PLR0904
)
@staticmethod
- def create_user(email: str) -> tuple[int, str]:
+ def create_user(email: str, status: str = "pending") -> tuple[int, str]:
"""Create a new user and return (user_id, token).
+ Args:
+ email: User email address
+ status: Initial status (pending, active, or disabled)
+
Raises:
ValueError: If user ID cannot be retrieved after insert or if user
- not found.
+ not found, or if status is invalid.
"""
+ if status not in {"pending", "active", "disabled"}:
+ msg = f"Invalid status: {status}"
+ raise ValueError(msg)
+
# Generate a secure token for RSS feed access
token = secrets.token_urlsafe(32)
with Database.get_connection() as conn:
@@ -590,14 +598,19 @@ class Database: # noqa: PLR0904
try:
cursor.execute(
"INSERT INTO users (email, token, status) VALUES (?, ?, ?)",
- (email, token, "pending"),
+ (email, token, status),
)
conn.commit()
user_id = cursor.lastrowid
if user_id is None:
msg = "Failed to get user ID after insert"
raise ValueError(msg)
- logger.info("Created user %s with email %s", user_id, email)
+ logger.info(
+ "Created user %s with email %s (status: %s)",
+ user_id,
+ email,
+ status,
+ )
except sqlite3.IntegrityError:
# User already exists
cursor.execute(