equal
deleted
inserted
replaced
18 function gt_cookie(s) { |
18 function gt_cookie(s) { |
19 var splits = s.split("-", 2); |
19 var splits = s.split("-", 2); |
20 var counter = parseInt(splits[0]) |
20 var counter = parseInt(splits[0]) |
21 var hash = splits[1] |
21 var hash = splits[1] |
22 if (mk_hash(counter.toString() + salt) == hash) { |
22 if (mk_hash(counter.toString() + salt) == hash) { |
23 return counter |
23 return counter |
24 } else { |
24 } else { |
25 return 0 |
25 return 0 |
26 } |
26 } |
27 } |
27 } |
28 |
|
29 |
28 |
30 app.get('/', function(req, res){ |
29 app.get('/', function(req, res){ |
31 var counter = gt_cookie(req.cookies.counter) || 0; |
30 var counter = gt_cookie(req.cookies.counter) || 0; |
32 res.cookie('counter', mk_cookie(counter + 1)); |
31 res.cookie('counter', mk_cookie(counter + 1)); |
33 if (counter >= 5) { |
32 if (counter >= 5) { |
34 res.write('You are a valued customer ' + |
33 res.write('You are a valued customer ' + |
35 'visting the site ' + counter + ' times.'); |
34 'visting the site ' + counter + ' times.'); |
36 } else { |
35 } else { |
37 res.write('This is visit number '+ counter +'!'); |
36 res.write('This is visit number '+ counter +'!'); |
38 } |
37 } |
39 res.end(); |
38 res.end(); |
40 }); |
39 }); |
41 |
40 |
42 // starting the server |
41 // starting the server |