better usage of cookies for prefs

pull/725/head
Thibault Duplessis 2015-07-17 17:09:18 +02:00
parent 0b2ff2e871
commit b38a375181
4 changed files with 15 additions and 11 deletions

View File

@ -42,7 +42,7 @@ object Pref extends LilaController {
implicit val req = ctx.body
(setters get name) ?? {
case (form, fn) => FormResult(form) { v =>
fn(v, ctx) map { Ok(()) withCookies _ }
fn(v, ctx) map { cookies => Ok(()).withCookies(cookies: _*) }
}
}
}
@ -62,8 +62,9 @@ object Pref extends LilaController {
"bgImg" -> (forms.bgImg -> save("bgImg") _),
"is3d" -> (forms.is3d -> save("is3d") _))
private def save(name: String)(value: String, ctx: Context): Fu[Cookie] =
ctx.me ?? {
api.setPrefString(_, name, value, notifyChange = false)
} inject LilaCookie.session(name, value)(ctx.req)
private def save(name: String)(value: String, ctx: Context): Fu[List[Cookie]] =
ctx.me match {
case Some(me) => api.setPrefString(me, name, value, notifyChange = false) inject Nil
case None => fuccess(List(LilaCookie.session(name, value)(ctx.req)))
}
}

View File

@ -38,8 +38,8 @@ withLangAnnotations: Boolean = true)(body: Html)(implicit ctx: Context)
@openGraph.map(_.html)
<link href="@routes.Blog.atom()" type="application/atom+xml" rel="alternate" title="Latest blog posts" />
@if(withLangAnnotations){@langAnnotations}
@if(ctx.pref.transp) {
<style type="text/css">body.transp::before{background-image:url('@ctx.pref.bgImgOrDefault');}</style>
@ctx.transpBgImg.map { img =>
<style type="text/css">body.transp::before{background-image:url('@img');}</style>
}
</head>
<body class="preload base @List(

View File

@ -48,14 +48,17 @@ sealed trait Context extends lila.user.UserContextWrapper {
def currentSoundSet =
ctxPref("soundSet").fold(Pref.default.realSoundSet)(lila.pref.SoundSet.apply)
def currentBg = ctxPref("bg") | "light"
lazy val currentBg = ctxPref("bg") | "light"
def transpBgImg = pref.bgImg ifTrue pref.transp
def transpBgImg = currentBg == "transp" option {
ctxPref("bgImg") | Pref.defaultBgImg
}
def mobileApiVersion = Mobile.Api requestVersion req
private def ctxPref(name: String): Option[String] =
userContext.req.session get name orElse { pref get name }
if (isAuth) pref get name
else userContext.req.session get name orElse { pref get name }
}
sealed abstract class BaseContext(

View File

@ -92,7 +92,7 @@ case class Pref(
object Pref {
private val defaultBgImg = "http://l1.org/assets/images/background/bench.jpg"
val defaultBgImg = "http://l1.org/assets/images/background/bench.jpg"
object Tag {
val verifyTitle = "verifyTitle"