Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let userSchema = new mongoose.Schema({
- username: {type: String, required: true},
- email: {type: String, required: true, index: {unique: true}},
- joinDate: {type: Date, default: Date.now},
- clips: [clipSchema],
- hash: {type: String},
- salt: {type: String}
- })
- userSchema.methods.setPassword = (password) => {
- this.salt = crypto.randomBytes(32).toString('hex')
- this.hash = crypto.pbkdf2Sync(password, this.salt, 100000, 512, 'sha512').toString('hex')
- }
- let user = new User()
- user.username = req.body.username
- user.email = req.body.email
- user.setPassword(req.body.password)
- user.save((err) => {
- if (err) {
- sendJsonResponse(res, 404, err)
- } else {
- let token = user.generateJwt()
- sendJsonResponse(res, 200, { 'token': token })
- }
- })
- {
- "_id" : ObjectId("576338b363bb7df7024c044b"),
- "email" : "boss@potato.com",
- "username" : "Bob",
- "clips" : [ ],
- "joinDate" : ISODate("2016-06-16T23:39:31.825Z"),
- "__v" : 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement