Skip to content

abdulboyprogramming-arch/reg-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ Registration System

A complete, production-ready registration system built from scratch with Python, PostgreSQL, and MongoDB. No frontend frameworks, no Python web frameworks - just pure code.

License: MIT Python 3.8+ PostgreSQL MongoDB

πŸš€ Features

Frontend

  • πŸ“ Complete Registration Form with 20+ field types:
    • Text, Email, Password, Telephone
    • Date picker, Country dropdown, City input
    • Radio buttons (Gender, Contact method)
    • Checkboxes (Interests, Terms & Conditions)
    • File uploads (Profile picture, Resume, Multiple files)
    • Textarea (Bio), URL (Website), Social media handles
  • βœ… Real-time validation and username/email availability checking
  • πŸ” User login with secure session management
  • πŸ“Š User dashboard with activity feed and statistics
  • πŸ‘‘ Admin panel with complete user management
  • πŸ“± Fully responsive design for all devices

Backend

  • πŸš€ Pure Python HTTP server (no Flask/Django dependencies)
  • πŸ”’ Secure session-based authentication with HTTP-only cookies
  • πŸ“ File upload handling with validation and secure storage
  • πŸ”‘ Password hashing with SHA-256 (upgradable to bcrypt)
  • πŸ“ Comprehensive activity logging for audit trails
  • 🎯 RESTful API endpoints for all operations

Databases

  • PostgreSQL: Structured user data with JSONB support for flexible metadata
  • MongoDB: Activity logs, user sessions, and dynamic form submissions

πŸ“‹ Table of Contents

πŸ›  Tech Stack

Component Technology Version
Backend Python (http.server) 3.8+
Database (Structured) PostgreSQL 13+
Database (Unstructured) MongoDB 4.4+
Frontend HTML5, CSS3, Vanilla JS -
Authentication Session-based with cookies -
Password Security SHA-256 hashing -

πŸ“ Project Structure

registration_system/
β”‚
β”œβ”€β”€ backend/                         # Python backend server
β”‚   β”œβ”€β”€ server.py                   # Main HTTP server (entry point)
β”‚   β”œβ”€β”€ db_postgres.py              # PostgreSQL database operations
β”‚   β”œβ”€β”€ db_mongo.py                 # MongoDB database operations
β”‚   β”œβ”€β”€ routes/                     # API route handlers
β”‚   β”‚   β”œβ”€β”€ __init__.py            # Makes routes a Python package
β”‚   β”‚   β”œβ”€β”€ register.py            # Registration & login endpoints
β”‚   β”‚   β”œβ”€β”€ admin.py               # Admin management endpoints
β”‚   β”‚   └── api.py                 # General API endpoints
β”‚   └── templates/                  # HTML templates
β”‚       └── base.html              # Base template for pages
β”‚
β”œβ”€β”€ frontend/                        # Static frontend files
β”‚   β”œβ”€β”€ index.html                 # Landing page
β”‚   β”œβ”€β”€ register.html              # Registration form (20+ fields)
β”‚   β”œβ”€β”€ login.html                 # User login page
β”‚   β”œβ”€β”€ dashboard.html             # User dashboard
β”‚   β”œβ”€β”€ admin.html                 # Admin panel
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css             # Responsive CSS styles
β”‚   └── js/
β”‚       └── app.js                # Frontend JavaScript logic
β”‚
β”œβ”€β”€ uploads/                         # Uploaded files (auto-created)
β”‚   └── .gitkeep                   # Keep directory in version control
β”‚
β”œβ”€β”€ .env.example                    # Environment variables template
β”œβ”€β”€ .gitignore                      # Git ignore rules
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ PROJECT_STRUCTURE.md            # Detailed structure documentation
└── README.md                       # This file

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

Β· Python 3.8 or higher - Download Β· PostgreSQL 13 or higher - Download Β· MongoDB 4.4 or higher - Download Β· Git (optional) - Download

πŸ”§ Installation

  1. Clone the Repository
git clone https://github.com/abdulboyprogramming-arch/reg-system.git
cd reg-system
  1. Create and Activate Virtual Environment
