Skip to content

Commit

Permalink
allow forcing kid mode with http header (lichess-org#13882)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Nov 5, 2023
1 parent e7fdb78 commit 072c282
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/api/src/main/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ final class LoginContext(
def isBot = me.exists(_.isBot)
def noBot = !isBot
def troll = user.exists(_.marks.troll)
def kid = user.exists(_.kid)
def noKid = !kid
def isKidUser = user.exists(_.kid)
def isAppealUser = me.exists(_.enabled.no)
def isWebAuth = isAuth && oauth.isEmpty
def isOAuth = isAuth && oauth.isDefined
Expand All @@ -49,6 +48,8 @@ class Context(
def noBlind = !blind
lazy val mobileApiVersion = lila.security.Mobile.Api requestVersion req
def isMobileApi = mobileApiVersion.isDefined
def kid = HTTPRequest.isKid(req) || loginContext.isKidUser
def noKid = !kid
def flash(name: String): Option[String] = req.flash get name
def withLang(l: Lang) = new Context(req, l, loginContext, pref)

Expand Down
4 changes: 4 additions & 0 deletions modules/common/src/main/HTTPRequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import play.api.http.HeaderNames
import play.api.mvc.RequestHeader
import play.api.routing.Router
import scala.util.matching.Regex
import lila.common.Form.trueish

object HTTPRequest:

Expand Down Expand Up @@ -145,3 +146,6 @@ object HTTPRequest:
// this header is set by our nginx config, based on the nginx whitelist file.
def nginxWhitelist(req: RequestHeader) =
req.headers.get("X-Ip-Tier").flatMap(_.toIntOption).exists(_ > 1)

def isKid(req: RequestHeader) =
req.headers.get("X-Lichess-KidMode").exists(trueish)

0 comments on commit 072c282

Please sign in to comment.