-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.scala
107 lines (91 loc) · 2.94 KB
/
Main.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package controllers
import akka.pattern.ask
import play.api.data._, Forms._
import play.api.libs.concurrent.Akka
import play.api.libs.iteratee._
import play.api.libs.json._
import play.api.mvc._, Results._
import lila.app._
import lila.common.HTTPRequest
import lila.hub.actorApi.captcha.ValidCaptcha
import makeTimeout.large
import views._
object Main extends LilaController {
private lazy val blindForm = Form(tuple(
"enable" -> nonEmptyText,
"redirect" -> nonEmptyText
))
def toggleBlindMode = OpenBody { implicit ctx =>
implicit val req = ctx.body
fuccess {
blindForm.bindFromRequest.fold(
err => BadRequest, {
case (enable, redirect) =>
Redirect(redirect) withCookies lila.common.LilaCookie.cookie(
Env.api.Accessibility.blindCookieName,
if (enable == "0") "" else Env.api.Accessibility.hash,
maxAge = Env.api.Accessibility.blindCookieMaxAge.some,
httpOnly = true.some)
})
}
}
def websocket = SocketOption { implicit ctx =>
get("sri") ?? { uid =>
fuccess(Env.site.socketHandler(uid, ctx.userId, get("flag")).some)
}
}
def captchaCheck(id: String) = Open { implicit ctx =>
Env.hub.actor.captcher ? ValidCaptcha(id, ~get("solution")) map {
case valid: Boolean => Ok(valid fold (1, 0))
}
}
def embed = Action { req =>
Ok {
s"""document.write("<iframe src='${Env.api.Net.BaseUrl}?embed=" + document.domain + "' class='lichess-iframe' allowtransparency='true' frameBorder='0' style='width: ${getInt("w", req) | 820}px; height: ${getInt("h", req) | 650}px;' title='Lichess free online chess'></iframe>");"""
} as JAVASCRIPT withHeaders (CACHE_CONTROL -> "max-age=86400")
}
def developers = Open { implicit ctx =>
fuccess {
html.site.developers()
}
}
def themepicker = Open { implicit ctx =>
fuccess {
html.base.themepicker()
}
}
def lag = Open { implicit ctx =>
fuccess {
html.site.lag()
}
}
def mobile = Open { implicit ctx =>
OptionOk(Prismic getBookmark "mobile-apk") {
case (doc, resolver) => html.mobile.home(doc, resolver)
}
}
def mobileRegister(platform: String, deviceId: String) = Auth { implicit ctx =>
me =>
Env.push.registerDevice(me, platform, deviceId)
}
def mobileUnregister = Auth { implicit ctx =>
me =>
Env.push.unregisterDevices(me)
}
def jslog(id: String) = Open { ctx =>
val referer = HTTPRequest.referer(ctx.req)
lila.log("cheat").branch("jslog").info(s"${ctx.req.remoteAddress} ${ctx.userId} $referer")
lila.mon.cheat.cssBot()
ctx.userId.?? {
Env.report.api.autoBotReport(_, referer)
}
lila.game.GameRepo pov id map {
_ ?? lila.game.GameRepo.setBorderAlert
} inject Ok
}
def notFound(req: RequestHeader): Fu[Result] =
reqToCtx(req) map { implicit ctx =>
lila.mon.http.response.code404()
NotFound(html.base.notFound())
}
}