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"})
|
||||
//const hashedPassword = await bcrypt.hash(password, 10);
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
const success = await DB.newUser({
|
||||
username: username,
|
||||
email: email,
|
||||
const response = await DB.newUser({
|
||||
username: username.toLowerCase(),
|
||||
email: email.toLowerCase(),
|
||||
password: hashedPassword
|
||||
});
|
||||
if(success){
|
||||
if(!response.toLowerCase){
|
||||
let user = {
|
||||
userid: success.insertedId,
|
||||
userid: response.insertedId,
|
||||
profile: profile,
|
||||
}
|
||||
const userObj = new Profile(user);
|
||||
await DB.newProfile(userObj);
|
||||
return await login(req, res);
|
||||
}
|
||||
res.redirect('/signup');
|
||||
return res.json({status: response})
|
||||
}
|
||||
app.route('/signup').get(async (req, res) => {
|
||||
return await signup(req, res);
|
||||
@@ -125,7 +125,6 @@ DB.getDB.then((DB)=>{
|
||||
res.cookie('session_id', doc.insertedId, cookiesOptions);
|
||||
//Chooses the most recent update profile
|
||||
const latestProfile = await DB.latestProfile(user._id);
|
||||
console.log("latestProfile", latestProfile)
|
||||
res.cookie('profile_id', latestProfile._id, cookiesOptions);
|
||||
return res.json({
|
||||
status: "ok",
|
||||
|
||||
@@ -50,8 +50,12 @@ const getDB = new Promise((resolve, reject) => {
|
||||
|
||||
DB.newUser = (userInformation)=>{
|
||||
return DB.usersCol.insertOne(userInformation).catch((err)=>{
|
||||
if (err.name === 'MongoError' && err.code === 11000) {
|
||||
// Duplicate username
|
||||
return "User already exists";
|
||||
}
|
||||
console.log(err);
|
||||
return false;
|
||||
return "System Error";
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user