The Checklist Application is a central management panel that connects multiple company free zones into a single unified dashboard. This application leverages Express.js for server-side logic, integrates MySQL for database management, and utilizes session handling for secure user authentication. The application also incorporates real-time features using Socket.IO and provides OTP-based email authentication.
- Features
- Installation
- Usage
- Environment Variables
- CORS Configuration
- Running the Application
- License
- Centralized management for multiple free zones.
- User session management with MySQL session store.
- Secure OTP-based authentication via email.
- File uploads and dynamic content rendering.
- Integration with external services using Socket.IO and Axios.
- Domain-based configuration management.
-
Clone the repository:
git clone https://github.com/yourusername/checklist-app.git cd checklist-app
-
Install the required dependencies:
npm install
-
Set up the MySQL database and configure the
.env
file with your database credentials:DB_HOST=your_database_host DB_USER=your_database_user DB_PASSWORD=your_database_password DB_NAME=your_database_name PORT=1002
-
Run the application:
npm start
-
Domain Check Middleware: Fetches the configuration for the current domain and loads it into the session and request objects.
const domainCheck = async (req, res, next) => { // Middleware logic here }; app.use(domainCheck);
-
Session Management: Sessions are stored using
express-mysql-session
.const sessionStore = new MySQLStore({ expiration: 86400000 }, db); app.use(session({ store: sessionStore, secret: 'your_secret_key', resave: true, saveUninitialized: true, }));
-
Login: Handles user login and OTP generation.
app.post('/login', async (req, res) => { // Login logic here });
-
Verify OTP: Validates the OTP entered by the user.
app.post('/verifyOTP', (req, res) => { // OTP verification logic here });
-
Dashboard: Main dashboard displaying the connected free zones and company files.
app.get('/dashboard/:ctaas', sessionCheck, async (req, res) => { // Dashboard logic here });
-
Encrypt: Encrypts sensitive data using AES-256-CBC.
function encrypt(text, secretKey) { const cipher = crypto.createCipher('aes-256-cbc', secretKey); let encrypted = cipher.update(text, 'utf8', 'hex'); encrypted += cipher.final('hex'); return encrypted; }
-
Decrypt: Decrypts data encrypted with AES-256-CBC.
function decrypt(text, secretKey) { const decipher = crypto.createDecipher('aes-256-cbc', secretKey); let decrypted = decipher.update(text, 'hex', 'utf8'); decrypted += decipher.final('utf8'); return decrypted; }
-
OTP Generation: Generates a 6-digit OTP.
function generateOTP() { let otp = ''; for (let i = 0; i < 6; i++) { otp += Math.floor(Math.random() * 10); } return otp; }
-
Sending OTP via Email: Sends the generated OTP to the user's email using
nodemailer
.async function sendOTPEmail(email, otp, companyName, companyAddress) { const mailOptions = { from: `${companyName} <no-reply@yourdomain.com>`, to: email, subject: `${companyName} Login OTP`, html: `<p>Your OTP is ${otp}</p>` }; await transporter.sendMail(mailOptions); }
-
Domain Configuration Table: Stores domain-specific configurations.
CREATE TABLE domain_config ( id INT AUTO_INCREMENT PRIMARY KEY, domain VARCHAR(255) UNIQUE, location_id INT, logo_url VARCHAR(255), background VARCHAR(255), -- Add other configuration fields );
-
Users Table: Stores user credentials and roles.
CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(255), email VARCHAR(255) UNIQUE, password VARCHAR(255), role ENUM('admin', 'Freezone', 'Central'), status ENUM('active', 'inactive') );
- Real-time Communication: Socket.IO is used for real-time communication with the central server.
const socket = io.connect('https://run.crmsoftware.ae/'); socket.on('connect', () => { console.log('Connected to CRM software'); });
Set up the following environment variables in your .env
file:
DB_HOST=your_database_host
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
PORT=1002