93
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
object Application extends Controller {
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
//SHA-1, SHA-256
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
def mk_hash(s: String) : String = {
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
val hash_fun = MessageDigest.getInstance("SHA-1")
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
hash_fun.digest(s.getBytes).map{ "%02x".format(_) }.mkString
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
}
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
|
98
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
9 |
def gt_cookie(c: Cookie) : Int = c.value.split("/") match {
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
10 |
case Array(s, h)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
11 |
if (s.forall(_.isDigit) && mk_hash(s) == h) => s.toInt
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
12 |
case _ => 0
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
13 |
}
|
93
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
def mk_cookie(i: Int) : Cookie = {
|
98
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
16 |
val hash = mk_hash(i.toString)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
17 |
Cookie("visits", s"$i/$hash")
|
93
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
}
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
def index = Action { request => ... }
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
}
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
|