|
|
|
@ -136,141 +136,6 @@ var utils = require('./../public/src/utils.js'),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.loginViaLocal = function(username, password, next) {
|
|
|
|
|
|
|
|
|
|
if (!username || !password) {
|
|
|
|
|
return next({
|
|
|
|
|
status: 'error',
|
|
|
|
|
message: 'invalid-user'
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
RDB.get('username:' + username + ':uid', function(err, uid) {
|
|
|
|
|
RDB.handle(err);
|
|
|
|
|
|
|
|
|
|
if (uid == null) {
|
|
|
|
|
return next({
|
|
|
|
|
status: 'error',
|
|
|
|
|
message: 'invalid-user'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.getUserField(uid, 'password', function(user_password) {
|
|
|
|
|
bcrypt.compare(password, user_password, function(err, res) {
|
|
|
|
|
if (res === true) {
|
|
|
|
|
next({
|
|
|
|
|
status: "ok",
|
|
|
|
|
user: {
|
|
|
|
|
uid: uid
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
next({
|
|
|
|
|
status: 'error',
|
|
|
|
|
message: 'invalid-password'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.loginViaTwitter = function(twid, handle, callback) {
|
|
|
|
|
User.get_uid_by_twitter_id(twid, function(uid) {
|
|
|
|
|
if (uid !== null) {
|
|
|
|
|
// Existing User
|
|
|
|
|
callback(null, {
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// New User
|
|
|
|
|
User.create(handle, null, null, function(err, uid) {
|
|
|
|
|
if (err !== null) {
|
|
|
|
|
callback(err);
|
|
|
|
|
} else {
|
|
|
|
|
// Save twitter-specific information to the user
|
|
|
|
|
User.setUserField(uid, 'twid', twid);
|
|
|
|
|
RDB.hset('twid:uid', twid, uid);
|
|
|
|
|
callback(null, {
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.loginViaGoogle = function(gplusid, handle, email, callback) {
|
|
|
|
|
User.get_uid_by_google_id(gplusid, function(uid) {
|
|
|
|
|
if (uid !== null) {
|
|
|
|
|
// Existing User
|
|
|
|
|
callback(null, {
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// New User
|
|
|
|
|
var success = function(uid) {
|
|
|
|
|
// Save google-specific information to the user
|
|
|
|
|
User.setUserField(uid, 'gplusid', gplusid);
|
|
|
|
|
RDB.hset('gplusid:uid', gplusid, uid);
|
|
|
|
|
callback(null, {
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.get_uid_by_email(email, function(uid) {
|
|
|
|
|
if (!uid) {
|
|
|
|
|
User.create(handle, null, email, function(err, uid) {
|
|
|
|
|
if (err !== null) {
|
|
|
|
|
callback(err);
|
|
|
|
|
} else success(uid);
|
|
|
|
|
});
|
|
|
|
|
} else success(uid); // Existing account -- merge
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.loginViaFacebook = function(fbid, name, email, callback) {
|
|
|
|
|
User.get_uid_by_fbid(fbid, function(uid) {
|
|
|
|
|
if (uid !== null) {
|
|
|
|
|
// Existing User
|
|
|
|
|
callback(null, {
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// New User
|
|
|
|
|
var success = function(uid) {
|
|
|
|
|
// Save facebook-specific information to the user
|
|
|
|
|
User.setUserField(uid, 'fbid', fbid);
|
|
|
|
|
RDB.hset('fbid:uid', fbid, uid);
|
|
|
|
|
callback(null, {
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.get_uid_by_email(email, function(uid) {
|
|
|
|
|
if (!uid) {
|
|
|
|
|
User.create(name, null, email, function(err, uid) {
|
|
|
|
|
if (err !== null) {
|
|
|
|
|
callback(err);
|
|
|
|
|
} else success(uid);
|
|
|
|
|
});
|
|
|
|
|
} else success(uid); // Existing account -- merge
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.logout = function(sessionID, callback) {
|
|
|
|
|
User.get_uid_by_session(sessionID, function(uid) {
|
|
|
|
|
if (uid) {
|
|
|
|
|
RDB.del('sess:' + sessionID + ':uid');
|
|
|
|
|
RDB.del('uid:' + uid + ':session');
|
|
|
|
|
callback(true);
|
|
|
|
|
} else callback(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.create = function(username, password, email, callback) {
|
|
|
|
|
|
|
|
|
|