-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
39 lines (30 loc) · 843 Bytes
/
auth.js
File metadata and controls
39 lines (30 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module.exports = function(app) {
// called by server.js to create/login user
var auth = {
// go through db to find/upsert user
upsertUser: function(req, res) {
var userObject = new Object();
userObject.username = req.body.username;
saveUser(userObject);
// response with success/fail of user authentication
// res.send('upsertUser');
}
};
function saveUser(userObject) {
var user = new app.models.User ({
username: userObject.username
});
app.models.User.findOne({ username: user.username }, function(err, doc) {
if (err)
return console.log(err);
if (doc)
return console.log('exists');
user.save(function(err, doc) {
if (err)
console.log(err);
console.log('saved');
});
});
}
return auth;
};