Skip to content

Latest commit

 

History

History
622 lines (467 loc) · 16.1 KB

File metadata and controls

622 lines (467 loc) · 16.1 KB

🎯 LA TANDA ADMIN SYSTEM - COMPLETE GUIDE

Date: October 26, 2025 21:40 UTC For: ebanksnigel@gmail.com (Super Admin) Status: Admin Login Working | Panel Investigation Complete


1️⃣ HOW ADMIN LOGIN WORKS

Admin Panel Access

🌐 Admin Panel URL:

https://latanda.online/admin-panel-v2.html

🔐 How It Works:

  1. Frontend Protection (JavaScript)

    • Page checks for latanda_auth_token in localStorage
    • Requires role: "administrator", "admin", "MIT", or "IT"
    • Redirects to /auth-enhanced.html if not authenticated
    • After login, redirects back to admin panel
  2. Login Page

    • Uses /auth-enhanced.html (enhanced authentication page)
    • Sends credentials to API endpoint
  3. API Login Endpoint

    • URL: https://api.latanda.online/api/admin/login
    • Method: POST
    • Body:
      {
        "username": "admin",
        "password": "[REDACTED-ROTATE-PASSWORD]"
      }
  4. Frontend Login Code (Line 1167 in admin-panel-v2.html)

    const response = await fetch('https://api.latanda.online/api/admin/login', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ username, password })
    });

Login Flow Diagram

User visits /admin-panel-v2.html
    ↓
JavaScript checks localStorage for auth_token
    ↓
[NO TOKEN] → Redirect to /auth-enhanced.html
    ↓
User enters: username=admin, password=[REDACTED-ROTATE-PASSWORD]
    ↓
POST /api/admin/login
    ↓
Backend validates credentials
    ↓
Returns: {success: true, token: "...", user: {...}}
    ↓
Frontend stores token in localStorage
    ↓
Redirect back to admin-panel-v2.html
    ↓
[HAS TOKEN] → Load admin panel

2️⃣ ADMIN PANEL CAPABILITIES

✅ What the Frontend CAN Handle

The admin panel (/admin-panel-v2.html) has UI for these features:

1. Dashboard (Statistics)

  • Total Users count
  • Active Groups count
  • Pending Deposits count
  • Total Transactions

2. Deposit ManagementFULLY FUNCTIONAL

  • View pending deposits
  • Approve deposits (requires confirm_deposits permission)
  • Reject deposits (requires reject_deposits permission)
  • View deposit history

3. User ManagementHAS UI

  • View all users
  • Search users
  • View user details

4. Transaction ViewingHAS UI

  • View all transactions (requires view_all_transactions permission)
  • Filter by status, date, amount

5. KYC ManagementHAS UI

  • View pending KYC verifications
  • Approve/reject KYC submissions
  • View KYC documents

⚠️ What Your Permissions Allow

Your Current Permissions (8 total):

✅ confirm_deposits       - Approve user deposits
✅ reject_deposits        - Reject fraudulent deposits
✅ view_all_transactions  - View all platform transactions
✅ manage_users           - User management operations
✅ manage_kyc             - KYC verification
✅ view_audit_logs        - Security audit logs
✅ manage_groups          - Group administration
✅ platform_admin         - Full platform access

Frontend Permission Checks:

// Line 1234 in admin-panel-v2.html
if (currentUser.permissions.includes('confirm_deposits')) {
    // Show approve button
}

The frontend checks your permissions and enables/disables UI elements accordingly.


3️⃣ ADMIN ENDPOINTS STATUS

✅ Working Endpoints

Endpoint Method Status Your Access
/api/admin/login POST ✅ Working ✅ Public (login)
/api/admin/verify POST ⚠️ Has bug ✅ Should work after fix

❌ Broken Endpoints (2FA Enforcement Bug)

Problem: "session is not defined" error in require2FAForAdmin() function

Affected Endpoints:

