Hack ID by hack.sv
A comprehensive identity management system for hack.sv events, built with Flask.
- Google OAuth 2.0 - Secure authentication with Google accounts
- User Registration - Complete profile setup with legal name, preferred name, pronouns, and date of birth
- Session Management - Secure session handling with CSRF protection
- Profile Dashboard - Personalized user dashboard with profile information
- Event Enrollment - Track user participation across multiple events
- Discord Integration - Link Discord accounts and manage server roles
- Pronoun Support - Inclusive pronoun system (he/him/his, she/her/hers, they/them/theirs, other)
- Admin Panel - Comprehensive user management interface
- API Key System - Secure API access with Bearer token authentication
- Data Import/Export - CSV and JSON data processing capabilities
- User Analytics - Event participation tracking and statistics
- GDPR Compliant - Full data deletion and privacy controls
- Opt-out System - Permanent data deletion with secure token system
- Privacy Policy - Comprehensive privacy documentation
- Data Minimization - Collect only necessary information
- Automatic Cleanup - Temporary event data auto-deletion
- CSRF Protection - All forms protected against CSRF attacks
- Session Security - Secure session cookies with httpOnly flag
- Input Validation - All user inputs validated and sanitized
- SQL Injection Prevention - Parameterized queries throughout
- Rate Limiting - API endpoints protected against abuse (disabled in development)
- Privacy by Design - Minimal data collection and automatic cleanup
- Python 3.8+
- Google Cloud Platform account
- Discord Bot (optional, for Discord integration)
- AWS SES account (optional, for email notifications)
git clone https://github.com/your-org/hack-id.git
cd hack-id
pip install -r requirements.txtCopy the example environment file and configure your settings:
cp .env.example .envEdit .env with your configuration:
# Required - Flask Configuration
SECRET_KEY=your-super-secret-key-here
PROD=FALSE
# Required - Google OAuth
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
# Optional - Discord Integration
DISCORD_BOT_TOKEN=your-discord-bot-token
DISCORD_GUILD_ID=your-discord-server-id
# Optional - Email Notifications
MAIL_HOST=email-smtp.us-west-1.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=your-aws-ses-smtp-username
MAIL_PASSWORD=your-aws-ses-smtp-password- Visit Google Cloud Console
- Create a new project or select existing
- Enable the Google+ API and People API
- Create OAuth 2.0 credentials
- Add authorized redirect URIs:
- Development:
http://127.0.0.1:3000/auth/google/callback - Production:
https://yourdomain.com/auth/google/callback
- Development:
The database will be automatically created on first run:
python app.pyConfigure your admin email in models/admin.py or use the admin panel to manage permissions.
hack-id/
βββ app.py # Main Flask application
βββ config.py # Configuration management
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ PRIVACY.md # Privacy policy
βββ generate_opt_out_links.py # Privacy compliance script
β
βββ models/ # Data models
β βββ user.py # User management
β βββ admin.py # Admin permissions
β βββ opt_out.py # Privacy opt-out system
β
βββ routes/ # Flask routes
β βββ auth.py # Authentication & registration
β βββ admin.py # Admin panel
β βββ opt_out.py # Privacy management
β
βββ services/ # Business logic
β βββ auth_service.py # Authentication services
β βββ dashboard_service.py # Dashboard data
β βββ data_deletion.py # Privacy compliance
β
βββ utils/ # Utilities
β βββ database.py # Database connection
β βββ db_init.py # Database initialization
β βββ discord.py # Discord API integration
β βββ events.py # Event management
β βββ error_handling.py # Error handling
β
βββ templates/ # HTML templates
β βββ auth.html # Login/registration
β βββ dashboard.html # User dashboard
β βββ register.html # User registration
β βββ admin/ # Admin templates
β βββ opt_out.html # Privacy pages
β
βββ static/ # Static files
βββ events.json # Event definitions
βββ permissions.json # API permissions
| Variable | Required | Description |
|---|---|---|
SECRET_KEY |
Yes | Flask secret key for sessions |
PROD |
No | Set to TRUE for production mode |
GOOGLE_CLIENT_ID |
Yes | Google OAuth client ID |
GOOGLE_CLIENT_SECRET |
Yes | Google OAuth client secret |
DISCORD_BOT_TOKEN |
No | Discord bot token for integration |
DISCORD_GUILD_ID |
No | Discord server ID |
MAIL_HOST |
No | AWS SES SMTP host |
MAIL_PORT |
No | AWS SES SMTP port (587) |
MAIL_USERNAME |
No | AWS SES SMTP username |
MAIL_PASSWORD |
No | AWS SES SMTP password |
For production deployment:
- Set
PROD=TRUEin your environment - Use HTTPS for all URLs
- Configure proper database backups
- Set up monitoring and logging
- Review security settings in
config.py
Coolify is a self-hosted platform-as-a-service that makes deployment easy. This project includes Docker configuration for seamless Coolify deployment.
- A Coolify instance (self-hosted or managed)
- A GitHub/GitLab repository with this code
- Domain name (optional, but recommended for production)
-
Create a New Resource in Coolify
- Log into your Coolify dashboard
- Click "New Resource" β "Application"
- Select your Git repository
-
Configure Build Settings
- Build Pack: Select "Dockerfile" (recommended) or "Nixpacks"
- Dockerfile Path:
Dockerfile(default) - Port:
3000
-
Set Environment Variables
In Coolify's environment variables section, add the following:
# Required - Flask Configuration SECRET_KEY=your-super-secret-key-here PROD=TRUE # Required - Google OAuth GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret REDIRECT_URI=https://yourdomain.com/auth/google/callback # Optional - Discord Integration DISCORD_BOT_TOKEN=your-discord-bot-token DISCORD_GUILD_ID=your-discord-server-id # Optional - Email Notifications (AWS SES) MAIL_HOST=email-smtp.us-west-1.amazonaws.com MAIL_PORT=587 MAIL_USERNAME=your-aws-ses-smtp-username MAIL_PASSWORD=your-aws-ses-smtp-password EMAIL_SENDER=your-email@domain.com EMAIL_SENDER_NAME=Your Name # Optional - PostHog Analytics POSTHOG_API_KEY=your-posthog-api-key POSTHOG_HOST=https://us.i.posthog.com POSTHOG_ENABLED=true # Optional - Listmonk Integration LISTMONK_URL=https://mail.yourdomain.com LISTMONK_API_KEY=your-listmonk-api-key LISTMONK_ENABLED=true
-
Configure Persistent Storage
Add a persistent volume for the SQLite database:
- Source Path:
/app/users.db - Destination Path:
/data/users.db - This ensures your database persists across deployments
Note: The database and all tables will be automatically created on first startup. If you have an existing database, see the "Uploading an Existing Database" section below.
- Source Path:
-
Set Up Health Checks
Coolify will automatically use the health check defined in the Dockerfile:
- Health Check URL:
/health - Interval: 30 seconds
- Health Check URL:
-
Deploy
- Click "Deploy" to start the deployment
- Coolify will build the Docker image and start the container
- Monitor the build logs for any errors
-
Configure Domain (Optional)
- In Coolify, go to "Domains" section
- Add your custom domain
- Coolify will automatically handle SSL certificates via Let's Encrypt
If you want to run the Discord bot alongside the web app:
-
Option 1: Separate Service in Coolify
- Create a new application in Coolify
- Use the same repository
- Set Start Command:
python discord_bot.py - Add the same environment variables (especially
DISCORD_BOT_TOKENandDISCORD_GUILD_ID) - Mount the same database volume to share data with the web app
-
Option 2: Docker Compose (Advanced)
- Use the included
docker-compose.ymlfile - In Coolify, select "Docker Compose" as the build pack
- This will run both the web app and Discord bot in the same deployment
- Use the included
For deploying to other platforms (Railway, Render, Fly.io, etc.):
# Build the image
docker build -t hack-id .
# Run the container
docker run -d \
-p 3000:3000 \
-e SECRET_KEY=your-secret-key \
-e PROD=TRUE \
-e GOOGLE_CLIENT_ID=your-client-id \
-e GOOGLE_CLIENT_SECRET=your-client-secret \
-v $(pwd)/data:/app/data \
hack-id# Create a .env file with your environment variables
cp .env.example .env
# Edit .env with your values
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose downImportant: The SQLite database (users.db) must be persisted across deployments:
- Coolify: Use persistent volumes (configured in step 4 above)
- Docker: Mount a volume to
/app/users.dbor/app/data - Docker Compose: The included
docker-compose.ymlalready configures this
If you have an existing users.db file with configured users and admins, you can upload it to Coolify:
Method 1: Using Coolify's File Manager (Easiest)
- In Coolify, go to your application
- Navigate to "Storages" or "Volumes" section
- Find the persistent volume for the database
- Use the file manager to upload your
users.dbfile - Restart the application
Method 2: Using SSH/SCP
- Find your Coolify server's SSH details
- Locate the volume path (usually something like
/var/lib/docker/volumes/...) - Upload the database file:
# From your local machine scp users.db user@your-server:/path/to/volume/users.db - Restart the application in Coolify
Method 3: Using Docker Commands on Server
- SSH into your Coolify server
- Find your container:
docker ps | grep hack-id - Copy the database into the container:
docker cp users.db <container-id>:/app/users.db
- Restart the container in Coolify
Important Notes:
- Make sure to backup your existing database before uploading
- The database file should have proper permissions (readable by the container)
- After uploading, verify the database is working by checking the health endpoint
- The application will automatically create tables if they don't exist, but won't overwrite existing data
After deploying:
- Verify the health check endpoint:
https://yourdomain.com/health - Test Google OAuth login flow
- Set up your first admin user (see Admin Setup section)
- Configure database backups
- Test Discord integration (if enabled)
- Review application logs for any errors
- Set up monitoring and alerts
- CSRF Protection - All forms protected against CSRF attacks
- Session Security - Secure session cookies with httpOnly flag
- Input Validation - All user inputs validated and sanitized
- SQL Injection Prevention - Parameterized queries throughout
- Rate Limiting - API endpoints protected against abuse (disabled in development)
- Privacy by Design - Minimal data collection and automatic cleanup
The system includes a RESTful API with Bearer token authentication:
curl -H "Authorization: Bearer your-api-key" \
https://yourdomain.com/api/usersGET /api/users- List users (admin only)GET /api/events- List eventsPOST /api/users/{id}/events- Enroll user in eventDELETE /api/users/{id}- Delete user (privacy compliance)
This system is designed with privacy-first principles:
- Right to Access - Users can view all their data
- Right to Rectification - Users can update their information
- Right to Erasure - Complete data deletion system
- Right to Portability - Data export functionality
- Data Minimization - Only collect necessary information
- Opt-out Links - Generate permanent deletion links for email campaigns
- Automatic Cleanup - Temporary event data deleted after events
- Privacy Dashboard - Users control their data
python generate_opt_out_links.py --output privacy_links.csv- Create a Discord application at Discord Developer Portal
- Create a bot and copy the token
- Invite bot to your server with appropriate permissions
- Configure
DISCORD_BOT_TOKENandDISCORD_GUILD_ID
- Automatic role assignment for verified users
- Discord username display on dashboard
- Role removal during data deletion
When DEBUG_MODE=True (default when PROD=FALSE):
- Rate limiting disabled - No API or endpoint rate limits
- Detailed error messages - Full stack traces and debug info
- Auto-reload - Server restarts on code changes
- Debug logging - Verbose console output
python -m pytest tests/# Initialize database
python utils/db_init.py
# Import user data
python import_users.py
# Generate privacy links
python generate_opt_out_links.py- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue on GitHub
- Check the Privacy Policy for data handling information
- Review the configuration documentation above
- Built with Flask and modern web security practices
- Designed for hackathon organizers and event management
- Privacy-first approach inspired by GDPR and modern data protection standards