Invitation only for signup
This commit is contained in:
25
mongoDB.js
25
mongoDB.js
@@ -17,6 +17,7 @@ const getDB = new Promise((resolve, reject) => {
|
||||
console.log("Connected to DB!");
|
||||
DB.usersCol = db.db(DBName).collection("users");
|
||||
DB.tokensCol = db.db(DBName).collection("tokens");
|
||||
DB.invitationCol = db.db(DBName).collection("invitation");
|
||||
|
||||
DB.checkSessionOnDB = async (session_id, user_sid)=>{
|
||||
const temp_id = new mongo.ObjectID(session_id);
|
||||
@@ -48,6 +49,30 @@ const getDB = new Promise((resolve, reject) => {
|
||||
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)=>{
|
||||
return DB.usersCol.insertOne(userInformation).catch((err)=>{
|
||||
if (err.name === 'MongoError' && err.code === 11000) {
|
||||
|
||||
Reference in New Issue
Block a user