equal
deleted
inserted
replaced
4 def mk_hash(s: String) : String = { |
4 def mk_hash(s: String) : String = { |
5 val hash_fun = MessageDigest.getInstance("SHA-1") |
5 val hash_fun = MessageDigest.getInstance("SHA-1") |
6 hash_fun.digest(s.getBytes).map{ "%02x".format(_) }.mkString |
6 hash_fun.digest(s.getBytes).map{ "%02x".format(_) }.mkString |
7 } |
7 } |
8 |
8 |
9 def gt_cookie(c: Option[Cookie]) : Int = |
9 def gt_cookie(c: Cookie) : Int = c.value.split("/") match { |
10 c.map(_.value.split("/")) match { |
10 case Array(s, h) |
11 case Some(Array(s, h)) |
11 if (s.forall(_.isDigit) && mk_hash(s) == h) => s.toInt |
12 if (s.forall(_.isDigit) && mk_hash(s) == h) => s.toInt |
12 case _ => 0 |
13 case _ => 0 |
13 } |
14 } |
|
15 |
14 |
16 def mk_cookie(i: Int) : Cookie = { |
15 def mk_cookie(i: Int) : Cookie = { |
17 val s = i.toString |
16 val hash = mk_hash(i.toString) |
18 Cookie("visits", s + "/" + mk_hash(s)) |
17 Cookie("visits", s"$i/$hash") |
19 } |
18 } |
20 |
19 |
21 def index = Action { request => ... } |
20 def index = Action { request => ... } |
22 } |
21 } |
23 |
22 |