-
Notifications
You must be signed in to change notification settings - Fork 1
/
program.js
63 lines (45 loc) · 1.43 KB
/
program.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
var express = require('express');
var bodyParser = require('body-parser');
var crypto = require('crypto');
var level = require('level');
var app = express();
var db = level('./emailids', {'valueEncoding': 'json'});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.get('/', function (req, res) {
res.sendfile('index.html');
});
app.get('/bingo/:hash', function (req, res) {
var currentHash = req.params.hash;
console.log(currentHash);
var user = {};
var id = crypto.createHash('md5').update(currentHash + Date.now()).digest('hex');
if(req.cookies.id) {
}
db.get(currentHash, function (err, value) {
if (err) {
if(err.notFound) {
res.sendfile('forgot.html');
}
return;
}
user = value;
res.cookie('id', id,
{ path: '/bingo', maxAge: 8000000, httpOnly: true });
res.sendfile('bingo.html');
});
});
app.post('/signup', function (req, res) {
var user = {};
var hash = crypto.createHash('md5').update(email).digest('hex');
user['email'] = req.body.email;
db.put(hash, user, function (err) {
if (err) {
console.log("can't add key-value pair");
}
res.send('Thanks for signing up!');
});
});
app.listen(3000, function(){
console.log('listening on *:3000');
});