- 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
- C語言程序設計案例教程
- FuelPHP Application Development Blueprints
- 玩轉Scratch少兒趣味編程
- 微服務與事件驅動架構
- Interactive Data Visualization with Python
- 動手玩轉Scratch3.0編程:人工智能科創教育指南
- Learning ELK Stack
- Internet of Things with ESP8266
- C++反匯編與逆向分析技術揭秘(第2版)
- Machine Learning for OpenCV
- 超好玩的Scratch 3.5少兒編程
- Clojure編程樂趣
- C# 7 and .NET Core 2.0 Blueprints
- MATLAB計算機視覺實戰