NoLev commited on
Commit
c7f545b
·
verified ·
1 Parent(s): f05d9f8

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile.txt +26 -0
  2. env +8 -0
  3. package.json +21 -0
  4. schema.txt +100 -0
  5. server.js +80 -0
Dockerfile.txt ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Node.js runtime as the base image
2
+ ARG NODE_VERSION=18
3
+ FROM node:${NODE_VERSION}-slim
4
+
5
+ # Install additional utilities for development (optional for debugging)
6
+ RUN apt-get update && \
7
+ apt-get install -y \
8
+ bash \
9
+ curl \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Set working directory
13
+ WORKDIR /app
14
+
15
+ # Copy package.json and install dependencies
16
+ COPY package.json .
17
+ RUN npm install
18
+
19
+ # Copy the rest of the application code
20
+ COPY . .
21
+
22
+ # Expose the port the app runs on
23
+ EXPOSE 3000
24
+
25
+ # Run the application
26
+ CMD ["npm", "start"]
env ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ DB_HOST=novelcrafter-novelcrafter.g.aivencloud.com
2
+ DB_PORT=12221
3
+ DB_USER=avnadmin
4
+ DB_PASSWORD=AVNS_6uHxC3wASDZVJ_PxQXJ
5
+ DB_NAME=defaultdb
6
+ SESSION_SECRET=your-session-secret
7
+ JWT_SECRET=your-jwt-secret
8
+ PORT=3000
package.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "hyip-app",
3
+ "version": "1.0.0",
4
+ "description": "HYIP web app with user and admin features",
5
+ "main": "server.js",
6
+ "scripts": {
7
+ "start": "node server.js"
8
+ },
9
+ "dependencies": {
10
+ "express": "^4.18.2",
11
+ "mysql2": "^3.6.5",
12
+ "jsonwebtoken": "^9.0.2",
13
+ "bcryptjs": "^2.4.3",
14
+ "dotenv": "^16.3.1",
15
+ "node-cron": "^3.0.2",
16
+ "express-session": "^1.17.3",
17
+ "ejs": "^3.1.9",
18
+ "multer": "^1.4.5-lts.1",
19
+ "axios": "^1.7.2"
20
+ }
21
+ }
schema.txt ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CREATE DATABASE IF NOT EXISTS defaultdb;
2
+ USE defaultdb;
3
+
4
+ CREATE TABLE admins (
5
+ id INT AUTO_INCREMENT PRIMARY KEY,
6
+ username VARCHAR(255) NOT NULL UNIQUE,
7
+ email VARCHAR(255) NOT NULL UNIQUE,
8
+ password VARCHAR(255) NOT NULL,
9
+ full_name VARCHAR(255) NOT NULL,
10
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
11
+ );
12
+
13
+ CREATE TABLE users (
14
+ id INT AUTO_INCREMENT PRIMARY KEY,
15
+ username VARCHAR(255) NOT NULL UNIQUE,
16
+ email VARCHAR(255) NOT NULL UNIQUE,
17
+ password VARCHAR(255) NOT NULL,
18
+ full_name VARCHAR(255) NOT NULL,
19
+ dob DATE NOT NULL,
20
+ address TEXT NOT NULL,
21
+ country VARCHAR(100) NOT NULL,
22
+ zip_code VARCHAR(20) NOT NULL,
23
+ phone_number VARCHAR(20) NOT NULL,
24
+ balance DECIMAL(10,2) DEFAULT 0.00,
25
+ kyc_status VARCHAR(50) DEFAULT 'not_submitted',
26
+ withdrawal_status VARCHAR(50) DEFAULT 'active',
27
+ status VARCHAR(50) DEFAULT 'active',
28
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
29
+ );
30
+
31
+ CREATE TABLE kyc_documents (
32
+ id INT AUTO_INCREMENT PRIMARY KEY,
33
+ user_id INT,
34
+ document_category VARCHAR(50) NOT NULL, -- id, utility, ssn, selfie
35
+ document_type VARCHAR(50) NOT NULL, -- state_id, driver_license, passport, utility_bill, paystub, ssn, selfie
36
+ file_path VARCHAR(255) NOT NULL,
37
+ status VARCHAR(50) DEFAULT 'pending',
38
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
39
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
40
+ );
41
+
42
+ CREATE TABLE investment_plans (
43
+ id INT AUTO_INCREMENT PRIMARY KEY,
44
+ name VARCHAR(255) NOT NULL,
45
+ roi DECIMAL(5,2) NOT NULL,
46
+ tenure INT NOT NULL,
47
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
48
+ );
49
+
50
+ CREATE TABLE investments (
51
+ id INT AUTO_INCREMENT PRIMARY KEY,
52
+ user_id INT,
53
+ plan_id INT,
54
+ amount DECIMAL(10,2) NOT NULL,
55
+ status VARCHAR(50) DEFAULT 'active',
56
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
57
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
58
+ FOREIGN KEY (plan_id) REFERENCES investment_plans(id) ON DELETE SET NULL
59
+ );
60
+
61
+ CREATE TABLE payment_methods (
62
+ id INT AUTO_INCREMENT PRIMARY KEY,
63
+ crypto_name VARCHAR(255) NOT NULL,
64
+ wallet_address VARCHAR(255) NOT NULL,
65
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
66
+ );
67
+
68
+ CREATE TABLE transactions (
69
+ id INT AUTO_INCREMENT PRIMARY KEY,
70
+ user_id INT,
71
+ type VARCHAR(50) NOT NULL,
72
+ amount DECIMAL(10,2) NOT NULL,
73
+ status VARCHAR(50) DEFAULT 'pending',
74
+ wallet_address VARCHAR(255),
75
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
76
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
77
+ );
78
+
79
+ CREATE TABLE messages (
80
+ id INT AUTO_INCREMENT PRIMARY KEY,
81
+ user_id INT,
82
+ message TEXT NOT NULL,
83
+ is_read BOOLEAN NOT NULL DEFAULT FALSE,
84
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
85
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
86
+ );
87
+
88
+ CREATE TABLE testimonials (
89
+ id INT AUTO_INCREMENT PRIMARY KEY,
90
+ author VARCHAR(255) NOT NULL,
91
+ content TEXT NOT NULL,
92
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
93
+ );
94
+
95
+ CREATE TABLE withdrawals (
96
+ id INT AUTO_INCREMENT PRIMARY KEY,
97
+ username VARCHAR(255) NOT NULL,
98
+ amount DECIMAL(10,2) NOT NULL,
99
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
100
+ );
server.js ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const session = require('express-session');
3
+ const authRoutes = require('./routes/auth');
4
+ const userRoutes = require('./routes/user');
5
+ const adminRoutes = require('./routes/admin');
6
+ const investmentRoutes = require('./routes/investment');
7
+ const cron = require('./cron/roiCron');
8
+ const path = require('path');
9
+ const fs = require('fs');
10
+ const multer = require('multer');
11
+ require('dotenv').config();
12
+
13
+ const app = express();
14
+
15
+ // Create upload directory in project root
16
+ const uploadDir = path.join(__dirname, 'kyc_uploads');
17
+ if (!fs.existsSync(uploadDir)) {
18
+ fs.mkdirSync(uploadDir, { recursive: true });
19
+ }
20
+
21
+ // Configure multer for file uploads
22
+ const storage = multer.diskStorage({
23
+ destination: (req, file, cb) => {
24
+ cb(null, uploadDir);
25
+ },
26
+ filename: (req, file, cb) => {
27
+ cb(null, `${Date.now()}-${file.originalname}`);
28
+ }
29
+ });
30
+ const upload = multer({
31
+ storage,
32
+ fileFilter: (req, file, cb) => {
33
+ const allowedTypes = ['image/jpeg', 'image/png', 'application/pdf'];
34
+ if (allowedTypes.includes(file.mimetype)) {
35
+ cb(null, true);
36
+ } else {
37
+ cb(new Error('Invalid file type. Only JPG, PNG, PDF allowed.'));
38
+ }
39
+ },
40
+ limits: { fileSize: 5 * 1024 * 1024 } // 5MB limit
41
+ });
42
+
43
+ app.use(express.json());
44
+ app.use(express.urlencoded({ extended: true }));
45
+ app.use(session({
46
+ secret: process.env.SESSION_SECRET || 'your-secret-key',
47
+ resave: false,
48
+ saveUninitialized: false
49
+ }));
50
+ app.set('view engine', 'ejs');
51
+ app.set('views', path.join(__dirname, 'public/views'));
52
+ app.use(express.static(path.join(__dirname, 'public')));
53
+ app.use('/kyc_uploads', express.static(uploadDir));
54
+
55
+ // Make upload middleware available to routes
56
+ app.use((req, res, next) => {
57
+ req.upload = upload;
58
+ next();
59
+ });
60
+
61
+ // Serve KYC documents securely
62
+ app.get('/admin/kyc-document/:id', async (req, res) => {
63
+ try {
64
+ const [doc] = await require('./config/db').query('SELECT file_path FROM kyc_documents WHERE id = ?', [req.params.id]);
65
+ if (!doc.length) return res.status(404).send('Document not found');
66
+ res.sendFile(path.resolve(doc[0].file_path));
67
+ } catch (error) {
68
+ res.status(500).send('Error retrieving document');
69
+ }
70
+ });
71
+
72
+ app.use('/', authRoutes);
73
+ app.use('/user', userRoutes);
74
+ app.use('/admin', adminRoutes);
75
+ app.use('/investment', investmentRoutes);
76
+
77
+ app.get('/', (req, res) => res.render('index'));
78
+
79
+ const PORT = process.env.PORT || 3000;
80
+ app.listen(PORT, () => console.log(`Server running on port ${PORT}`));