# Windows
python -m venv venv
venv\Scripts\activate

# Linux/Mac
python3 -m venv venv
source venv/bin/activate
  1. Install Python Dependencies
pip install -r requirements.txt
  1. Setup PostgreSQL
-- Connect to PostgreSQL
psql -U postgres

-- Create database
CREATE DATABASE reg_system;

-- Create user (optional, if you want a dedicated user)
CREATE USER reg_user WITH PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE reg_system TO reg_user;

-- Exit
\q
  1. Setup MongoDB

MongoDB typically runs on default settings:

Β· URI: mongodb://localhost:27017/ Β· Database: registration_system (auto-created)

To verify MongoDB is running:

# Check MongoDB status
mongod --version

# Connect to MongoDB
mongosh

βš™οΈ Configuration

  1. Create Environment File

Copy the example environment file and update with your credentials:

cp .env.example .env
  1. Edit .env with Your Credentials
# PostgreSQL Configuration
DB_NAME=reg_system
DB_USER=postgres
DB_PASSWORD=your_actual_password_here
DB_HOST=localhost
DB_PORT=5432

# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/
MONGODB_DB_NAME=registration_system

# Security
SECRET_KEY=your-super-secret-key-here-change-this-in-production
SESSION_TIMEOUT_HOURS=24

# Server Configuration
PORT=8080
DEBUG=False

# File Upload Configuration
MAX_FILE_SIZE=5242880  # 5MB in bytes
ALLOWED_EXTENSIONS=jpg,jpeg,png,gif,pdf,doc,docx
  1. Test Database Connections
# Create a test script or run Python commands
python -c "from backend.db_postgres import PostgresDB; PostgresDB()"
python -c "from backend.db_mongo import MongoDB; MongoDB()"

πŸš€ Running the Application

Start the Server

cd backend
python server.py

Access the Application

Open your browser and navigate to:

http://localhost:8080

πŸ—ΊοΈ Default Pages

URL Description Access
/ Landing page (redirects to dashboard if logged in) Public
/register Registration form Public
/login.html Login page Public
/dashboard User dashboard Authenticated
/admin Admin panel Admin only

πŸ“‘ API Endpoints

Public Endpoints

Method Endpoint Description Request Body
POST /api/register Register new user {email, username, password, confirm_password, ...}
POST /api/login User login {username_or_email, password}
POST /api/check-availability Check username/email availability {field, value}
GET /api/session Get current session info -

Authenticated Endpoints

Method Endpoint Description Access
POST /api/upload Upload files Authenticated
POST /api/save-form-data Save custom form data Authenticated
GET /api/user-activity Get user activity logs Authenticated
GET /api/form-submissions Get user form submissions Authenticated
GET /api/stats Get user statistics Authenticated

Admin Endpoints

Method Endpoint Description Access
GET /api/users List all users Admin only
POST /api/update-user Update user details Admin only
GET /api/user-activity?user_id=X View specific user activity Admin only

πŸ—„οΈ Database Schema

PostgreSQL Tables

users Table

Column Type Description
id SERIAL Primary key
email VARCHAR(255) Unique email address
username VARCHAR(100) Unique username
password_hash VARCHAR(255) Hashed password
full_name VARCHAR(255) User's full name
phone VARCHAR(50) Phone number
date_of_birth DATE Date of birth
gender VARCHAR(20) Gender selection
country VARCHAR(100) Country of residence
city VARCHAR(100) City
postal_code VARCHAR(20) Postal/ZIP code
created_at TIMESTAMP Account creation time
updated_at TIMESTAMP Last update time
is_active BOOLEAN Account status
is_admin BOOLEAN Admin privileges
email_verified BOOLEAN Email verification status

user_metadata Table

Column Type Description
user_id INTEGER References users(id)
metadata JSONB Flexible user metadata
preferences JSONB User preferences

email_tokens Table

Column Type Description
id SERIAL Primary key
user_id INTEGER References users(id)
token VARCHAR(255) Unique verification token
expires_at TIMESTAMP Token expiration
used BOOLEAN Token usage status

MongoDB Collections

activity_logs

