75 lines
2.0 KiB
Bash
75 lines
2.0 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
# SCAR Chat - Database Setup Demo
|
||
|
|
# This script demonstrates the database management capabilities
|
||
|
|
|
||
|
|
set -e
|
||
|
|
|
||
|
|
DB_TOOL="./build/dbmanager"
|
||
|
|
DB_FILE="scar_chat.db"
|
||
|
|
|
||
|
|
echo "================================================"
|
||
|
|
echo "SCAR Chat - Database Management Demo"
|
||
|
|
echo "================================================"
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
# Clean up previous demo database
|
||
|
|
if [ -f "$DB_FILE" ]; then
|
||
|
|
echo "[1/7] Removing previous database..."
|
||
|
|
rm "$DB_FILE"
|
||
|
|
sleep 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "[2/7] Creating admin user..."
|
||
|
|
$DB_TOOL register admin AdminSecure123 admin@scar.local admin
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
echo "[3/7] Creating moderator user..."
|
||
|
|
$DB_TOOL register moderator ModeratorPass456 mod@scar.local moderator
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
echo "[4/7] Creating regular users..."
|
||
|
|
$DB_TOOL register alice AlicePassword789 alice@scar.local user
|
||
|
|
$DB_TOOL register bob BobPassword000 bob@scar.local user
|
||
|
|
$DB_TOOL register charlie CharliePass111 charlie@scar.local user
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
echo "[5/7] Listing all users..."
|
||
|
|
$DB_TOOL list
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
echo "[6/7] Testing authentication..."
|
||
|
|
echo " Testing valid credentials (alice)..."
|
||
|
|
if $DB_TOOL authenticate alice AlicePassword789 > /dev/null 2>&1; then
|
||
|
|
echo " ✓ Authentication successful"
|
||
|
|
else
|
||
|
|
echo " ✗ Authentication failed"
|
||
|
|
fi
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
echo " Testing invalid credentials (alice with wrong password)..."
|
||
|
|
if $DB_TOOL authenticate alice WrongPassword > /dev/null 2>&1; then
|
||
|
|
echo " ✗ Unexpected: authentication should have failed"
|
||
|
|
else
|
||
|
|
echo " ✓ Correctly rejected invalid credentials"
|
||
|
|
fi
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
echo "[7/7] Listing admin users..."
|
||
|
|
$DB_TOOL list-role admin
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
echo "================================================"
|
||
|
|
echo "Demo Complete!"
|
||
|
|
echo "================================================"
|
||
|
|
echo ""
|
||
|
|
echo "Database file: $DB_FILE"
|
||
|
|
echo ""
|
||
|
|
echo "Try these commands:"
|
||
|
|
echo " ./build/dbmanager list"
|
||
|
|
echo " ./build/dbmanager list-role user"
|
||
|
|
echo " ./build/dbmanager authenticate alice AlicePassword789"
|
||
|
|
echo " ./build/dbmanager setrole alice admin"
|
||
|
|
echo " ./build/dbmanager deactivate bob"
|
||
|
|
echo ""
|