- Node.js 6.x Blueprints
- Fernando Monteiro
- 104字
- 2021-07-14 10:35:01
Creating a models folder and adding a user schema
Create a models folder inside server/
and add the following code:
// Import Mongoose and password Encrypt var mongoose = require('mongoose'); var bcrypt = require('bcrypt-nodejs'); // define the schema for User model var userSchema = mongoose.Schema({ // Using local for Local Strategy Passport local: { name: String, email: String, password: String, } }); // Encrypt Password userSchema.methods.generateHash = function(password) { return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null); }; // Verify if password is valid userSchema.methods.validPassword = function(password) { return bcrypt.compareSync(password, this.local.password); }; // create the model for users and expose it to our app module.exports = mongoose.model('User', userSchema);
推薦閱讀
- Extending Jenkins
- Python王者歸來
- Windows Presentation Foundation Development Cookbook
- Learning Neo4j 3.x(Second Edition)
- TypeScript實(shí)戰(zhàn)指南
- Python貝葉斯分析(第2版)
- Kinect for Windows SDK Programming Guide
- ADI DSP應(yīng)用技術(shù)集錦
- 基于Struts、Hibernate、Spring架構(gòu)的Web應(yīng)用開發(fā)
- 響應(yīng)式Web設(shè)計(jì):HTML5和CSS3實(shí)戰(zhàn)(第2版)
- Swift語言實(shí)戰(zhàn)晉級(jí)
- Deep Learning with R Cookbook
- 深入實(shí)踐DDD:以DSL驅(qū)動(dòng)復(fù)雜軟件開發(fā)
- Mastering OpenStack
- C# 7.0本質(zhì)論