summaryrefslogtreecommitdiff
path: root/lib/user.js
diff options
context:
space:
mode:
authorWu Cheng-Han2016-01-12 08:01:42 -0600
committerWu Cheng-Han2016-01-12 08:01:42 -0600
commit2ecec3b59aabe2fd6156338cd4cbab7672d4f9b1 (patch)
treea27846db2e2e8d0ef1480893a8ad2b69dac36ad0 /lib/user.js
parent1672df3dceebe885ded02530799a78d5a07be1d7 (diff)
Support show last change user with profile and support YAML config inside the note with robots, lang, dir, breaks options
Diffstat (limited to '')
-rw-r--r--lib/user.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/user.js b/lib/user.js
index f89f7def..b3fae39c 100644
--- a/lib/user.js
+++ b/lib/user.js
@@ -1,6 +1,7 @@
//user
//external modules
var mongoose = require('mongoose');
+var md5 = require("blueimp-md5").md5;
//core
var config = require("../config.js");
@@ -20,9 +21,30 @@ var user = {
findUser: findUser,
newUser: newUser,
findOrNewUser: findOrNewUser,
- getUserCount: getUserCount
+ getUserCount: getUserCount,
+ parsePhotoByProfile: parsePhotoByProfile
};
+function parsePhotoByProfile(profile) {
+ var photo = null;
+ switch (profile.provider) {
+ case "facebook":
+ photo = 'https://graph.facebook.com/' + profile.id + '/picture';
+ break;
+ case "twitter":
+ photo = profile.photos[0].value;
+ break;
+ case "github":
+ photo = 'https://avatars.githubusercontent.com/u/' + profile.id + '?s=48';
+ break;
+ case "dropbox":
+ //no image api provided, use gravatar
+ photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value);
+ break;
+ }
+ return photo;
+}
+
function getUserCount(callback) {
model.count(function(err, count){
if(err) callback(err, null);
@@ -31,9 +53,13 @@ function getUserCount(callback) {
}
function findUser(id, callback) {
- model.findOne({
- id: id
- }, function (err, user) {
+ var rule = {};
+ var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$");
+ if (checkForHexRegExp.test(id))
+ rule._id = id;
+ else
+ rule.id = id;
+ model.findOne(rule, function (err, user) {
if (err) {
logger.error('find user failed: ' + err);
callback(err, null);