Skip to content
View OkfreelancerAi's full-sized avatar

Block or report OkfreelancerAi

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
OkfreelancerAi/README.md
  • 👋 Hi, I’m @OkfreelancerAi -// Import necessary modules const express = require('express'); const bodyParser = require('body-parser'); const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken');

const app = express(); app.use(bodyParser.json());

// MongoDB connection mongoose.connect('mongodb://localhost:27017/adultContentApp', { useNewUrlParser: true, useUnifiedTopology: true, });

// User schema for authentication and affiliate tracking const userSchema = new mongoose.Schema({ username: { type: String, required: true }, password: { type: String, required: true }, ageVerified: { type: Boolean, default: false }, affiliateCode: { type: String, unique: true }, // Unique affiliate code referredBy: { type: String }, // Tracks who referred the user earnings: { type: Number, default: 0 }, // Earnings from referrals });

userSchema.pre('save', async function (next) { if (this.isModified('password')) { this.password = await bcrypt.hash(this.password, 10); } next(); });

const User = mongoose.model('User', userSchema);

// Content schema for managing videos const contentSchema = new mongoose.Schema({ title: { type: String, required: true }, category: { type: String, required: true }, url: { type: String, required: true }, // Video URL price: { type: Number, required: true }, // Pay-to-watch price });

const Content = mongoose.model('Content', contentSchema);

// Middleware for authentication const authenticate = (req, res, next) => { const token = req.headers.authorization; if (!token) return res.status(401).send('Access denied');

try { const decoded = jwt.verify(token, 'secretKey'); req.user = decoded; next(); } catch (err) { res.status(400).send('Invalid token'); } };

// Routes

// Register a new user app.post('/register', async (req, res) => { const { username, password, referredBy } = req.body;

try { const affiliateCode = ${username}-${Date.now()}; // Generate unique affiliate code const user = new User({ username, password, affiliateCode, referredBy }); await user.save();

// Reward the referrer if applicable
if (referredBy) {
  const referrer = await User.findOne({ affiliateCode: referredBy });
  if (referrer) {
    referrer.earnings += 10; // Example reward for referral
    await referrer.save();
  }
}

res.status(201).send({ message: 'User registered successfully', affiliateCode });

} catch (err) { res.status(400).send(err.message); } });

// Login a user app.post('/login', async (req, res) => { const { username, password } = req.body;

const user = await User.findOne({ username }); if (!user) return res.status(404).send('User not found');

const validPassword = await bcrypt.compare(password, user.password); if (!validPassword) return res.status(400).send('Invalid credentials');

const token = jwt.sign({ id: user._id }, 'secretKey', { expiresIn: '1h' }); res.send({ token }); });

// Add new content (Admin only) app.post('/content', authenticate, async (req, res) => { const { title, category, url, price } = req.body;

try { const content = new Content({ title, category, url, price }); await content.save(); res.status(201).send('Content added successfully'); } catch (err) { res.status(400).send(err.message); } });

// Get all content (Pay-to-watch model) app.get('/content', authenticate, async (req, res) => { try { const contentList = await Content.find(); res.send(contentList); } catch (err) { res.status(500).send(err.message); } });

// Affiliate dashboard to check earnings app.get('/affiliate-dashboard', authenticate, async (req, res) => { try { const user = await User.findById(req.user.id); if (!user) return res.status(404).send('User not found');

res.send({
  username: user.username,
  affiliateCode: user.affiliateCode,
  earnings: user.earnings,
  referredBy: user.referredBy || 'None',
});

} catch (err) { res.status(500).send(err.message); } });

// Start server app.listen(3000, () => console.log('Server running on port 3000')); // Import necessary modules const express = require('express'); const bodyParser = require('body-parser'); const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken');

const app = express(); app.use(bodyParser.json());

// MongoDB connection mongoose.connect('mongodb://localhost:27017/adultContentApp', { useNewUrlParser: true, useUnifiedTopology: true, });

