Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Add REGISTRATION_ALLOWED_DOMAINS to restrict registration by email domain

Murtaza Nasireb80a8e1248e
diff --git a/config/env.asr.example b/config/env.asr.example
index 4199ee29..a7acf932 100644
--- a/config/env.asr.example
+++ b/config/env.asr.example
@@ -84,6 +84,9 @@ ASR_DIARIZE=true
# --- Application Settings ---
# Set to "true" to allow user registration, "false" to disable
ALLOW_REGISTRATION=false
+# Comma-separated list of allowed email domains for registration.
+# Leave empty to allow all domains. Example: company.com,subsidiary.org
+REGISTRATION_ALLOWED_DOMAINS=
SUMMARY_MAX_TOKENS=8000
CHAT_MAX_TOKENS=5000
diff --git a/config/env.transcription.example b/config/env.transcription.example
index 11d2d5e7..05c88919 100644
--- a/config/env.transcription.example
+++ b/config/env.transcription.example
@@ -167,6 +167,9 @@ ADMIN_PASSWORD=changeme
# --- Registration & Access ---
ALLOW_REGISTRATION=false
+# Comma-separated list of allowed email domains for registration.
+# Leave empty to allow all domains. Example: company.com,subsidiary.org
+REGISTRATION_ALLOWED_DOMAINS=
# --- Token Limits ---
SUMMARY_MAX_TOKENS=8000
diff --git a/config/env.whisper.example b/config/env.whisper.example
index 09a76042..82903ca1 100644
--- a/config/env.whisper.example
+++ b/config/env.whisper.example
@@ -79,6 +79,9 @@ TRANSCRIPTION_MODEL=whisper-1
# --- Application Settings ---
# Set to "true" to allow user registration, "false" to disable
ALLOW_REGISTRATION=false
+# Comma-separated list of allowed email domains for registration.
+# Leave empty to allow all domains. Example: company.com,subsidiary.org
+REGISTRATION_ALLOWED_DOMAINS=
SUMMARY_MAX_TOKENS=8000
CHAT_MAX_TOKENS=5000
diff --git a/config/env.whisperx.example b/config/env.whisperx.example
index 2380a7f5..a16d1b86 100644
--- a/config/env.whisperx.example
+++ b/config/env.whisperx.example
@@ -96,6 +96,9 @@ ASR_RETURN_SPEAKER_EMBEDDINGS=true
# --- Application Settings ---
# Set to "true" to allow user registration, "false" to disable
ALLOW_REGISTRATION=false
+# Comma-separated list of allowed email domains for registration.
+# Leave empty to allow all domains. Example: company.com,subsidiary.org
+REGISTRATION_ALLOWED_DOMAINS=
SUMMARY_MAX_TOKENS=8000
CHAT_MAX_TOKENS=5000
diff --git a/docs/getting-started.md b/docs/getting-started.md
index b09466c7..a633809b 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -198,6 +198,14 @@ By default, only the admin can create new users. Learn more about [user manageme
ALLOW_REGISTRATION=true
```
+To restrict registration to specific email domains (e.g., for company use), set:
+
+```bash
+REGISTRATION_ALLOWED_DOMAINS=company.com,subsidiary.org
+```
+
+Leave empty to allow all domains.
+
### Configure Your Timezone
Set your local timezone for accurate timestamp display:
diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md
index f0c28334..9f312168 100644
--- a/docs/getting-started/installation.md
+++ b/docs/getting-started/installation.md
@@ -201,11 +201,12 @@ Next, configure how the application behaves. These settings control user access
```bash
ALLOW_REGISTRATION=false
+REGISTRATION_ALLOWED_DOMAINS=
TIMEZONE="America/New_York"
LOG_LEVEL="INFO"
```
-Setting `ALLOW_REGISTRATION=false` means only the admin can create new user accounts, which is recommended for private installations where you want to control access. If you're running Speakr for a group or family, this prevents random people from creating accounts. The timezone setting affects how dates and times are displayed throughout the interface, so set it to your local timezone for convenience. The log level controls how much information Speakr writes to its logs. Use `INFO` during initial setup and testing to see what's happening, then switch to `ERROR` for production to reduce log volume and improve performance.
+Setting `ALLOW_REGISTRATION=false` means only the admin can create new user accounts, which is recommended for private installations where you want to control access. If you're running Speakr for a group or family, this prevents random people from creating accounts. If you enable registration and want to restrict it to specific email domains (e.g., for corporate use), set `REGISTRATION_ALLOWED_DOMAINS` to a comma-separated list of domains like `company.com,subsidiary.org`. Leave it empty to allow all domains. The timezone setting affects how dates and times are displayed throughout the interface, so set it to your local timezone for convenience. The log level controls how much information Speakr writes to its logs. Use `INFO` during initial setup and testing to see what's happening, then switch to `ERROR` for production to reduce log volume and improve performance.
### Step 5: Configure Advanced Features
diff --git a/src/api/auth.py b/src/api/auth.py
index 08b0aa09..7b751db1 100644
--- a/src/api/auth.py
+++ b/src/api/auth.py
@@ -105,6 +105,31 @@ def is_safe_url(target):
return test_url.scheme in ('http', 'https') and ref_url.netloc == test_url.netloc
+def is_registration_domain_allowed(email: str) -> bool:
+ """Check if email domain is allowed for registration.
+
+ Returns True if no domain restrictions are configured or if the
+ email domain is in the allowed list.
+ """
+ if not email:
+ return False
+
+ domains_env = os.environ.get('REGISTRATION_ALLOWED_DOMAINS', '')
+ if not domains_env or not domains_env.strip():
+ return True # No restriction configured
+
+ allowed = [d.strip().lower() for d in domains_env.split(',') if d.strip()]
+ if not allowed:
+ return True # Empty after parsing
+
+ parts = email.lower().rsplit('@', 1)
+ if len(parts) != 2:
+ return False # Invalid email format
+
+ domain = parts[1]
+ return domain in allowed
+
+
# --- Routes ---
@auth_bp.route('/register', methods=['GET', 'POST'])
@@ -122,6 +147,11 @@ def register():
form = RegistrationForm()
if form.validate_on_submit():
+ # Check if email domain is allowed
+ if not is_registration_domain_allowed(form.email.data):
+ flash('Registration is restricted. Please contact the administrator.', 'danger')
+ return render_template('register.html', title='Register', form=form)
+
hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
user = User(username=form.username.data, email=form.email.data, password=hashed_password)
db.session.add(user)