return error when register user with used email:
This commit is contained in:
13
index.js
13
index.js
@@ -76,21 +76,21 @@ DB.getDB.then((DB)=>{
|
|||||||
if(!username || !password || !email) return res.json({status: "fail"})
|
if(!username || !password || !email) return res.json({status: "fail"})
|
||||||
//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 success = await DB.newUser({
|
const response = await DB.newUser({
|
||||||
username: username,
|
username: username.toLowerCase(),
|
||||||
email: email,
|
email: email.toLowerCase(),
|
||||||
password: hashedPassword
|
password: hashedPassword
|
||||||
});
|
});
|
||||||
if(success){
|
if(!response.toLowerCase){
|
||||||
let user = {
|
let user = {
|
||||||
userid: success.insertedId,
|
userid: response.insertedId,
|
||||||
profile: profile,
|
profile: profile,
|
||||||
}
|
}
|
||||||
const userObj = new Profile(user);
|
const userObj = new Profile(user);
|
||||||
await DB.newProfile(userObj);
|
await DB.newProfile(userObj);
|
||||||
return await login(req, res);
|
return await login(req, res);
|
||||||
}
|
}
|
||||||
res.redirect('/signup');
|
return res.json({status: response})
|
||||||
}
|
}
|
||||||
app.route('/signup').get(async (req, res) => {
|
app.route('/signup').get(async (req, res) => {
|
||||||
return await signup(req, res);
|
return await signup(req, res);
|
||||||
@@ -125,7 +125,6 @@ DB.getDB.then((DB)=>{
|
|||||||
res.cookie('session_id', doc.insertedId, cookiesOptions);
|
res.cookie('session_id', doc.insertedId, cookiesOptions);
|
||||||
//Chooses the most recent update profile
|
//Chooses the most recent update profile
|
||||||
const latestProfile = await DB.latestProfile(user._id);
|
const latestProfile = await DB.latestProfile(user._id);
|
||||||
console.log("latestProfile", latestProfile)
|
|
||||||
res.cookie('profile_id', latestProfile._id, cookiesOptions);
|
res.cookie('profile_id', latestProfile._id, cookiesOptions);
|
||||||
return res.json({
|
return res.json({
|
||||||
status: "ok",
|
status: "ok",
|
||||||
|
|||||||
@@ -50,8 +50,12 @@ const getDB = new Promise((resolve, reject) => {
|
|||||||
|
|
||||||
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) {
|
||||||
|
// Duplicate username
|
||||||
|
return "User already exists";
|
||||||
|
}
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return false;
|
return "System Error";
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user