diff --git a/config.example.yaml b/config.example.yaml index 559cf6d..e7aa215 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -65,6 +65,11 @@ auth: # Can also be set via ADMIN_EMAIL environment variable admin_email: "" # Set this to your admin email address + # Default email to pre-fill in the login form + # When set, this email will be automatically filled in the email input field + # Leave empty to show an empty email field + default_email: "" # Set this to pre-fill the login form with a default email + # Environment-specific overrides can be set via environment variables: # - PORT: Server port # - HOST: Server host @@ -74,3 +79,4 @@ auth: # - ALLOWED_EMAILS: Comma-separated list of allowed emails # - ADMIN_EMAIL: Admin email address # - COOKIE_DOMAIN: Cookie domain for session cookies +# - DEFAULT_EMAIL: Default email to pre-fill in login form diff --git a/internal/config/config.go b/internal/config/config.go index d8e95c4..df81b8f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -42,6 +42,7 @@ type AuthConfig struct { AllowedEmails []string `yaml:"allowed_emails"` AdminEmail string `yaml:"admin_email"` CookieDomain string `yaml:"cookie_domain"` + DefaultEmail string `yaml:"default_email"` } func Load() (*Config, error) { @@ -122,6 +123,9 @@ func Load() (*Config, error) { if cookieDomain := os.Getenv("COOKIE_DOMAIN"); cookieDomain != "" { config.Auth.CookieDomain = cookieDomain } + if defaultEmail := os.Getenv("DEFAULT_EMAIL"); defaultEmail != "" { + config.Auth.DefaultEmail = defaultEmail + } return config, nil } diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 90ea040..a6fe562 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -469,6 +469,14 @@ func (h *Handlers) GetAuthStatus(w http.ResponseWriter, r *http.Request) { h.writeJSON(w, response) } +// GetConfig returns public configuration data +func (h *Handlers) GetConfig(w http.ResponseWriter, r *http.Request) { + configData := map[string]interface{}{ + "default_email": h.config.Auth.DefaultEmail, + } + h.writeJSON(w, configData) +} + // Admin endpoints // ListUsers returns all users (admin endpoint) diff --git a/main.go b/main.go index 173138a..24ac014 100644 --- a/main.go +++ b/main.go @@ -49,6 +49,7 @@ func main() { // API routes api := router.PathPrefix("/api").Subrouter() + api.HandleFunc("/config", h.GetConfig).Methods("GET") api.HandleFunc("/register/begin", h.BeginRegistration).Methods("POST") api.HandleFunc("/register/finish", h.FinishRegistration).Methods("POST") api.HandleFunc("/login/begin", h.BeginLogin).Methods("POST") diff --git a/web/login.html b/web/login.html index 2bb9ce6..65df6b9 100644 --- a/web/login.html +++ b/web/login.html @@ -282,7 +282,7 @@ return emailParam; } - // Pre-fill email input if email parameter exists + // Pre-fill email input if email parameter exists or from config function prefillEmail() { const email = getEmailFromUrl(); if (email) { @@ -290,6 +290,29 @@ if (emailInput) { emailInput.value = decodeURIComponent(email); } + } else { + // If no email parameter, try to get default email from config + loadDefaultEmail(); + } + } + + // Load default email from server configuration + async function loadDefaultEmail() { + try { + const response = await fetch('/api/config'); + if (response.ok) { + const config = await response.json(); + if (config.default_email) { + const emailInput = document.getElementById('email'); + if (emailInput && !emailInput.value) { + emailInput.value = config.default_email; + console.log('Pre-filled email from config:', config.default_email); + } + } + } + } catch (error) { + console.log('Could not load default email from config:', error); + // Fail silently - this is not critical functionality } }