Endpoint Method Impact
/api/admin/kyc/pending GET ❌ Returns 404
/api/admin/users GET ❌ Fails
/api/admin/verify POST ❌ 500 error
ALL OTHER ADMIN ENDPOINTS Various ⚠️ Likely affected

Error in Logs:

Server error: ReferenceError: session is not defined
    at require2FAForAdmin (/root/enhanced-api-production-complete.js:734:5)
    at Server.<anonymous> (/root/enhanced-api-production-complete.js:4603:33)

Root Cause: The 2FA enforcement code we added calls require2FAForAdmin(dbUser) but references a session variable that doesn't exist in that scope.

Code Location: Line 734 in /root/enhanced-api-production-complete.js

Quick Fix Needed: The require2FAForAdmin() function needs to receive session as a parameter, or the code calling it needs to be adjusted.


4️⃣ ROLE ASSIGNMENT SYSTEM

✅ MANUAL ROLE ASSIGNMENT (You Control It)

System Type: MANUAL (Administrator-controlled)

How It Works:

  1. Admin Assigns Roles via API

    • Endpoint: POST /api/admin/users/:id/assign-role
    • Requires: Admin authentication + token
    • Your Permission:manage_users (you have this)
  2. Available Roles (Backend supports these)

    • super_admin - Full platform access (YOU)
    • admin - Standard admin
    • user - Regular user (default)
    • moderator - Limited admin
    • coordinator - Group coordinator
    • suspended - Suspended user
  3. Get Available Roles

    • Endpoint: GET /api/admin/users/roles
    • Returns list of all assignable roles

Example: Assigning a Role

# Get your session token first
TOKEN="[from login response]"

# Assign role to user
curl -X POST https://api.latanda.online/api/admin/users/user_123abc/assign-role \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"role": "admin"}'

❌ NO Achievement-Based Role System

Current State: No automatic role upgrades

Future Possibility:

  • You could build an achievement system
  • Achievements would grant points/badges
  • But roles would still be manually assigned by admins
  • Achievements don't automatically change roles

43 Users with null Roles

Issue: 43 out of 44 users have role: null

Impact:

  • Regular user login still works (uses email, not role)
  • They can't access role-restricted features
  • Doesn't affect basic user functions

Solution: You would need to manually assign roles to these users using the /api/admin/users/:id/assign-role endpoint.


5️⃣ SMTP EMAIL SYSTEM

Current Status: ⚠️ NOT CONFIGURED

What "SMTP_PASS still needs verification" Means:

This is asking YOU to verify/configure the email system, not asking you to check if it's working.

For: System capabilities (sending emails from the platform)

Current Configuration:

// In enhanced-api-production-complete.js (lines 473-480)
const emailConfig = {
    host: 'smtp.gmail.com',        Set
    port: 587,                      Set
    secure: false,                  Set
    auth: {
        user: process.env.SMTP_USER || 'noreply@latanda.online',  ⚠️ Defaults to noreply@
        pass: process.env.SMTP_PASS || ''    EMPTY (not set)
    }
};

Environment Variables Check:

ssh root@168.231.67.201 "printenv | grep SMTP"
# Returns: (empty)

Result: SMTP password is NOT SET in environment

Why Email Matters

Email Functions in the System:

// 1. 2FA Code Delivery
send2FAEmail(email, code, userName)

// 2. Registration Verification
sendVerificationEmail(email, code, userName)

// 3. Password Reset
sendPasswordResetEmail(email, resetLink, userName)

What Doesn't Work Without SMTP:

  • ❌ 2FA codes won't be delivered to your email
  • ❌ User registration verification emails fail
  • ❌ Password reset emails fail
  • ❌ Admin notifications won't send

How to Configure SMTP (Your Action Required)

