This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongoose = require(mongoose), | |
| User = require(./user-model); | |
| var connStr = mongodb://localhost:27017/mongoose-bcrypt-test; | |
| mongoose.connect(connStr, function(err) { | |
| if (err) throw err; | |
| console.log(Successfully connected to MongoDB); | |
| }); | |
| // create a user a new user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongoose = require(‘mongoose’), | |
| Schema = mongoose.Schema, | |
| bcrypt = require(‘bcrypt’), | |
| SALT_WORK_FACTOR = 10; | |
| var UserSchema = new Schema({ | |
| username: { type: String, required: true, index: { unique: true } }, | |
| password: { type: String, required: true } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UserSchema.methods.comparePassword = function(candidatePassword, cb) { | |
| bcrypt.compare(candidatePassword, this.password, function(err, isMatch) { | |
| if (err) return cb(err); | |
| cb(null, isMatch); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UserSchema.pre(‘save’, { var user = this; | |
| // only hash the password if it has been modified (or is new) | |
| if (!user.isModified('password')) return next(); | |
| // generate a salt | |
| bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) { | |
| if (err) return next(err); | |
| // hash the password along with our new salt | |
| bcrypt.hash(user.password, salt, function(err, hash) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongoose = require('mongoose'), | |
| Schema = mongoose.Schema, | |
| bcrypt = require(bcrypt), | |
| SALT_WORK_FACTOR = 10; | |
| var UserSchema = new Schema({ | |
| username: { type: String, required: true, index: { unique: true } }, | |
| password: { type: String, required: true } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { "name" : "MongoDB Notebook", "description" : "My MongoDB Notes", "created" : ISODate("2012-09-25T12:22:23.590Z"), "author" : "test_user", "tags" : [ "mongodb", "nosql" ], "notes" : [ { "title" : "Say hello to MongoDB", "text" : "Say hello to MongoDB", "created" : ISODate("2012-09-25T12:22:23.593Z"), "tags" : [ "mongodb", "getting-started" ] }, { "title" : "How to setup ReplicaSet in MongoDB", "text" : "How to setup ReplicaSet in MongoDB", "created" : ISODate("2012-09-25T12:22:23.593Z"), "tags" : [ "mongodb", "replication" ] } ] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rhc app cartridge add -a notebook -c mongodb-2.0 rhc app cartridge add -a notebook -c rockmongo-1.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git add . git commit -a -m "maven multi module project structure created" git push |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Document(collection = “notebooks”) public class Notebook { | |
| @Id private String id; private String name; private String description; @DateTimeFormat(style = "M-") private Date created = new Date(); private String author; private String[] tags; private Note[] notes; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongoose = require('mongoose'), | |
| Schema = mongoose.Schema, | |
| bcrypt = require('bcrypt'), | |
| SALT_WORK_FACTOR = 10; | |
| var UserSchema = new Schema({ | |
| username: { type: String, required: true, index: { unique: true } }, | |
| password: { type: String, required: true } | |
| }); |