- 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);
推薦閱讀
- Learning Python Web Penetration Testing
- Mastering AWS Lambda
- JavaScript語言精髓與編程實踐(第3版)
- 面向STEM的Scratch創新課程
- Learning Firefox OS Application Development
- Serverless架構
- Scientific Computing with Scala
- C語言程序設計同步訓練與上機指導(第三版)
- 細說Python編程:從入門到科學計算
- Node學習指南(第2版)
- Distributed Computing in Java 9
- MongoDB Cookbook(Second Edition)
- 零基礎學編程系列(全5冊)
- Roslyn Cookbook
- Python AI游戲編程入門:基于Pygame和PyTorch