-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuser.js
30 lines (25 loc) · 1013 Bytes
/
user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');
// define the schema for our user model
var userSchema = mongoose.Schema({
local : {
firstname : {type: String, required: true},
accounttype : {type: String, required: true},
lastname : {type: String, required: true},
email : {type: String, required: true},
idNumber : {type: String, required: true},
username : {type: String, required: true},
password : {type: String, required: true},
radio : String
},
});
// generating a hash
userSchema.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};
// check 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);