-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.js
35 lines (30 loc) · 868 Bytes
/
users.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
31
32
33
34
35
//Requiring packages we're using
var mysql = require("mysql");
var bcrypt = require("bcryptjs");
// define the schema for our user model
// !!! is this correctly pointing to our DB?
var userSchema = MySQL.schema({
local: {
fullname: String,
username: String,
email: String,
password: String
// },
// facebook: {
// id: String,
// token: String,
// name: String,
// email: String
// }
});
// methods ======================
// generating a hash
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.local.password);
};
// create the model for users and expose it to our app
module.exports = MySQL.model("User", userSchema);