{
  _id: ObjectId,
  user_id: Number,
  action: String,
  ip_address: String,
  user_agent: String,
  details: Object,
  timestamp: ISODate
}

form_submissions

{
  _id: ObjectId,
  submission_type: String,
  user_id: Number,
  data: Object,
  submitted_at: ISODate
}

user_sessions

{
  _id: ObjectId,
  user_id: Number,
  session_token: String,
  expires_at: ISODate,
  created_at: ISODate
}

πŸ”’ Security Features

Β· βœ… HTTP-only cookies for session storage Β· βœ… Password hashing with SHA-256 (upgradable to bcrypt) Β· βœ… Session expiration (24 hours default) Β· βœ… Account deactivation capability Β· βœ… Input validation and sanitization Β· βœ… Activity logging for audit trails Β· βœ… Admin-only endpoints protection Β· βœ… File upload validation (type and size) Β· βœ… Environment variables for secrets Β· βœ… SQL injection prevention (parameterized queries)

πŸ”§ Extensibility

The system is designed for easy extension:

Add New API Endpoints

  1. Add method in appropriate route class (routes/register.py, routes/admin.py, or routes/api.py)
  2. Add route mapping in server.py

Add New Database Tables

  1. Add creation logic in db_postgres.py init_db() method
  2. Add helper methods for CRUD operations

Add New Frontend Pages

  1. Create HTML file in frontend/
  2. Add route in server.py GET handler

Implement Email Verification

Β· Table email_tokens is ready Β· Add email sending logic in routes/register.py

Add Password Reset

Β· Extend email_tokens table for reset tokens Β· Add new endpoints in routes/api.py

Implement Rate Limiting

Β· Add rate limiter class in server.py Β· Decorate API endpoints with rate limit checks

πŸ› Troubleshooting

Database Connection Errors

Error: psycopg2.OperationalError: could not connect to server

Solution:

# Check if PostgreSQL is running
sudo systemctl status postgresql  # Linux
pg_ctl status  # Mac
# Windows: Check Services

# Verify credentials in .env file
cat .env | grep DB_

MongoDB Connection Errors

Error: pymongo.errors.ServerSelectionTimeoutError

Solution:

# Check if MongoDB is running
sudo systemctl status mongod  # Linux
brew services list | grep mongodb  # Mac
# Windows: Check Services

# Start MongoDB if needed
sudo systemctl start mongod  # Linux
brew services start mongodb  # Mac

File Upload Issues

Error: File too large or File type not allowed

Solution:

Β· Check MAX_FILE_SIZE in .env (default: 5MB) Β· Verify ALLOWED_EXTENSIONS includes your file type Β· Ensure uploads/ directory has write permissions

Session Problems

Issue: Session not persisting or immediate logout

Solution:

Β· Clear browser cookies Β· Check MongoDB user_sessions collection for expired sessions Β· Verify SESSION_TIMEOUT_HOURS in .env

Port Already in Use

Error: Address already in use

Solution:

# Change PORT in .env file
PORT=8081

# Or kill process using the port
# Linux/Mac
lsof -ti:8080 | xargs kill -9
# Windows
netstat -ano | findstr :8080
taskkill /PID <PID> /F

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

Β· Follow PEP 8 style guide for Python code Β· Use meaningful commit messages Β· Update documentation for new features Β· Add tests for new functionality Β· Ensure all existing features work

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

Β· Built with Python's built-in http.server module Β· PostgreSQL for reliable structured data storage Β· MongoDB for flexible document storage Β· Vanilla JavaScript for lightweight frontend

πŸ“ž Support

For issues, questions, or contributions:

Β· Open an issue on GitHub Β· Contact the maintainer Β· Check the troubleshooting section


⚠️ Security Notice: This code is for educational/demonstration purposes. For production use, please implement:

Β· HTTPS with SSL/TLS certificates Β· Strong password hashing (bcrypt/argon2) Β· Rate limiting on all endpoints Β· CSRF protection Β· Regular security updates Β· Database encryption at rest


Made with ❀️ for the developer community

About

Registration system built from scratch with Python, PostgreSQL, MongoDB, and vanilla frontend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors