app.models
Database models for the Mail List Shield application.
This module defines the SQLAlchemy ORM models for the applicationβs database,
including user accounts, API keys, batch validation jobs, and subscription tiers.
Classes
APIKeys
|
Table for storing API keys associated with user accounts. |
BatchJobs
|
Table for batch email validation jobs. |
Tiers
|
Table for subscription tiers. |
Users
|
Table for user accounts. |
Module Contents
-
class app.models.APIKeys(user, key_hash, label=None, expires_at=None)[source]
Bases: app.db.Model
Table for storing API keys associated with user accounts.
API keys are hashed before storage for security. Each key belongs to a single
user and can be active or revoked.
-
id[source]
Primary key.
-
user_id[source]
Foreign key to the Users table.
-
key_hash[source]
Bcrypt hash of the API key.
-
label[source]
Optional user-provided label for the key.
-
created_at[source]
Timestamp when the key was created.
-
expires_at[source]
Optional expiration timestamp.
-
last_used[source]
Timestamp of the last API call using this key.
-
is_active[source]
Whether the key is currently active.
-
id[source]
-
user_id[source]
-
key_hash[source]
-
label[source]
-
created_at[source]
-
expires_at[source]
-
last_used[source]
-
is_active[source]
-
check_key(key_plain)[source]
Verify if a plaintext key matches this keyβs hash.
- Parameters:
key_plain β The plaintext API key to verify.
- Returns:
True if the key matches, False otherwise.
- Return type:
bool
-
delete_key()[source]
Delete this API key from the database.
- Returns:
True if deletion was successful.
- Return type:
bool
-
update_last_used()[source]
Update the last_used timestamp to the current time.
-
save()[source]
Save the current state of this API key to the database.
- Returns:
The saved API key instance.
- Return type:
APIKeys
-
class app.models.BatchJobs(*args, **kwargs)[source]
Bases: app.db.Model
Table for batch email validation jobs.
Tracks the status and metadata of batch validation jobs, including
uploaded files, processing status, and results.
-
id[source]
Primary key.
-
uid[source]
Unique 6-character identifier for the job.
-
user_id[source]
Foreign key to the Users table.
-
user[source]
Relationship to the user who created the job.
-
status[source]
Current status of the job.
-
original_file_name[source]
Original name of the uploaded file.
-
uploaded_file[source]
Path to the uploaded file in object storage.
-
accepted_file[source]
Path to the accepted/processed file.
-
results_file[source]
Path to the results file in object storage.
-
row_count[source]
Number of rows in the uploaded file.
-
last_pick_row[source]
Last row processed by the worker.
-
last_pick_time[source]
Timestamp of the last worker pick.
-
source[source]
Source of the job (e.g., βwebβ, βapiβ).
Row number containing headers (0 or 1).
-
email_column[source]
Name of the column containing email addresses.
-
uploaded[source]
Timestamp when the file was uploaded.
-
started[source]
Timestamp when processing started.
-
finished[source]
Timestamp when processing finished.
-
result[source]
Final result summary.
-
id[source]
-
uid[source]
-
user_id[source]
-
user[source]
-
status[source]
-
original_file_name[source]
-
uploaded_file[source]
-
accepted_file[source]
-
results_file[source]
-
row_count[source]
-
last_pick_row[source]
-
last_pick_time[source]
-
source[source]
-
header_row[source]
-
email_column[source]
-
uploaded[source]
-
started[source]
-
finished[source]
-
result[source]
-
generate_job_uid()[source]
Generate a unique 6-character identifier for this job.
Ensures uniqueness by checking against existing jobs in the database.
-
generate_results_download_link()[source]
Generate a pre-signed download URL for the results file.
- Returns:
- A pre-signed URL for downloading the results file,
or None if no results file exists.
- Return type:
str
-
class app.models.Tiers[source]
Bases: app.db.Model
Table for subscription tiers.
Defines the available subscription tiers and their associated
Stripe price IDs.
-
id[source]
Primary key.
-
name[source]
Internal name of the tier.
-
label[source]
Display label for the tier.
-
stripe_price_id[source]
Associated Stripe price ID for subscriptions.
-
users[source]
Relationship to users on this tier.
-
id[source]
-
name[source]
-
label[source]
-
stripe_price_id[source]
-
users[source]
-
class app.models.Users(email, password, tier_id, firstName, lastName, newsletter, member_since, last_login, email_confirmation_code)[source]
Bases: app.db.Model, flask_login.UserMixin
Table for user accounts.
Stores user account information including authentication credentials,
profile data, subscription status, and security settings.
-
id[source]
Primary key.
-
email[source]
Unique email address for the user.
-
password[source]
Bcrypt-hashed password.
-
role[source]
User role (e.g., βuserβ, βadminβ).
-
stripe_customer_id[source]
Associated Stripe customer ID.
-
tier_id[source]
Foreign key to the subscription tier.
-
credits[source]
Number of validation credits available.
-
tier[source]
Relationship to the userβs subscription tier.
-
cancel_at[source]
Scheduled subscription cancellation date.
-
firstName[source]
Userβs first name.
-
lastName[source]
Userβs last name.
-
newsletter[source]
Newsletter subscription status.
-
member_since[source]
Account creation timestamp.
-
last_login[source]
Last login timestamp.
-
email_confirmation_code[source]
Code for email verification.
-
last_confirmation_codes_sent[source]
Last time a confirmation code was sent.
-
number_of_email_confirmation_codes_sent[source]
Count of confirmation codes sent.
-
email_confirmed[source]
Whether the email is confirmed (0 or 1).
-
google_avatar_url[source]
URL to Google avatar if using OAuth.
-
avatar_uploaded[source]
Whether a custom avatar was uploaded.
-
totp_secret[source]
Secret key for TOTP two-factor authentication.
-
totp_enabled[source]
Whether TOTP is enabled (0 or 1).
-
api_keys[source]
Relationship to userβs API keys.
-
id[source]
-
email[source]
-
password[source]
-
role[source]
-
stripe_customer_id[source]
-
tier_id[source]
-
credits[source]
-
tier[source]
-
cancel_at[source]
-
firstName[source]
-
lastName[source]
-
newsletter[source]
-
member_since[source]
-
last_login[source]
-
email_confirmation_code[source]
-
last_confirmation_codes_sent[source]
-
number_of_email_confirmation_codes_sent[source]
-
email_confirmed[source]
-
google_avatar_url[source]
-
avatar_uploaded[source]
-
totp_secret[source]
-
totp_enabled[source]
-
api_keys[source]
-
save()[source]
Save the current state of this user to the database.
- Returns:
The saved user instance.
- Return type:
Users
-
avatar(size=256)[source]
Get the URL for the userβs avatar image.
Returns the avatar from uploaded file, Google OAuth, or Gravatar
in order of priority.
- Parameters:
size β The size of the avatar image in pixels.
- Returns:
URL to the userβs avatar image.
- Return type:
str
-
is_connected_google()[source]
Check if the user has connected their Google account.
- Returns:
True if Google account is connected, False otherwise.
- Return type:
bool
-
totp()[source]
Get the TOTP secret and QR code for two-factor authentication setup.
- Returns:
A tuple containing (secret, qr_code_data_uri).
- Return type:
tuple
-
totp_match(code)[source]
Verify a TOTP code against the userβs secret.
- Parameters:
code β The 6-digit TOTP code to verify.
- Returns:
True if the code is valid, False otherwise.
- Return type:
bool
-
totp_reset_secret()[source]
Generate a new TOTP secret for the user.
This invalidates any existing authenticator app configurations.
-
folder_size()[source]
Get the human-readable size of the userβs storage folder.
- Returns:
The folder size with appropriate units (e.g., β5 MBβ).
- Return type:
str
-
folder_quota()[source]
Get the human-readable storage quota for the user.
- Returns:
The storage quota (currently fixed at 500 MB).
- Return type:
str
-
folder_usage_percentage()[source]
Calculate the percentage of storage quota used.
- Returns:
The usage percentage (0-100).
- Return type:
int
-
add_credits(amount)[source]
Add validation credits to the userβs account.
- Parameters:
amount β The number of credits to add.
-
deduct_credits(amount)[source]
Deduct validation credits from the userβs account.
- Parameters:
amount β The number of credits to deduct.