consolidate all repos to one for archive
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
var mongoose = require('mongoose');
|
||||
var Schema = mongoose.Schema;
|
||||
|
||||
var mdataSchema = new Schema({
|
||||
'user_id' : {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user'
|
||||
},
|
||||
'title' : String,
|
||||
'question' : String,
|
||||
'timestamp' : Date,
|
||||
'tags' : Array,
|
||||
'answering_id' : {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'mdata'
|
||||
},
|
||||
'answer' : {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'mdata'
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('mdata', mdataSchema);
|
@@ -0,0 +1,15 @@
|
||||
var mongoose = require('mongoose');
|
||||
var Schema = mongoose.Schema;
|
||||
|
||||
var photoSchema = new Schema({
|
||||
'name' : String,
|
||||
'path' : String,
|
||||
'postedBy' : {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user'
|
||||
},
|
||||
'views' : Number,
|
||||
'likes' : Number
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('photo', photoSchema);
|
@@ -0,0 +1,8 @@
|
||||
var mongoose = require('mongoose');
|
||||
var Schema = mongoose.Schema;
|
||||
|
||||
var tagsSchema = new Schema({
|
||||
'name' : String
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('tags', tagsSchema);
|
@@ -0,0 +1,44 @@
|
||||
var mongoose = require('mongoose');
|
||||
var bcrypt = require('bcrypt');
|
||||
var Schema = mongoose.Schema;
|
||||
|
||||
var userSchema = new Schema({
|
||||
'username' : String,
|
||||
'password' : String,
|
||||
'email' : String
|
||||
});
|
||||
|
||||
userSchema.pre('save', function(next){
|
||||
var user = this;
|
||||
bcrypt.hash(user.password, 10, function(err, hash){
|
||||
if(err){
|
||||
return next(err);
|
||||
}
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
userSchema.statics.authenticate = function(username, password, callback){
|
||||
User.findOne({username: username})
|
||||
.exec(function(err, user){
|
||||
if(err){
|
||||
return callback(err);
|
||||
} else if(!user) {
|
||||
var err = new Error("User not found.");
|
||||
err.status = 401;
|
||||
return callback(err);
|
||||
}
|
||||
bcrypt.compare(password, user.password, function(err, result){
|
||||
if(result === true){
|
||||
return callback(null, user);
|
||||
} else{
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var User = mongoose.model('user', userSchema);
|
||||
module.exports = User;
|
Reference in New Issue
Block a user