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