Check for invitations which were used already
This commit is contained in:
4
index.js
4
index.js
@@ -116,6 +116,8 @@ DB.getDB.then((DB) => {
|
||||
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"});
|
||||
let isUserAlreadyRegistered = await DB.getUser(email);
|
||||
if(isUserAlreadyRegistered && isUserAlreadyRegistered._id) return res.json({status: "This user is already registered"});
|
||||
return res.json({status: "ok", ... r});
|
||||
});
|
||||
|
||||
@@ -131,6 +133,8 @@ DB.getDB.then((DB) => {
|
||||
// Check if the new user has an invitation.
|
||||
// TODO: Alert admin of signup attempts via email.
|
||||
if (!await DB.getInvitation(email)) return res.json({ status: "Not invitation found!" });
|
||||
let isUserAlreadyRegistered = await DB.getUser(email);
|
||||
if(isUserAlreadyRegistered && isUserAlreadyRegistered._id) return res.json({status: "This user is already registered"});
|
||||
// Hash password to be stored on the DB.
|
||||
// TODO: I think this is missing a Salt factor to improve security
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
|
||||
@@ -84,6 +84,8 @@ DB.getDB.then((DB)=>{
|
||||
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"});
|
||||
let isUserAlreadyRegistered = await DB.getUser(email);
|
||||
if(isUserAlreadyRegistered && isUserAlreadyRegistered._id) return res.json({status: "This user is already registered"});
|
||||
return res.json({status: "ok", ... r});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user