- 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);
推薦閱讀
- Building a Game with Unity and Blender
- Software Testing using Visual Studio 2012
- 編寫高質量代碼:改善C程序代碼的125個建議
- jQuery開發基礎教程
- R Deep Learning Cookbook
- Building Serverless Applications with Python
- Getting Started with React Native
- Canvas Cookbook
- Node.js 12實戰
- SQL Server 2008 R2數據庫技術及應用(第3版)
- 基于GPU加速的計算機視覺編程:使用OpenCV和CUDA實時處理復雜圖像數據
- Java EE輕量級解決方案:S2SH
- React.js實戰
- Processing開發實戰
- Microsoft Windows Identity Foundation Cookbook