Login Formúlar + Digest + Google Login
This commit is contained in:
1
db/index.js
Normal file
1
db/index.js
Normal file
@ -0,0 +1 @@
|
||||
exports.users = require('./users');
|
64
db/users.js
Normal file
64
db/users.js
Normal file
@ -0,0 +1,64 @@
|
||||
exports.createUser = function(userobj, cb) {
|
||||
process.nextTick(function (){
|
||||
var lastId = records[records.length - 1].id
|
||||
userobj.id = lastId+1;
|
||||
records.push(userobj)
|
||||
return cb(null, userobj)
|
||||
})
|
||||
}
|
||||
|
||||
exports.findByUsernameGoogle = function(userobj, cb) {
|
||||
process.nextTick(function (){
|
||||
console.log(userobj)
|
||||
for (var i = 0, len = records.length; i < len; i++) {
|
||||
var record = records[i];
|
||||
if (record.googleId === userobj.googleId) {
|
||||
return cb(null, record);
|
||||
}
|
||||
}
|
||||
return cb(null, null);
|
||||
})
|
||||
}
|
||||
|
||||
exports.findByToken = function(userobj, cb) {
|
||||
process.nextTick(function (){
|
||||
console.log(userobj)
|
||||
for (var i = 0, len = records.length; i < len; i++) {
|
||||
var record = records[i];
|
||||
if (record.token === userobj.token) {
|
||||
return cb(null, record);
|
||||
}
|
||||
}
|
||||
return cb(null, null);
|
||||
})
|
||||
}
|
||||
|
||||
var records = [
|
||||
{ id: 1, username: 'jack', password: 'secret', displayName: 'Jack', emails: [ { value: 'jack@example.com' } ], googleId: 1 }
|
||||
, { id: 2, username: 'jill', password: 'birthday', displayName: 'Jill', emails: [ { value: 'jill@example.com' } ], googleId: 2 }
|
||||
];
|
||||
|
||||
exports.findById = function(id, cb) {
|
||||
process.nextTick(function() {
|
||||
var idx = id - 1;
|
||||
if (records[idx]) {
|
||||
cb(null, records[idx]);
|
||||
} else {
|
||||
cb(new Error('User ' + id + ' does not exist'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.findByUsername = function(username, cb) {
|
||||
process.nextTick(function() {
|
||||
for (var i = 0, len = records.length; i < len; i++) {
|
||||
var record = records[i];
|
||||
console.log("Username")
|
||||
console.log(username)
|
||||
if (record.username === username) {
|
||||
return cb(null, record);
|
||||
}
|
||||
}
|
||||
return cb(null, null);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user