-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
52 lines (48 loc) · 1.49 KB
/
functions.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
var config = {
user: 'uuwfugiqgqhqnf',
database: 'd28f8fbcb9h2bs',
password: '3d8b2018c28fe6a3b1b61c8e6366ece388d3667c032fd9214546bc3f923e9e72',
host: 'ec2-54-235-173-161.compute-1.amazonaws.com',
port: '5432',
max: 10,
idleTimeoutMillis: 3000,
};
//var bcrypt = require('bcryptjs'),
var Q = require('q');
var pg = require('pg');
pg.defaults.ssl = true;
var pool = new pg.Pool(config);
exports.localReg = function (username, password) {
var deferred = Q.defer();
var collection={};
pool.connect(function (err, db) {
db.query('SELECT * FROM public.users', function(err, res)
{
console.log(res.rows);
collection=res.rows[0];
});
//check if username is already assigned in our database
// collection.findOne({'username' : username})
// .then(function (result) {
// if (null != result) {
// console.log("USERNAME ALREADY EXISTS:", result.username);
// deferred.resolve(false); // username exists
// }
// else {
// var hash = bcrypt.hashSync(password, 8);
// var user = {
// "username": username,
// "password": hash,
// "avatar": "http://placepuppy.it/images/homepage/Beagle_puppy_6_weeks.JPG"
// }
// console.log("CREATING USER:", username);
// collection.insert(user)
// .then(function () {
// db.close();
// deferred.resolve(user);
// });
// }
// });
});
return deferred.promise;
};