# Coaching Management System

A standalone Node.js web app for admin-managed student accounts and student quiz exams.

## Features

- Separate Admin and Student panels
- Coaching institute profile with branding, contact details, logo, and document headers
- Admin login and Student login
- Add, deactivate, reactivate, and reset student accounts
- CSV import for student accounts
- Student profile fields: name, roll/registration number, student mobile, guardian mobile, college, course, and email
- Question bank with answer explanations
- Create quizzes with MCQ, true/false, short answer, and written questions
- Assign quizzes to selected students
- Exam schedule, retake limit, pass mark, negative marking, random questions, and random answers
- Student exam dashboard with timer-based quiz taking
- Exam autosave and basic tab-switch/copy/paste warning tracking
- Auto scoring, manual review for written answers, pass/fail result, and submission history
- Result CSV export plus result PDF download
- Question bank CSV import/export
- Quiz JSON import/export
- Filtered student and payment CSV/PDF reports
- Batch-based student management
- Quiz duplication as a draft copy
- Printable HTML certificates and certificate PDF download for passed attempts
- Profile and password change
- SMTP-ready result emails with fallback email log
- Admin-managed SMS gateway settings with REVE/custom HTTP provider support, per-feature SMS toggles, SMS templates, OTP/payment/result SMS logs
- Password reset links by email/log
- CSRF protection, rate limiting, login lockout, and security headers
- Activity log for important actions
- SQLite database with JSON backup for simple deployment/testing

## Run

Install dependencies once:

```powershell
npm.cmd install
```

Start the app:

```powershell
npm.cmd start
```

Then open:

```text
http://localhost:3000
```

## Demo Login

Admin:

```text
admin@example.com
admin123
```

Student:

```text
student@example.com
student123
```

## Data

The app creates `data/database.sqlite` and keeps `data/database.json` as a readable backup. Delete both files if you want to reset demo data.

## Optional SMTP

Set these environment variables before starting the app to send real result emails:

```powershell
$env:SMTP_HOST="smtp.example.com"
$env:SMTP_PORT="587"
$env:SMTP_USER="user@example.com"
$env:SMTP_PASS="your-password"
$env:SMTP_FROM="Quiz System <user@example.com>"
npm.cmd start
```

Without SMTP, reset/result emails are stored in the admin Activity → Email Result Log area.

## Optional SMS Gateway

SMS is configured from Admin -> Institute Profile -> SMS Gateway Settings. Turn the SMS system on/off, enable individual SMS types, set templates, and enter REVE SMS or custom HTTP gateway details from the admin panel.

For REVE SMS, keep the default parameter names:

```text
From: callerID
To: toUser
Content: messageContent
Hash: hash
```

If SMS is off or the gateway is not fully configured, messages are kept in Activity -> SMS Log.

## Test

```powershell
npm.cmd test
```

The smoke test starts the app on a temporary port and data folder, then verifies login, CSRF, dashboard, import/export, and password-reset request routes.

## Docker Deployment

```powershell
docker build -t student-quiz-system .
docker run --env-file .env -p 3000:3000 -v ${PWD}\data:/app/data student-quiz-system
```

For HTTPS production deployment, put the app behind Nginx/Caddy and set:

```text
COOKIE_SECURE=true
```

For Hostinger Node.js Web App, also set:

```text
DISABLE_SQLITE=true
DATA_DIR=./data
```

## Notes

This is a complete starter project. Before public production use, enable HTTPS, set strong admin passwords, configure SMTP, and deploy behind a reverse proxy such as Nginx/Caddy.