// User schema for authentication and affiliate tracking const userSchema = new mongoose.Schema({ username: { type: String, required: true }, password: { type: String, required: true }, ageVerified: { type: Boolean, default: false }, affiliateCode: { type: String, unique: true }, // Unique affiliate code referredBy: { type: String }, // Tracks who referred the user earnings: { type: Number, default: 0 }, // Earnings from referrals });

userSchema.pre('save', async function (next) { if (this.isModified('password')) { this.password = await bcrypt.hash(this.password, 10); } next(); });

const User = mongoose.model('User', userSchema);

// Content schema for managing videos const contentSchema = new mongoose.Schema({ title: { type: String, required: true }, category: { type: String, required: true }, url: { type: String, required: true }, // Video URL price: { type: Number, required: true }, // Pay-to-watch price });

const Content = mongoose.model('Content', contentSchema);

// Middleware for authentication const authenticate = (req, res, next) => { const token = req.headers.authorization; if (!token) return res.status(401).send('Access denied');

try { const decoded = jwt.verify(token, 'secretKey'); req.user = decoded; next(); } catch (err) { res.status(400).send('Invalid token'); } };

// Routes

// Register a new user app.post('/register', async (req, res) => { const { username, password, referredBy } = req.body;

try { const affiliateCode = ${username}-${Date.now()}; // Generate unique affiliate code const user = new User({ username, password, affiliateCode, referredBy }); await user.save();

// Reward the referrer if applicable
if (referredBy) {
  const referrer = await User.findOne({ affiliateCode: referredBy });
  if (referrer) {
    referrer.earnings += 10; // Example reward for referral
    await referrer.save();
  }
}

res.status(201).send({ message: 'User registered successfully', affiliateCode });

} catch (err) { res.status(400).send(err.message); } });

// Login a user app.post('/login', async (req, res) => { const { username, password } = req.body;

const user = await User.findOne({ username }); if (!user) return res.status(404).send('User not found');

const validPassword = await bcrypt.compare(password, user.password); if (!validPassword) return res.status(400).send('Invalid credentials');

const token = jwt.sign({ id: user._id }, 'secretKey', { expiresIn: '1h' }); res.send({ token }); });

// Add new content (Admin only) app.post('/content', authenticate, async (req, res) => { const { title, category, url, price } = req.body;

try { const content = new Content({ title, category, url, price }); await content.save(); res.status(201).send('Content added successfully'); } catch (err) { res.status(400).send(err.message); } });

// Get all content (Pay-to-watch model) app.get('/content', authenticate, async (req, res) => { try { const contentList = await Content.find(); res.send(contentList); } catch (err) { res.status(500).send(err.message); } });

// Affiliate dashboard to check earnings app.get('/affiliate-dashboard', authenticate, async (req, res) => { try { const user = await User.findById(req.user.id); if (!user) return res.status(404).send('User not found');

res.send({
  username: user.username,
  affiliateCode: user.affiliateCode,
  earnings: user.earnings,
  referredBy: user.referredBy || 'None',
});

} catch (err) { res.status(500).send(err.message); } });

// Start server app.listen(3000, () => console.log('Server running on port 3000')); 1000003355 1000003356 1000003357 1000003358 1000003360 1000003361 1000003751 1000003752 1000003753 1000003754 1000003758 I’m interested in ...

  • 🌱 I’m currently learning ...
  • 💞️ I’m looking to collaborate on ...
  • 📫 How to reach me ...
  • 😄 Pronouns: ...
  • ⚡ Fun fact: ...

Popular repositories Loading

  1. miniapps miniapps Public

    Forked from farcasterxyz/miniapps

    TypeScript 1

  2. chainscout chainscout Public

    Forked from blockscout/chainscout

    TypeScript

  3. next-netlify-starter next-netlify-starter Public

    JavaScript

  4. OkfreelancerAi OkfreelancerAi Public template

    Config files for my GitHub profile.

  5. next-netlify-starter-5cf6f next-netlify-starter-5cf6f Public

    JavaScript

  6. expo expo Public

    Forked from expo/expo

    An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.

    TypeScript