Option 1: Gmail App Password (Recommended)

  1. Go to Google Account Security:

    https://myaccount.google.com/security
    
  2. Enable 2-Step Verification

    • Required for App Passwords
  3. Generate App Password:

  4. Set Environment Variables:

    ssh root@168.231.67.201
    
    # Add to .bashrc
    echo "export SMTP_USER='ebanksnigel@gmail.com'" >> ~/.bashrc
    echo "export SMTP_PASS='your-16-char-password-here'" >> ~/.bashrc
    source ~/.bashrc
    
    # Restart API with new environment
    pm2 restart latanda-api --update-env
  5. Test Email:

    # Should trigger a 2FA email
    curl -X POST http://localhost:3002/api/auth/enable-2fa \
      -H "Authorization: Bearer [YOUR_TOKEN]"
    
    # Check your inbox: ebanksnigel@gmail.com

Option 2: Use SendGrid (Production Alternative)

  • More reliable for production
  • Higher sending limits
  • Better deliverability
  • Requires SendGrid API key setup

6️⃣ YOUR ADMIN CREDENTIALS

Login Information

🔑 Username: admin
🔒 Password: [REDACTED-ROTATE-PASSWORD]
📧 Email: ebanksnigel@gmail.com
👑 Role: super_admin

How to Login

Method 1: Via Admin Panel (Recommended)

  1. Go to: https://latanda.online/admin-panel-v2.html
  2. You'll be redirected to login page
  3. Enter: username: admin, password: [REDACTED-ROTATE-PASSWORD]
  4. Admin panel loads with your permissions

Method 2: Direct API Call (Testing)

curl -X POST https://api.latanda.online/api/admin/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"[REDACTED-ROTATE-PASSWORD]"}'

Response:

{
  "success": true,
  "data": {
    "token": "86995b8af6bf46a60a434e1c6a39a22dd9bb2ff4ada8d49df953d07b14335b69",
    "user": {
      "username": "admin",
      "role": "super_admin",
      "permissions": [8 permissions]
    }
  }
}

Session Details

  • Token Length: 64 characters
  • Expiration: 8 hours from login
  • Storage: database.sessions in backend
  • 2FA Status: Enabled (you have 2FA already configured)

7️⃣ WHAT NEEDS FIXING

🚨 Critical: 2FA Enforcement Bug

Issue: session is not defined error in require2FAForAdmin()

Impact: Most admin endpoints return 404 or 500 errors

Affected:

  • /api/admin/kyc/pending - 404
  • /api/admin/users - Fails
  • /api/admin/verify - 500 error
  • Possibly all admin endpoints except login

Fix Required: Adjust the 2FA enforcement code to pass session properly to require2FAForAdmin() function.

⚠️ Medium: SMTP Not Configured

Issue: Email system configured but password not set

Impact:

  • 2FA codes won't be delivered
  • Registration emails fail
  • Password resets fail

Fix Required: Set SMTP_USER and SMTP_PASS environment variables (see Section 5)

📝 Low: 43 Users with null Roles

Issue: Regular users don't have roles assigned

Impact:

  • Regular user login works
  • Role-based features won't work for them
  • Not blocking admin functions

Fix Required: Use /api/admin/users/:id/assign-role to assign roles


8️⃣ NEXT STEPS

Immediate (Fix Admin Endpoints)

  1. Fix 2FA Enforcement Bug ⚠️ CRITICAL

    • Prevents all admin endpoints from working
    • Need to adjust require2FAForAdmin() calls
  2. Test Admin Panel Access

Short-term (Email System)

  1. Configure SMTP 📧
    • Get Gmail App Password
    • Set SMTP_USER and SMTP_PASS env vars
    • Restart API
    • Test 2FA email delivery

Optional (User Management)

  1. Assign Roles to Users
    • Use /api/admin/users/:id/assign-role
    • Assign appropriate roles to 43 users
    • Enable role-based features

9️⃣ SUMMARY OF YOUR QUESTIONS

Q1: "Should we investigate the 404 endpoints?"

A:INVESTIGATED

Finding:

  • Endpoints exist in code (line 2392 for KYC)
  • PM2 running correct file
  • Problem: 2FA enforcement code has bug (session is not defined)
  • This causes endpoints to crash before reaching their logic
  • Returns 404 or 500 instead of working

Q2: "How is admin login set up? Separate page or platform section?"

A:SEPARATE PAGE + UNIFIED LOGIN

Setup:

  • Admin Panel: Separate page (/admin-panel-v2.html)
  • Login Page: Unified (/auth-enhanced.html)
  • API Endpoint: Dedicated admin endpoint (/api/admin/login)

Flow:

  1. Visit admin panel → Redirects to auth page
  2. Login with admin credentials
  3. Redirects back to admin panel
  4. Admin panel checks role and enables admin UI

Q3: "Is the admin panel frontend capable of handling all 8 permissions?"

A:YES (Partially Implemented)

Frontend Has UI For:

  • confirm_deposits - Approve button visible if you have permission
  • reject_deposits - Reject button visible if you have permission
  • view_all_transactions - Transaction list shows all if you have permission
  • manage_kyc - KYC review UI present
  • manage_users - User list present, management UI basic
  • manage_groups - Group list present, management UI basic
  • view_audit_logs - May not have UI yet
  • platform_admin - General admin access

Permission Checking:

// Frontend checks your permissions (line 1234)
if (currentUser.permissions.includes('confirm_deposits')) {
    // Enable approve button
}

Result: The frontend DOES check permissions and shows/hides UI accordingly. Some features have complete UI, others are basic.


Q4: "Am I in charge of assigning roles or does the system have an achievement-based role system?"

A:YOU ARE IN CHARGE (Manual Assignment)

System Type: MANUAL role assignment

How It Works:

  • You use /api/admin/users/:id/assign-role endpoint
  • You have manage_users permission ✅
  • You can assign any role: admin, user, moderator, coordinator, etc.
  • No automatic role upgrades from achievements

Achievement System:

  • Achievements exist separately
  • They grant points/badges/rewards
  • But they DON'T automatically change user roles
  • Roles are always manually assigned by admins (you)

Example:

# You assign admin role to user
curl -X POST https://api.latanda.online/api/admin/users/user_abc123/assign-role \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"role": "admin"}'

Q5: "Is the SMTP_PASS verification for me to verify or for the mailing system?"

A:FOR YOU TO CONFIGURE

Meaning:

  • "Needs verification" = "Needs YOU to set it up"
  • It's for the mailing system capabilities
  • The email system is configured but missing password
  • Without password: emails won't send

What You Need to Do:

  1. Get Gmail App Password (16 characters)
  2. Set environment variables:
    export SMTP_USER="ebanksnigel@gmail.com"
    export SMTP_PASS="your-app-password"
  3. Restart API: pm2 restart latanda-api --update-env

Why It Matters:

  • Your 2FA codes will be sent to your email
  • Without SMTP configured, 2FA codes won't arrive
  • Also affects: registration emails, password resets, admin notifications

Your Email: ebanksnigel@gmail.com (will receive all emails)


🎯 QUICK REFERENCE

Admin Login

URL: https://latanda.online/admin-panel-v2.html
Username: admin
Password: [REDACTED-ROTATE-PASSWORD]
Role: super_admin
Permissions: 8 (all admin functions)

Fix Priority

1. 🚨 CRITICAL: Fix 2FA enforcement bug (session is not defined)
2. 📧 MEDIUM: Configure SMTP email (set SMTP_PASS)
3. 📝 LOW: Assign roles to 43 users

Your Permissions

✅ confirm_deposits
✅ reject_deposits
✅ view_all_transactions
✅ manage_users
✅ manage_kyc
✅ view_audit_logs
✅ manage_groups
✅ platform_admin

Role Assignment

Endpoint: POST /api/admin/users/:id/assign-role
Your Control: ✅ Manual assignment
System: ❌ No automatic role upgrades

Email Configuration

Status: ⚠️ Not configured
Action: Set SMTP_USER and SMTP_PASS
Purpose: Send 2FA codes, verification emails, password resets
Your Email: ebanksnigel@gmail.com

Document Status: ✅ Complete Investigation Last Updated: October 26, 2025 21:40 UTC Maintained by: Claude Code + ebanksnigel@gmail.com