Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

[WIP] hash password #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
13 changes: 12 additions & 1 deletion app/db/models/blog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
const mongoose = require('mongoose')
const blogSchema = require('./schemas/blog')

module.exports = mongoose.model('Blog', blogSchema)
blogSchema.pre('save', function (next) {
if (!this.isModified('password')) return next()
this.password = Bycrypt.hashSync(this.password, 10)
next()
})

blogSchema.methods.comparePassword = function (plainText, cb) {
return cb(null, Bycrypt.compareSync(plainText, this.password))
}

module.exports = mongoose.model('Blog', blogSchema)