asteroid/docs/USER-MANAGEMENT-SYSTEM.org

4.1 KiB

User Management System - Complete

Overview

Complete user management system with dedicated admin interface, user creation, role management, and comprehensive API endpoints.

What Was Completed

User Management Page

  • Created dedicated /admin/users route
  • Separate page from main admin dashboard
  • Clean, organized interface for user administration

Features Implemented

User Creation

  • Inline user creation form
  • Fields: username, email, password, role
  • Real-time validation
  • Success/error messaging

User Display

  • List all users with key information
  • Shows: username, email, role, status, creation date
  • Clean table layout with proper formatting

User Statistics

  • Total user count
  • Active/inactive breakdown
  • Role distribution

Role Management

  • Listener role (default)
  • DJ role (content creators)
  • Admin role (full access)

User Actions

  • Activate/deactivate users
  • Role assignment
  • User deletion (future enhancement)

API Endpoints

GET /api/users

Returns all users in the system

{
  "status": "success",
  "users": [
    {
      "id": 2,
      "username": "admin",
      "email": "admin@asteroid.radio",
      "role": "admin",
      "active": true,
      "created-date": 1759214069
    }
  ]
}

GET /api/users/stats

Returns user statistics

{
  "status": "success",
  "total-users": 6,
  "active-users": 6,
  "roles": {
    "admin": 2,
    "listener": 4
  }
}

POST /api/users/create

Creates a new user (requires admin authentication)

POST /asteroid/api/users/create
Content-Type: application/x-www-form-urlencoded

username=newuser&email=user@example.com&password=pass123&role=listener

Files Created/Modified

New Files

  • template/users.chtml - User management template
  • test-user-api.sh - API testing script

Modified Files

  • asteroid.lisp - Added user management routes
  • auth-routes.lisp - Enhanced authentication
  • user-management.lisp - Core user functions

Technical Implementation

Authentication & Authorization

  • Requires admin role for user management
  • Session-based authentication
  • Role-based access control (RBAC)

Database Schema

Users stored in USERS collection with fields:

  • _id - Unique identifier
  • username - Unique username
  • email - Email address
  • password-hash - Bcrypt hashed password
  • role - User role (listener/DJ/admin)
  • active - Active status (boolean)
  • created-date - Unix timestamp
  • last-login - Unix timestamp

Security Features

  • Password hashing with bcrypt
  • Session management
  • CSRF protection (via Radiance)
  • Role-based access control

Testing

API Testing Script

Created test-user-api.sh for comprehensive testing:

# Test user statistics
curl -s http://localhost:8080/asteroid/api/users/stats | jq .

# Test user creation (with authentication)
curl -s -b cookies.txt -X POST http://localhost:8080/asteroid/api/users/create \
  -d "username=testuser" \
  -d "email=test@example.com" \
  -d "password=testpass123" \
  -d "role=listener" | jq .

Test Results

  • All API endpoints working
  • User creation successful
  • Authentication working
  • Role assignment working
  • 6 users created and tested

Usage

Creating a User

  1. Navigate to /asteroid/admin/users
  2. Fill in the user creation form
  3. Select appropriate role
  4. Click "Create User"
  5. User appears in the list immediately

Managing Users

  1. View all users in the table
  2. See user details (email, role, status)
  3. Track creation dates
  4. Monitor active/inactive status

Integration

With Admin Dashboard

  • Link from main admin dashboard
  • Consistent styling and navigation
  • Integrated authentication

With Authentication System

  • Uses existing auth-routes.lisp
  • Leverages session management
  • Integrates with role system

Future Enhancements (Requires PostgreSQL)

  • User editing
  • Password reset
  • Email verification
  • User activity logs
  • Advanced permissions

Status: COMPLETE

User management system fully functional and production-ready. All core features implemented and tested.