This repository has been archived by the owner on Mar 21, 2018. It is now read-only.
forked from realcodywburns/gimme-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
76 lines (64 loc) · 1.91 KB
/
db.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var mongoose = require( 'mongoose' );
var Schema = mongoose.Schema;
var bcrypt = require('bcryptjs');
SALT_WORK_FACTOR = 10;
//store the dap data
var devDapp = new Schema(
{
//basic info
"number": {type: Number, index: {unique: true}},
"owner":String,
"dappName": String,
"devTeam": String,
"shortDes": String,
"donateAddr": String,
"dappWebsite": String,
"statusx": String,
"category": String,
"releaseDate": String,
//social media - if is null then no icon later
"github": String,
"linkedin": String,
"reddit": String,
"rss": String,
"skype": String,
"twitter": String,
"youtube": String,
//store social rating
"upvoteCount": Number,
"downvoteCount": Number
});
var userSchema = new mongoose.Schema({
"username": {type: String, unique: true},
"password": {type: String},
"email": String,
"type": String
});
mongoose.model('devDapp', devDapp);
mongoose.model('User', userSchema);
module.exports = mongoose.model('devDapp');
var User = module.exports = mongoose.model('User');
//user account stuff
module.exports.createUser = function(newUser, callback){
bcrypt.genSalt(10, function(err,salt){
bcrypt.hash(newUser.password,salt,function(err,hash){
newUser.password = hash;
newUser.save(callback);
});
});
}
module.exports.getUserByUsername = function(username, callback){
var query = {username: username};
User.findOne(query, callback);
}
module.exports.getUserById = function(id, callback){
User.findById(id, callback);
}
module.exports.comparePassword = function(candidatePassword, hash,callback){
bcrypt.compare(candidatePassword, hash, function(err, isMatch){
if(err) throw err;
callback(null, isMatch);
});
}
mongoose.connect( 'mongodb://localhost/gimmeDappDB' );
mongoose.set('debug', true);