Commit
This commit is contained in:
commit
d1c8cae2c1
1417 changed files with 326736 additions and 0 deletions
63
models/Users.js
Normal file
63
models/Users.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
const mongoose = require('mongoose')
|
||||
const {checkpass} = require('./../function/Users/pass')
|
||||
// const pass = require('./../function/Users/pass')
|
||||
|
||||
const UserSchema = new mongoose.Schema({
|
||||
email:{
|
||||
type: String,
|
||||
require: [true, 'Veuillez fournir un email'],
|
||||
match: [/^\S+@\S+\.\S+$/, 'Veuillez fournir un email valide'],
|
||||
unique: true,
|
||||
trim: true,
|
||||
lowercase: true
|
||||
},
|
||||
password:{
|
||||
type: String,
|
||||
require: [true, 'Veuillez fournir un mot de passe'],
|
||||
minlength:[6, 'Votre mot de passe doit avoir plus de 6 Caractère'],
|
||||
select: false
|
||||
},
|
||||
role:{
|
||||
type: String,
|
||||
enum:[ 'coca', 'pepsi' , 'breizhcola'],
|
||||
default: 'breizhcola'
|
||||
},
|
||||
age:{
|
||||
type: Number
|
||||
} ,
|
||||
sessions_history :[
|
||||
{
|
||||
type: String
|
||||
}
|
||||
],
|
||||
preferences:{
|
||||
darkmode :{
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
}
|
||||
},{
|
||||
timestamps: true
|
||||
})
|
||||
|
||||
UserSchema.pre('save', async function(next){
|
||||
if (!this.isModified('password')){
|
||||
return next()
|
||||
}
|
||||
try{
|
||||
//const salt = await bcrypt.genSalt(10)
|
||||
//this.password = await bcrypt.hash(this.password , salt)
|
||||
this.password = 'HOL'+this.password+'OLI'
|
||||
next()
|
||||
}
|
||||
catch(err){
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
UserSchema.methods.matchPass = checkpass
|
||||
// user.matchPass('helo')
|
||||
// UserSchema.methods = {...UserSchema.methods, ...pass}
|
||||
// user.checkpass('helo')
|
||||
|
||||
module.exports = mongoose.model('User', UserSchema)
|
||||
Loading…
Add table
Add a link
Reference in a new issue