10000 Added Creating new user feature · mythLabs/api-server-node-express@cc3fc5c · GitHub
[go: up one dir, main page]

Skip to content

Commit cc3fc5c

Browse files
committed
Added Creating new user feature
1 parent c256bee commit cc3fc5c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

controllers/authentication.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
const User = require('../models/user');
2+
13
exports.signup = function(req,res,next) {
2-
res.send({sucess: 'true'});
4+
const email = req.body.email;
5+
const password= req.body.password;
6+
7+
//See if user with email already exists
8+
User.findOne({email: email},function(err,existingUser){
9+
if (err) { return next(err)}
10+
11+
if (existingUser) {
12+
return res.status(422).send({error: 'Email is in use'});
13+
}
14+
15+
const user = new User({
16+
email: email,
17+
password: password
18+
});
19+
20+
user.save(function(err){
21+
if (err) { return next(err);}
22+
23+
res.json(user);
24+
});
25+
26+
})
327
}

models/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ const ModelClass = mongoose.model('user',userSchema);
1212
//export
1313

1414

15-
module.export = ModelClass;
15+
module.exports = ModelClass;

0 commit comments

Comments
 (0)
0