Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mongoose, { Schema } from 'mongoose';
- import bcrypt from 'bcrypt';
- const UserSchema = new mongoose.Schema({
- name: {type:String, required:true},
- email: {type: String, required:true},
- username: { type: String, required: true, unique: true },
- password: { type: String, required: true },
- profileimage: {type:Buffer, contentType: String },
- admin: {type:Boolean, default:false},
- Date_Created:{type: Date },
- is_active: { type: Boolean, default: false }
- });
- UserSchema.methods.generateHash = function(password) {
- return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
- };
- // checking if password is valid
- UserSchema.methods.validPassword = function(password) {
- return bcrypt.compareSync(password, this.password);
- };
- module.exports = mongoose.model('User', UserSchema);
Add Comment
Please, Sign In to add comment