better usage of cookies for prefs
This commit is contained in:
parent
0b2ff2e871
commit
b38a375181
|
@ -42,7 +42,7 @@ object Pref extends LilaController {
|
||||||
implicit val req = ctx.body
|
implicit val req = ctx.body
|
||||||
(setters get name) ?? {
|
(setters get name) ?? {
|
||||||
case (form, fn) => FormResult(form) { v =>
|
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") _),
|
"bgImg" -> (forms.bgImg -> save("bgImg") _),
|
||||||
"is3d" -> (forms.is3d -> save("is3d") _))
|
"is3d" -> (forms.is3d -> save("is3d") _))
|
||||||
|
|
||||||
private def save(name: String)(value: String, ctx: Context): Fu[Cookie] =
|
private def save(name: String)(value: String, ctx: Context): Fu[List[Cookie]] =
|
||||||
ctx.me ?? {
|
ctx.me match {
|
||||||
api.setPrefString(_, name, value, notifyChange = false)
|
case Some(me) => api.setPrefString(me, name, value, notifyChange = false) inject Nil
|
||||||
} inject LilaCookie.session(name, value)(ctx.req)
|
case None => fuccess(List(LilaCookie.session(name, value)(ctx.req)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ withLangAnnotations: Boolean = true)(body: Html)(implicit ctx: Context)
|
||||||
@openGraph.map(_.html)
|
@openGraph.map(_.html)
|
||||||
<link href="@routes.Blog.atom()" type="application/atom+xml" rel="alternate" title="Latest blog posts" />
|
<link href="@routes.Blog.atom()" type="application/atom+xml" rel="alternate" title="Latest blog posts" />
|
||||||
@if(withLangAnnotations){@langAnnotations}
|
@if(withLangAnnotations){@langAnnotations}
|
||||||
@if(ctx.pref.transp) {
|
@ctx.transpBgImg.map { img =>
|
||||||
<style type="text/css">body.transp::before{background-image:url('@ctx.pref.bgImgOrDefault');}</style>
|
<style type="text/css">body.transp::before{background-image:url('@img');}</style>
|
||||||
}
|
}
|
||||||
</head>
|
</head>
|
||||||
<body class="preload base @List(
|
<body class="preload base @List(
|
||||||
|
|
|
@ -48,14 +48,17 @@ sealed trait Context extends lila.user.UserContextWrapper {
|
||||||
def currentSoundSet =
|
def currentSoundSet =
|
||||||
ctxPref("soundSet").fold(Pref.default.realSoundSet)(lila.pref.SoundSet.apply)
|
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
|
def mobileApiVersion = Mobile.Api requestVersion req
|
||||||
|
|
||||||
private def ctxPref(name: String): Option[String] =
|
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(
|
sealed abstract class BaseContext(
|
||||||
|
|
|
@ -92,7 +92,7 @@ case class Pref(
|
||||||
|
|
||||||
object 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 {
|
object Tag {
|
||||||
val verifyTitle = "verifyTitle"
|
val verifyTitle = "verifyTitle"
|
||||||
|
|
Loading…
Reference in a new issue