Invitation only for signup
This commit is contained in:
44
Payments.js
Normal file
44
Payments.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
const Stripe = require('stripe');
|
||||||
|
|
||||||
|
const stripe = Stripe(process.env.STRIPE);
|
||||||
|
|
||||||
|
const addNewCustomer = async (email, profile) => {
|
||||||
|
const customer = await Stripe.customers.create({
|
||||||
|
email,
|
||||||
|
description: profile ? profile.firstName + " " + profile.lastName : "new costumer",
|
||||||
|
});
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCustomerByID = async (id) => {
|
||||||
|
const customer = await Stripe.customers.retrieve(id);
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const addNewCustomerCard = async (customer, cardInfo) => {
|
||||||
|
let template = {
|
||||||
|
"address_city": cardInfo.address_city,
|
||||||
|
"address_country": cardInfo.address_country,
|
||||||
|
"address_line1": cardInfo.address_line1,
|
||||||
|
"address_line2": cardInfo.address_line2,
|
||||||
|
"address_state": cardInfo.address_state,
|
||||||
|
"address_zip": cardInfo.address_zip,
|
||||||
|
customer,
|
||||||
|
"exp_month": cardInfo.exp_month,
|
||||||
|
"exp_year": cardInfo.exp_year,
|
||||||
|
"name": cardInfo.name,
|
||||||
|
};
|
||||||
|
const card = await stripe.customers.createSource(
|
||||||
|
'cus_KKsGI28Nrbm61K',
|
||||||
|
template
|
||||||
|
);
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCustomerCard = async (customer, card) => {
|
||||||
|
const card = await stripe.customers.retrieveSource(
|
||||||
|
customer,
|
||||||
|
card
|
||||||
|
);
|
||||||
|
return card;
|
||||||
|
}
|
||||||
31
PromotionalPosts.js
Normal file
31
PromotionalPosts.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
const DB = require("./mongoDB.js");
|
||||||
|
const Post = require("./def/post.js");
|
||||||
|
|
||||||
|
let PromotionalPosts = {};
|
||||||
|
|
||||||
|
DB.getDB.then((DB)=>{
|
||||||
|
PromotionalPosts.PopularGroups = async () => {
|
||||||
|
let groups = DB.getGroups(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PromotionalPosts.PopularCourses = async () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PromotionalPosts.ImportantNews = async () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PromotionalPosts.IntroPost = async () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PromotionalPosts.continueWatchingCourse = async () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = PromotionalPosts;
|
||||||
@@ -134,9 +134,13 @@ userDB = (DB) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Groups
|
//Groups
|
||||||
DB.getGroups = async () => {
|
DB.getGroups = async (excludePrivate = false) => {
|
||||||
let r = await DB.profileCols.find({isGroup: true, isCourse: {$ne: true}})
|
let query = {
|
||||||
.sort({ lastUpdate: -1 }).limit(10)
|
isGroup: true,
|
||||||
|
isCourse: {$ne: true},
|
||||||
|
};
|
||||||
|
if(excludePrivate) query.isPrivate = false;
|
||||||
|
let r = await DB.profileCols.find(query).sort({ lastUpdate: -1 }).limit(10)
|
||||||
.toArray().catch((err) => {
|
.toArray().catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
4
index.js
4
index.js
@@ -73,7 +73,9 @@ DB.getDB.then((DB)=>{
|
|||||||
const password = req.query.password || req.body.password;
|
const password = req.query.password || req.body.password;
|
||||||
const email = req.query.email || req.body.email;
|
const email = req.query.email || req.body.email;
|
||||||
const profile = req.query.profile || req.body.profile;
|
const profile = req.query.profile || req.body.profile;
|
||||||
if(!username || !password || !email) return res.json({status: "fail"})
|
if(!username || !password || !email) return res.json({status: "fail"});
|
||||||
|
//Check if the new user has an invitation
|
||||||
|
if(!await DB.getInvitation(email)) return res.json({status: "Not invitation found!"});
|
||||||
//const hashedPassword = await bcrypt.hash(password, 10);
|
//const hashedPassword = await bcrypt.hash(password, 10);
|
||||||
const hashedPassword = await bcrypt.hash(password, 10);
|
const hashedPassword = await bcrypt.hash(password, 10);
|
||||||
const response = await DB.newUser({
|
const response = await DB.newUser({
|
||||||
|
|||||||
25
mongoDB.js
25
mongoDB.js
@@ -17,6 +17,7 @@ const getDB = new Promise((resolve, reject) => {
|
|||||||
console.log("Connected to DB!");
|
console.log("Connected to DB!");
|
||||||
DB.usersCol = db.db(DBName).collection("users");
|
DB.usersCol = db.db(DBName).collection("users");
|
||||||
DB.tokensCol = db.db(DBName).collection("tokens");
|
DB.tokensCol = db.db(DBName).collection("tokens");
|
||||||
|
DB.invitationCol = db.db(DBName).collection("invitation");
|
||||||
|
|
||||||
DB.checkSessionOnDB = async (session_id, user_sid)=>{
|
DB.checkSessionOnDB = async (session_id, user_sid)=>{
|
||||||
const temp_id = new mongo.ObjectID(session_id);
|
const temp_id = new mongo.ObjectID(session_id);
|
||||||
@@ -48,6 +49,30 @@ const getDB = new Promise((resolve, reject) => {
|
|||||||
return usernamesCache[userid];
|
return usernamesCache[userid];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DB.newInvitation = (userid, name, email)=>{
|
||||||
|
const invitation = {
|
||||||
|
responsable: new mongo.ObjectID(userid),
|
||||||
|
email,
|
||||||
|
name,
|
||||||
|
ts: new Date()
|
||||||
|
}
|
||||||
|
return DB.invitationCol.insertOne(invitation).catch((err)=>{
|
||||||
|
if (err.name === 'MongoError' && err.code === 11000) {
|
||||||
|
// Duplicate invite email
|
||||||
|
return "This email already has been invited";
|
||||||
|
}
|
||||||
|
console.log(err);
|
||||||
|
return "System Error";
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
DB.getInvitation = (email)=>{
|
||||||
|
return DB.invitationCol.findOne({email}).catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return "System Error";
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
DB.newUser = (userInformation)=>{
|
DB.newUser = (userInformation)=>{
|
||||||
return DB.usersCol.insertOne(userInformation).catch((err)=>{
|
return DB.usersCol.insertOne(userInformation).catch((err)=>{
|
||||||
if (err.name === 'MongoError' && err.code === 11000) {
|
if (err.name === 'MongoError' && err.code === 11000) {
|
||||||
|
|||||||
34
package-lock.json
generated
34
package-lock.json
generated
@@ -16,7 +16,8 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"mongodb": "^3.6.3",
|
"mongodb": "^3.6.3",
|
||||||
"nodemailer": "^6.6.3"
|
"nodemailer": "^6.6.3",
|
||||||
|
"stripe": "^8.178.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@mapbox/node-pre-gyp": {
|
"node_modules/@mapbox/node-pre-gyp": {
|
||||||
@@ -38,6 +39,11 @@
|
|||||||
"node-pre-gyp": "bin/node-pre-gyp"
|
"node-pre-gyp": "bin/node-pre-gyp"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/node": {
|
||||||
|
"version": "16.10.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.10.2.tgz",
|
||||||
|
"integrity": "sha512-zCclL4/rx+W5SQTzFs9wyvvyCwoK9QtBpratqz2IYJ3O8Umrn0m3nsTv0wQBk9sRGpvUe9CwPDrQFB10f1FIjQ=="
|
||||||
|
},
|
||||||
"node_modules/abbrev": {
|
"node_modules/abbrev": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||||
@@ -1090,6 +1096,18 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/stripe": {
|
||||||
|
"version": "8.178.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/stripe/-/stripe-8.178.0.tgz",
|
||||||
|
"integrity": "sha512-Yk31NdIKf+MKTOdS2CTUIAHzUHOQwayoJFHBkrKGo7bJAlkPFzrIeOORH8SpduoXPZF8mq0JA7qNcFuFPBqabA==",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": ">=8.1.0",
|
||||||
|
"qs": "^6.6.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^8.1 || >=10.*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/tar": {
|
"node_modules/tar": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
|
||||||
@@ -1191,6 +1209,11 @@
|
|||||||
"tar": "^6.1.0"
|
"tar": "^6.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/node": {
|
||||||
|
"version": "16.10.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.10.2.tgz",
|
||||||
|
"integrity": "sha512-zCclL4/rx+W5SQTzFs9wyvvyCwoK9QtBpratqz2IYJ3O8Umrn0m3nsTv0wQBk9sRGpvUe9CwPDrQFB10f1FIjQ=="
|
||||||
|
},
|
||||||
"abbrev": {
|
"abbrev": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||||
@@ -1990,6 +2013,15 @@
|
|||||||
"ansi-regex": "^2.0.0"
|
"ansi-regex": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"stripe": {
|
||||||
|
"version": "8.178.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/stripe/-/stripe-8.178.0.tgz",
|
||||||
|
"integrity": "sha512-Yk31NdIKf+MKTOdS2CTUIAHzUHOQwayoJFHBkrKGo7bJAlkPFzrIeOORH8SpduoXPZF8mq0JA7qNcFuFPBqabA==",
|
||||||
|
"requires": {
|
||||||
|
"@types/node": ">=8.1.0",
|
||||||
|
"qs": "^6.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"tar": {
|
"tar": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"mongodb": "^3.6.3",
|
"mongodb": "^3.6.3",
|
||||||
"nodemailer": "^6.6.3"
|
"nodemailer": "^6.6.3",
|
||||||
|
"stripe": "^8.178.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ DB.getDB.then((DB)=>{
|
|||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
const profileid = getProfileId(req);
|
const profileid = getProfileId(req);
|
||||||
let posts = await DB.getFeed(profileid);
|
let posts = await DB.getFeed(profileid);
|
||||||
|
//Add non-organic posts
|
||||||
|
|
||||||
return res.json(posts)
|
return res.json(posts)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ DB.getDB.then((DB)=>{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/new", async (req, res) => {
|
router.get("/new", async (req, res) => { //Deprecated please use route post("/")
|
||||||
let profile = {
|
let profile = {
|
||||||
userid: getUserId(req),
|
userid: getUserId(req),
|
||||||
... req.query.content
|
... req.query.content
|
||||||
@@ -37,6 +37,47 @@ DB.getDB.then((DB)=>{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post("/", async (req, res) => {
|
||||||
|
let profile = {
|
||||||
|
userid: getUserId(req),
|
||||||
|
... req.body.content
|
||||||
|
};
|
||||||
|
let profileObj = new Profile(profile);
|
||||||
|
let r = await DB.newProfile(profileObj);
|
||||||
|
return res.json({
|
||||||
|
status: "ok",
|
||||||
|
... profileObj.toObj()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post("/invite", async (req, res) => {
|
||||||
|
const userid = getUserId(req);
|
||||||
|
const name = req.body.name;
|
||||||
|
const email = req.body.email;
|
||||||
|
//validate email?
|
||||||
|
if(!name || !email) return res.json({status: "incomplete request"});
|
||||||
|
let r = await DB.newInvitation(userid, name, email);
|
||||||
|
if(!r.toLowerCase){
|
||||||
|
//send email invitation
|
||||||
|
return res.json({
|
||||||
|
status: "ok"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return res.json({
|
||||||
|
status: r
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/invite/:email", async (req, res) => {
|
||||||
|
const userid = getUserId(req);
|
||||||
|
const email = req.body.email;
|
||||||
|
//validate email?
|
||||||
|
if(email) return res.json({status: "provide valid email"});
|
||||||
|
let r = await DB.getInvitation(email);
|
||||||
|
if(!r) return res.json({status: "no invitation found with that email"});
|
||||||
|
return res.json({status: "ok", ... r});
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/groups", async (req, res) => {
|
router.get("/groups", async (req, res) => {
|
||||||
let groups = await DB.getGroups();
|
let groups = await DB.getGroups();
|
||||||
return res.json({
|
return res.json({
|
||||||
|
|||||||
Reference in New Issue
Block a user