Merge branch 'master' into timestamp
Conflicts: views/partials/challenges.jade
This commit is contained in:
@ -1,17 +1,18 @@
|
||||
var mongoose = require('mongoose');
|
||||
var bcrypt = require('bcrypt-nodejs');
|
||||
var crypto = require('crypto');
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var userSchema = new mongoose.Schema({
|
||||
email: { type: String, unique: true, lowercase: true },
|
||||
// password: String,
|
||||
//email: { type: String, unique: true, lowercase: true, match: /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/ },
|
||||
email: String,
|
||||
password: String,
|
||||
|
||||
linkedin: String,
|
||||
facebook: String,
|
||||
github: String,
|
||||
twitter: String,
|
||||
google: String,
|
||||
github: String,
|
||||
instagram: String,
|
||||
linkedin: String,
|
||||
tokens: Array,
|
||||
challengesCompleted: { type: Array, default: [] },
|
||||
challengesHash: {
|
||||
@ -221,8 +222,8 @@ var userSchema = new mongoose.Schema({
|
||||
gender: { type: String, default: '' },
|
||||
location: { type: String, default: '' },
|
||||
website: { type: String, default: '' },
|
||||
picture: { type: String, default: '' },
|
||||
username: { type: String, default: '' }
|
||||
picture: { type: String, default: '' }
|
||||
//username: { type: String, default: '', unique: true, match: /^[a-zA-Z0-9_]+$/ }
|
||||
},
|
||||
|
||||
resetPasswordToken: String,
|
||||
@ -230,20 +231,19 @@ var userSchema = new mongoose.Schema({
|
||||
});
|
||||
|
||||
/**
|
||||
* Hash the password for security.
|
||||
* "Pre" is a Mongoose middleware that executes before each user.save() call.
|
||||
* Password hashing Mongoose middleware.
|
||||
*/
|
||||
|
||||
userSchema.pre('save', function(next) {
|
||||
var user = this;
|
||||
|
||||
if (!user.isModified('password')) return next();
|
||||
if (!user.isModified('password')) { return next(); }
|
||||
|
||||
bcrypt.genSalt(5, function(err, salt) {
|
||||
if (err) return next(err);
|
||||
if (err) { return next(err); }
|
||||
|
||||
bcrypt.hash(user.password, salt, null, function(err, hash) {
|
||||
if (err) return next(err);
|
||||
if (err) { return next(err); }
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
@ -251,24 +251,22 @@ userSchema.pre('save', function(next) {
|
||||
});
|
||||
|
||||
/**
|
||||
* Validate user's password.
|
||||
* Used by Passport-Local Strategy for password validation.
|
||||
* Helper method for validationg user's password.
|
||||
*/
|
||||
|
||||
userSchema.methods.comparePassword = function(candidatePassword, cb) {
|
||||
bcrypt.compare(candidatePassword, this.password, function(err, isMatch) {
|
||||
if (err) return cb(err);
|
||||
if (err) { return cb(err); }
|
||||
cb(null, isMatch);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get URL to a user's gravatar.
|
||||
* Used in Navbar and Account Management page.
|
||||
* Helper method for getting user's gravatar.
|
||||
*/
|
||||
|
||||
userSchema.methods.gravatar = function(size) {
|
||||
if (!size) size = 200;
|
||||
if (!size) { size = 200; }
|
||||
|
||||
if (!this.email) {
|
||||
return 'https://gravatar.com/avatar/?s=' + size + '&d=retro';
|
||||
@ -278,4 +276,4 @@ userSchema.methods.gravatar = function(size) {
|
||||
return 'https://gravatar.com/avatar/' + md5 + '?s=' + size + '&d=retro';
|
||||
};
|
||||
|
||||
module.exports = mongoose.model('User', userSchema);
|
||||
module.exports = mongoose.model('User', userSchema);
|
||||
|
Reference in New Issue
Block a user