make the site template layout compile
parent
e4d7b1c23e
commit
355da3ca58
|
@ -0,0 +1,7 @@
|
|||
package lila.app
|
||||
|
||||
trait Modules {
|
||||
|
||||
def userEnv = lila.user.Env.current
|
||||
def gameEnv = lila.game.Env.current
|
||||
}
|
|
@ -2,7 +2,7 @@ package controllers
|
|||
|
||||
import lila.app._
|
||||
import lila.api._
|
||||
import lila.http.LilaCookie
|
||||
import lila.common.LilaCookie
|
||||
|
||||
import play.api.mvc._
|
||||
import play.api.mvc.Results._
|
||||
|
@ -25,6 +25,16 @@ object Auth extends LilaController {
|
|||
// Redirect(routes.User.show(username)) withCookies LilaCookie.session("sessionId", sessionId)
|
||||
// }
|
||||
|
||||
def login = TODO
|
||||
// Open { implicit ctx ⇒
|
||||
// Ok(html.auth.login(loginForm))
|
||||
// }
|
||||
|
||||
def authenticate = TODO
|
||||
def logout = TODO
|
||||
def signup = TODO
|
||||
def signupPost = TODO
|
||||
|
||||
protected def gotoLogoutSucceeded(implicit req: RequestHeader) = {
|
||||
req.session get "sessionId" foreach lila.security.Store.delete
|
||||
logoutSucceeded(req) withCookies LilaCookie.newSession
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import views._
|
||||
|
||||
object ForumCateg extends LilaController with ForumController {
|
||||
|
||||
// def index = Open { implicit ctx ⇒
|
||||
// IOk(categApi list ~ctx.me.map(teamCache.teamIds) map {
|
||||
// html.forum.categ.index(_)
|
||||
// })
|
||||
// }
|
||||
|
||||
def show(slug: String, page: Int) = TODO
|
||||
// Open { implicit ctx ⇒
|
||||
// CategGrantRead(slug) {
|
||||
// IOptionOk(categApi.show(slug, page)) {
|
||||
// case (categ, topics) ⇒ html.forum.categ.show(categ, topics)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
|
@ -3,13 +3,15 @@ package controllers
|
|||
import lila.app._
|
||||
import lila.user.Context
|
||||
import lila.forum
|
||||
import lila.team.Env.{ current ⇒ teamEnv }
|
||||
|
||||
import play.api.mvc._
|
||||
import play.api.mvc.Results._
|
||||
|
||||
trait Controller extends forum.Granter { self: LilaController ⇒
|
||||
trait ForumController extends forum.Granter { self: LilaController ⇒
|
||||
|
||||
// protected def userBelongsToTeam = env.team.api.belongsTo _
|
||||
protected def userBelongsToTeam(teamId: String, userId: String): Fu[Boolean] =
|
||||
teamEnv.api.belongsTo(teamId, userId)
|
||||
|
||||
protected def CategGrantRead[A <: Result](categSlug: String)(a: ⇒ A)(implicit ctx: Context): Result =
|
||||
isGrantedRead(categSlug).fold(a,
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import views._
|
||||
import lila.user.Context
|
||||
import lila.common.LilaCookie
|
||||
import lila.i18n._
|
||||
|
||||
import play.api.data.Form
|
||||
|
||||
object I18n extends LilaController {
|
||||
|
||||
// private def transInfos = env.i18n.transInfos
|
||||
// private def pool = env.i18n.pool
|
||||
// private def translator = env.i18n.translator
|
||||
// private def forms = env.i18n.forms
|
||||
// private def i18nKeys = env.i18n.keys
|
||||
// private def repo = env.i18n.translationRepo
|
||||
|
||||
def contribute = TODO
|
||||
// Open { implicit ctx ⇒
|
||||
// val mines = (pool fixedReqAcceptLanguages ctx.req map { lang ⇒
|
||||
// transInfos get lang
|
||||
// }).toList.flatten
|
||||
// Ok(html.i18n.contribute(transInfos.all, mines))
|
||||
// }
|
||||
|
||||
// def translationForm(lang: String) = Open { implicit ctx ⇒
|
||||
// OptionOk(transInfos get lang) { info ⇒
|
||||
// val (form, captcha) = forms.translationWithCaptcha
|
||||
// renderTranslationForm(form, info, captcha)
|
||||
// }
|
||||
// }
|
||||
|
||||
// def translationPost(lang: String) = OpenBody { implicit ctx ⇒
|
||||
// OptionResult(transInfos get lang) { info ⇒
|
||||
// implicit val req = ctx.body
|
||||
// val data = forms.decodeTranslationBody
|
||||
// FormIOResult(forms.translation) { form ⇒
|
||||
// renderTranslationForm(form, info, forms.captchaCreate, data)
|
||||
// } { metadata ⇒
|
||||
// forms.process(lang, metadata, data) map { _ ⇒
|
||||
// Redirect(routes.I18n.contribute).flashing("success" -> "1")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// private def renderTranslationForm(form: Form[_], info: TransInfo, captcha: Captcha.Challenge, data: Map[String, String] = Map.empty)(implicit ctx: Context) =
|
||||
// html.i18n.translationForm(
|
||||
// info,
|
||||
// form,
|
||||
// i18nKeys,
|
||||
// pool.default,
|
||||
// translator.rawTranslation(info.lang) _,
|
||||
// captcha,
|
||||
// data)
|
||||
|
||||
// def fetch(from: Int) = Open { implicit ctx ⇒
|
||||
// JsonOk((repo findFrom from map {
|
||||
// _ map (_.toJson)
|
||||
// }).unsafePerformIO)
|
||||
// }
|
||||
|
||||
// val hideCalls = Open { implicit ctx ⇒
|
||||
// implicit val req = ctx.req
|
||||
// val cookie = LilaCookie.cookie(
|
||||
// env.i18n.hideCallsCookieName,
|
||||
// "1",
|
||||
// maxAge = env.i18n.hideCallsCookieMaxAge.some)
|
||||
// Redirect(routes.Lobby.home()) withCookies cookie
|
||||
// }
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import lila.http.LilaCookie
|
||||
import lila.common.LilaCookie
|
||||
import lila.user.{ Context, HeaderContext, BodyContext, User ⇒ UserModel }
|
||||
import lila.user.Env.{ current ⇒ userEnv }
|
||||
import lila.security.{ Permission, Granter }
|
||||
|
@ -16,6 +16,7 @@ import play.api.libs.concurrent.Execution.Implicits._
|
|||
|
||||
trait LilaController
|
||||
extends Controller
|
||||
with Modules
|
||||
with ContentTypes
|
||||
with RequestGetter
|
||||
with ResponseWriter {
|
||||
|
@ -26,10 +27,6 @@ trait LilaController
|
|||
|
||||
// protected def toJson[A: WritesJson](data: A) = Json toJson data
|
||||
|
||||
val TODO = Action {
|
||||
NotImplemented[play.api.templates.Html](views.html.defaultpages.todo())
|
||||
}
|
||||
|
||||
protected def Open(f: Context ⇒ Fu[Result]): Action[AnyContent] =
|
||||
Open(BodyParsers.parse.anyContent)(f)
|
||||
|
||||
|
@ -104,11 +101,10 @@ trait LilaController
|
|||
|
||||
// protected def ValidIOk(valid: IO[Valid[Unit]]): Result = ValidOk(valid.unsafePerformIO)
|
||||
|
||||
// protected def FormResult[A](form: Form[A])(op: A ⇒ Result)(implicit req: Request[_]) =
|
||||
// form.bindFromRequest.fold(
|
||||
// form ⇒ BadRequest(form.errors mkString "\n"),
|
||||
// data ⇒ op(data)
|
||||
// )
|
||||
protected def FormResult[A](form: Form[A])(op: A ⇒ Fu[Result])(implicit req: Request[_]): Fu[Result] =
|
||||
form.bindFromRequest.fold(
|
||||
form ⇒ fuccess(BadRequest(form.errors mkString "\n")),
|
||||
op)
|
||||
|
||||
// protected def FormIOResult[A, B](form: Form[A])(err: Form[A] ⇒ B)(op: A ⇒ IO[Result])(
|
||||
// implicit writer: Writeable[B],
|
||||
|
@ -173,7 +169,7 @@ trait LilaController
|
|||
// protected def IOptionResult[A](ioa: IO[Option[A]])(op: A ⇒ Result)(implicit ctx: Context) =
|
||||
// ioa.unsafePerformIO.fold(notFound(ctx))(a ⇒ op(a))
|
||||
|
||||
protected def notFound(implicit ctx: Context): Fu[Result] =
|
||||
protected def notFound(implicit ctx: Context): Fu[Result] =
|
||||
Lobby handleNotFound ctx
|
||||
|
||||
// protected def todo = Open { implicit ctx ⇒
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import views._
|
||||
|
||||
import play.api.mvc._
|
||||
import play.api.mvc.Results._
|
||||
import play.api.data._
|
||||
import play.api.data.Forms._
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.iteratee._
|
||||
import play.api.libs.concurrent.Akka
|
||||
|
||||
object Main extends LilaController {
|
||||
|
||||
// def websocket = WebSocket.async[JsValue] { implicit req ⇒
|
||||
// implicit val ctx = reqToCtx(req)
|
||||
// env.site.socket.join(
|
||||
// uidOption = get("sri"),
|
||||
// username = ctx.me map (_.username),
|
||||
// flag = get("flag")
|
||||
// )
|
||||
// }
|
||||
|
||||
// def captchaCheck(id: String) = Open { implicit ctx ⇒
|
||||
// Ok(env.site.captcha get id valid ~get("solution") fold (1, 0))
|
||||
// }
|
||||
|
||||
// def embed = Open { implicit ctx ⇒
|
||||
// JsOk("""document.write("<iframe src='%s?embed=" + document.domain + "' class='lichess-iframe' allowtransparency='true' frameBorder='0' style='width: %dpx; height: %dpx;' title='Lichess free online chess'></iframe>");"""
|
||||
// .format(env.settings.NetBaseUrl, getInt("w") | 820, getInt("h") | 650),
|
||||
// CACHE_CONTROL -> "max-age=86400"
|
||||
// )
|
||||
// }
|
||||
|
||||
def developers = TODO
|
||||
// Open { implicit ctx ⇒
|
||||
// Ok(views.html.site.developers())
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package controllers
|
||||
|
||||
import play.api.mvc._
|
||||
import play.api.libs.Comet
|
||||
import play.api.libs.concurrent._
|
||||
import play.api.libs.json._
|
||||
import akka.pattern.ask
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
|
||||
import lila.app._
|
||||
import lila.socket.actorApi.GetNbMembers
|
||||
// import lila.monitor._
|
||||
import makeTimeout.short
|
||||
|
||||
object Monitor extends LilaController {
|
||||
|
||||
// private def reporting = env.monitor.reporting
|
||||
// private def usernameMemo = env.user.usernameMemo
|
||||
// private def userRepo = env.user.userRepo
|
||||
// private def gameRepo = env.game.gameRepo
|
||||
|
||||
def index = TODO
|
||||
// Action {
|
||||
// Ok(views.html.monitor.monitor())
|
||||
// }
|
||||
|
||||
// def websocket = WebSocket.async[JsValue] { implicit req ⇒
|
||||
// env.monitor.socket.join(uidOption = get("sri", req))
|
||||
// }
|
||||
|
||||
// def status = Open { implicit ctx ⇒
|
||||
// Async {
|
||||
// import lila.common.Futuristic.ioToFuture
|
||||
// (~get("key") match {
|
||||
// case "elo" ⇒
|
||||
// userRepo.idsAverageElo(usernameMemo.keys).toFuture zip
|
||||
// gameRepo.recentAverageElo(5).toFuture map {
|
||||
// case (users, (rated, casual)) ⇒ List(users, rated, casual) mkString " "
|
||||
// }
|
||||
// case "moves" ⇒ (reporting ? GetNbMoves).mapTo[Int]
|
||||
// case "players" ⇒ (reporting ? GetNbMembers).mapTo[Int] map { "%d %d".format(_, usernameMemo.preciseCount) }
|
||||
// case _ ⇒ (reporting ? GetStatus).mapTo[String]
|
||||
// }) map { x ⇒ Ok(x.toString) }
|
||||
// }
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import views._
|
||||
import lila.user.{ Context, BodyContext, Setting ⇒ UserSetting }
|
||||
|
||||
import play.api.data.Form
|
||||
import play.api.mvc.{ Result, Cookie }
|
||||
import play.api.mvc.Results._
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
|
||||
object Setting extends LilaController {
|
||||
|
||||
def set(name: String) = OpenBody { implicit ctx ⇒
|
||||
implicit val req = ctx.body
|
||||
(setters get name) zmap {
|
||||
case (form, fn) ⇒ FormResult(form) { v ⇒
|
||||
fn(UserSetting(ctx), v) map { Ok() withCookies _ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private type Setter = (Form[String], (UserSetting, String) ⇒ Fu[Cookie])
|
||||
|
||||
private def forms = userEnv.forms
|
||||
|
||||
private lazy val setters = Map(
|
||||
"theme" -> setTheme,
|
||||
"sound" -> setSound,
|
||||
"chat" -> setChat,
|
||||
"bg" -> setBg)
|
||||
|
||||
private lazy val setTheme: Setter = forms.theme -> {
|
||||
(setting, v) ⇒ setting.theme(v)
|
||||
}
|
||||
|
||||
private lazy val setSound: Setter = forms.sound -> {
|
||||
(setting, v) ⇒ setting.sound(v)
|
||||
}
|
||||
|
||||
private lazy val setChat: Setter = forms.chat -> {
|
||||
(setting, v) ⇒ setting.chat(v)
|
||||
}
|
||||
|
||||
private lazy val setBg: Setter = forms.bg -> {
|
||||
(setting, v) ⇒ setting.bg(v)
|
||||
}
|
||||
}
|
|
@ -9,4 +9,6 @@ import play.api.mvc.Results._
|
|||
object Team extends LilaController {
|
||||
|
||||
def show(id: String, page: Int) = TODO
|
||||
|
||||
def requests = TODO
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import lila.app._
|
|||
import views._
|
||||
import lila.security.Permission
|
||||
import lila.user.{ Context, User ⇒ UserModel }
|
||||
import lila.http.LilaCookie
|
||||
import lila.common.LilaCookie
|
||||
import lila.user.Env.{ current ⇒ userEnv }
|
||||
import lila.security.Env.{ current ⇒ securityEnv }
|
||||
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
package lila
|
||||
|
||||
package object app extends PackageObject with WithPlay
|
||||
import scalaz.Zero
|
||||
import play.api.mvc.{ Result, Results }
|
||||
|
||||
package object app extends PackageObject with WithPlay {
|
||||
|
||||
implicit val LilaResultZero = new Zero[Result] {
|
||||
val zero = Results.NotFound
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ object Environment
|
|||
with PaginatorHelper
|
||||
with FormHelper
|
||||
with SetupHelper
|
||||
with SettingHelper
|
||||
with MessageHelper
|
||||
with RoundHelper
|
||||
with AiHelper
|
||||
|
@ -25,9 +26,9 @@ object Environment
|
|||
with ForumHelper
|
||||
with I18nHelper
|
||||
with BookmarkHelper
|
||||
with NotificationHelper {
|
||||
with NotificationHelper
|
||||
with TeamHelper {
|
||||
// with tournament.TournamentHelper
|
||||
// with team.TeamHelper {
|
||||
|
||||
def netDomain = apiEnv.Net.Domain
|
||||
def netBaseUrl = apiEnv.Net.BaseUrl
|
||||
|
|
|
@ -2,11 +2,15 @@ package lila.app
|
|||
package templating
|
||||
|
||||
import lila.forum.{ Granter, Post }
|
||||
import lila.team.Env.{ current ⇒ teamEnv }
|
||||
|
||||
import play.api.templates.Html
|
||||
|
||||
trait ForumHelper extends Granter { self: UserHelper with StringHelper ⇒
|
||||
|
||||
protected def userBelongsToTeam(teamId: String, userId: String): Fu[Boolean] =
|
||||
teamEnv.api.belongsTo(teamId, userId)
|
||||
|
||||
def authorName(post: Post) =
|
||||
post.userId.fold(escape(post.showAuthor))(userIdToUsername)
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package lila.app
|
||||
package templating
|
||||
|
||||
import http.{ Context, Setting }
|
||||
import lila.user.Theme
|
||||
import lila.user.{ Theme, Setting, Context }
|
||||
|
||||
import play.api.templates.Html
|
||||
|
|
@ -6,27 +6,29 @@ import lila.user.Context
|
|||
import controllers.routes
|
||||
|
||||
import play.api.templates.Html
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
|
||||
// TODO
|
||||
// trait TeamHelper {
|
||||
trait TeamHelper {
|
||||
|
||||
// private def cached = env.team.cached
|
||||
private def api = teamEnv.api
|
||||
|
||||
// def myTeam(teamId: String)(implicit ctx: Context): Boolean =
|
||||
// ctx.me.zmap(me ⇒ teamEnv.api.belongsTo(teamId, me.id))
|
||||
def myTeam(teamId: String)(implicit ctx: Context): Boolean =
|
||||
ctx.me.zmap(me ⇒ api.belongsTo(teamId, me.id).await)
|
||||
|
||||
// def teamIds(userId: String): List[String] = env.team.cached.teamIds(userId)
|
||||
def teamIds(userId: String): List[String] =
|
||||
api.teamIds(userId).await
|
||||
|
||||
// def teamIdToName(id: String): String = (cached name id) | id
|
||||
def teamIdToName(id: String): String = (api teamName id).await | id
|
||||
|
||||
// def teamLink(id: String, cssClass: Option[String] = None): Html = Html {
|
||||
// """<a class="%s" href="%s">%s</a>""".format(
|
||||
// ~cssClass.map(" " + _),
|
||||
// routes.Team.show(id),
|
||||
// teamIdToName(id))
|
||||
// }
|
||||
def teamLink(id: String, cssClass: Option[String] = None): Html = Html {
|
||||
"""<a class="%s" href="%s">%s</a>""".format(
|
||||
cssClass.zmap(" " + _),
|
||||
routes.Team.show(id),
|
||||
teamIdToName(id))
|
||||
}
|
||||
|
||||
// def teamForumUrl(id: String) = routes.ForumCateg.show("team-" + id)
|
||||
def teamForumUrl(id: String) = routes.ForumCateg.show("team-" + id)
|
||||
|
||||
// def teamNbRequests(ctx: Context) = ~ctx.me.map(cached.nbRequests)
|
||||
// }
|
||||
def teamNbRequests(ctx: Context) =
|
||||
(ctx.userId zmap api.nbRequests).await
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import play.api.templates.Html
|
|||
// TODO
|
||||
trait UiHelper { self: I18nHelper ⇒
|
||||
|
||||
// lazy val siteMenu = new SiteMenu(trans)
|
||||
lazy val siteMenu = new lila.app.ui.SiteMenu(trans)
|
||||
|
||||
// lazy val lobbyMenu = new LobbyMenu(trans)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ final class SiteMenu(trans: I18nKeys) {
|
|||
import SiteMenu._
|
||||
|
||||
// TODO
|
||||
// val play = new Elem("play", routes.Lobby.home, trans.play)
|
||||
val play = new Elem("play", routes.Lobby.home, trans.play)
|
||||
// val game = new Elem("game", routes.Game.realtime, trans.games)
|
||||
// val tournament = new Elem("tournament", routes.Tournament.home, trans.tournament)
|
||||
// val user = new Elem("user", routes.User.list(page = 1), trans.people)
|
||||
|
@ -20,10 +20,10 @@ final class SiteMenu(trans: I18nKeys) {
|
|||
// val forum = new Elem("forum", routes.ForumCateg.index, trans.forum)
|
||||
// val message = new Elem("message", routes.Message.inbox(page = 1), trans.inbox)
|
||||
|
||||
// private val authenticated = List(play, game, tournament, user, team, forum, message)
|
||||
// private val anonymous = List(play, game, tournament, user, team, forum)
|
||||
private val authenticated = List(play)//, game, tournament, user, team, forum, message)
|
||||
private val anonymous = List(play)//, game, tournament, user, team, forum)
|
||||
|
||||
// def all(me: Option[User]) = me.isDefined.fold(authenticated, anonymous)
|
||||
def all(me: Option[User]) = me.isDefined.fold(authenticated, anonymous)
|
||||
}
|
||||
|
||||
object SiteMenu {
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
@(title: String, active: Option[ui.SiteMenu.Elem] = None, baseline: Option[Html] = None, goodies: Option[Html] = None, menu: Option[Html] = None, chat: Option[Html] = None, underchat: Option[Html] = None, robots: Boolean = true, moreCss: Html = Html(""), moreJs: Html = Html(""), signedJs: Option[String] = None)(body: Html)(implicit ctx: Context)
|
||||
@(
|
||||
title: String,
|
||||
active: Option[lila.app.ui.SiteMenu.Elem] = None,
|
||||
baseline: Option[Html] = None,
|
||||
goodies: Option[Html] = None,
|
||||
menu: Option[Html] = None,
|
||||
chat: Option[Html] = None,
|
||||
underchat: Option[Html] = None,
|
||||
robots: Boolean = true,
|
||||
moreCss: Html = Html(""),
|
||||
moreJs: Html = Html(""),
|
||||
signedJs: Option[String] = None)(body: Html)(implicit ctx: Context)
|
||||
<!doctype html>
|
||||
<html lang="@lang.language">
|
||||
<head>
|
||||
|
@ -123,5 +134,5 @@
|
|||
@if(lang.language != "en") {
|
||||
<script src="@routes.Assets.at("trans/" + lang.language + ".js")?v=@assetVersion"></script>
|
||||
}
|
||||
</body>
|
||||
</html>
|
||||
</body>
|
||||
</html>
|
28
conf/routes
28
conf/routes
|
@ -5,9 +5,6 @@
|
|||
# Lobby
|
||||
GET / controllers.Lobby.home
|
||||
|
||||
# Misc
|
||||
POST /cli controllers.Cli.command
|
||||
|
||||
# User
|
||||
# POST /@/:username/export controllers.User.export(username: String)
|
||||
# GET /@/:username/:filterName controllers.User.showFilter(username: String, filterName: String, page: Int ?= 1)
|
||||
|
@ -79,7 +76,7 @@ GET /$fullId<[\w\-]{12}> controllers.Round.player(fu
|
|||
# GET /team/new controllers.Team.form
|
||||
# POST /team/new controllers.Team.create
|
||||
# GET /team/me controllers.Team.mine
|
||||
# GET /team/requests controllers.Team.requests
|
||||
GET /team/requests controllers.Team.requests
|
||||
# GET /team/search controllers.Team.search(text: String ?= "", page: Int ?= 1)
|
||||
GET /team/:id controllers.Team.show(id: String, page: Int ?= 1)
|
||||
# GET /team/:id/join controllers.Team.joinPage(id: String)
|
||||
|
@ -101,7 +98,7 @@ GET /team/:id controllers.Team.show(id: String,
|
|||
# GET /$gameId<[\w\-]{8}>/pgn controllers.Analyse.pgn(gameId: String)
|
||||
#
|
||||
# Setting
|
||||
# POST /setting/:name controllers.Setting.set(name: String)
|
||||
POST /setting/:name controllers.Setting.set(name: String)
|
||||
#
|
||||
# Setup
|
||||
# GET /setup/ai controllers.Setup.aiForm
|
||||
|
@ -116,18 +113,18 @@ GET /team/:id controllers.Team.show(id: String,
|
|||
# POST /api/game/new controllers.Setup.api
|
||||
#
|
||||
# I18n
|
||||
# GET /translation/contribute controllers.I18n.contribute
|
||||
GET /translation/contribute controllers.I18n.contribute
|
||||
# GET /translation/form/:lang controllers.I18n.translationForm(lang: String)
|
||||
# POST /translation/form/:lang controllers.I18n.translationPost(lang: String)
|
||||
# GET /translation/fetch/:from controllers.I18n.fetch(from: Int)
|
||||
# POST /translation/hideCalls controllers.I18n.hideCalls
|
||||
#
|
||||
# Authentication
|
||||
# GET /login controllers.Auth.login
|
||||
# POST /login controllers.Auth.authenticate
|
||||
# GET /logout controllers.Auth.logout
|
||||
# GET /signup controllers.Auth.signup
|
||||
# POST /signup controllers.Auth.signupPost
|
||||
GET /login controllers.Auth.login
|
||||
POST /login controllers.Auth.authenticate
|
||||
GET /logout controllers.Auth.logout
|
||||
GET /signup controllers.Auth.signup
|
||||
POST /signup controllers.Auth.signupPost
|
||||
#
|
||||
# Mod
|
||||
# POST /mod/:username/engine controllers.Mod.engine(username: String)
|
||||
|
@ -159,7 +156,7 @@ GET /wiki/:slug controllers.Wiki.show(slug: String)
|
|||
# Forum
|
||||
# GET /forum controllers.ForumCateg.index
|
||||
# GET /forum/recent controllers.ForumPost.recent
|
||||
# GET /forum/:slug controllers.ForumCateg.show(slug: String, page: Int ?= 1)
|
||||
GET /forum/:slug controllers.ForumCateg.show(slug: String, page: Int ?= 1)
|
||||
# GET /forum/:categSlug/form controllers.ForumTopic.form(categSlug: String)
|
||||
# POST /forum/:categSlug/new controllers.ForumTopic.create(categSlug: String)
|
||||
# GET /forum/:categSlug/:slug controllers.ForumTopic.show(categSlug: String, slug: String, page: Int ?= 1)
|
||||
|
@ -178,11 +175,16 @@ GET /wiki/:slug controllers.Wiki.show(slug: String)
|
|||
DELETE /notification/$id<[\w]{8}> controllers.Notification.remove(id)
|
||||
#
|
||||
# Monitor
|
||||
# GET /monitor controllers.Monitor.index
|
||||
GET /monitor controllers.Monitor.index
|
||||
# GET /monitor/socket controllers.Monitor.websocket
|
||||
# GET /monitor/players controllers.Monitor.nbPlayers
|
||||
# GET /monitor/mps controllers.Monitor.nbMoves
|
||||
# GET /monitor/status controllers.Monitor.status
|
||||
|
||||
# Misc
|
||||
POST /cli controllers.Cli.command
|
||||
# GET /captcha/$id<[\w]{8}> controllers.Main.captchaCheck(id: String)
|
||||
GET /developers controllers.Main.developers
|
||||
|
||||
# Assets
|
||||
GET /assets/*file controllers.Assets.at(path="/public", file)
|
||||
|
|
|
@ -8,9 +8,7 @@ trait Granter {
|
|||
private val TeamSlugPattern = """^team-([\w-]+)$""".r
|
||||
private val StaffSlug = "staff"
|
||||
|
||||
protected def userBelongsToTeam(teamId: String, userId: String): Fu[Boolean] =
|
||||
// TODO make abstract
|
||||
fuccess(false)
|
||||
protected def userBelongsToTeam(teamId: String, userId: String): Fu[Boolean]
|
||||
|
||||
def isGrantedRead(categSlug: String)(implicit ctx: Context): Boolean =
|
||||
(categSlug == StaffSlug).fold(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package lila.security
|
||||
|
||||
import lila.common.PimpedJson._
|
||||
import lila.http.LilaCookie
|
||||
import lila.common.LilaCookie
|
||||
import lila.db.api._
|
||||
import tube.firewallTube
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import tube.{ anonConfigTube, filterConfigTube }
|
|||
import lila.game.Game
|
||||
import lila.db.Implicits._
|
||||
import lila.db.api._
|
||||
import lila.http.LilaCookie
|
||||
import lila.common.LilaCookie
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
|
|
|
@ -36,7 +36,7 @@ final class Env(
|
|||
private[team] lazy val requestColl = db(CollectionRequest)
|
||||
private[team] lazy val memberColl = db(CollectionMember)
|
||||
|
||||
private[team] lazy val cached = new Cached(CacheCapacity)
|
||||
lazy val cached = new Cached(CacheCapacity)
|
||||
private[team] lazy val paginator = new PaginatorBuilder(
|
||||
maxPerPage = PaginatorMaxPerPage,
|
||||
maxUserPerPage = PaginatorMaxUserPerPage)
|
||||
|
|
|
@ -140,4 +140,10 @@ final class TeamApi(
|
|||
|
||||
def belongsTo(teamId: String, userId: String): Fu[Boolean] =
|
||||
cached teamIds userId map (_ contains teamId)
|
||||
|
||||
def teamIds(userId: String) = cached teamIds userId
|
||||
|
||||
def teamName(teamId: String) = cached name teamId
|
||||
|
||||
def nbRequests(teamId: String) = cached nbRequests teamId
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ final class Env(config: Config, db: lila.db.Env) {
|
|||
|
||||
lazy val usernameMemo = new UsernameMemo(ttl = OnlineTtl)
|
||||
|
||||
private lazy val cached = new Cached(ttl = CachedNbTtl)
|
||||
val forms = DataForm
|
||||
|
||||
def usernameOption(id: String): Fu[Option[String]] = cached username id
|
||||
|
||||
|
@ -42,6 +42,8 @@ final class Env(config: Config, db: lila.db.Env) {
|
|||
UserRepo.averageElo map { elo ⇒ "Average elo is %f" format elo }
|
||||
}
|
||||
}
|
||||
|
||||
private lazy val cached = new Cached(ttl = CachedNbTtl)
|
||||
}
|
||||
|
||||
object Env {
|
||||
|
|
|
@ -1,27 +1,31 @@
|
|||
package lila.user
|
||||
|
||||
import lila.common.LilaCookie
|
||||
import play.api.mvc.Cookie
|
||||
|
||||
final class Setting(ctx: Context) {
|
||||
|
||||
def theme = Theme(get("theme"))
|
||||
def theme(value: String) = set("theme", Theme(value).toString)
|
||||
def theme(value: String) = set("theme", Theme(value).toString)
|
||||
|
||||
def sound = get("sound", "false").parseBoolean | false
|
||||
def sound(value: String) = set("sound", value)
|
||||
def sound(value: String) = set("sound", value)
|
||||
|
||||
def chat = get("chat", "true").parseBoolean | true
|
||||
def chat(value: String) = set("chat", value)
|
||||
def chat(value: String) = set("chat", value)
|
||||
|
||||
def bg = get("bg", "light")
|
||||
def bg(value: String) = set("bg", value)
|
||||
def bg(value: String) = set("bg", value)
|
||||
|
||||
private def get(name: String, default: String = ""): String =
|
||||
ctx.req.session get name orElse {
|
||||
ctx.me flatMap (_ setting name) map (_.toString)
|
||||
} getOrElse default
|
||||
|
||||
// then, set LilaCookie.session(name, value.toString)(ctx.req)
|
||||
private def set(name: String, value: String): Funit =
|
||||
ctx.me zmap { m ⇒ UserRepo.saveSetting(m.id, name, value.toString) }
|
||||
private def set(name: String, value: String): Fu[Cookie] =
|
||||
ctx.me zmap { m ⇒
|
||||
UserRepo.saveSetting(m.id, name, value.toString)
|
||||
} inject LilaCookie.session(name, value.toString)(ctx.req)
|
||||
}
|
||||
|
||||
object Setting {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package lila.user
|
||||
|
||||
import scalaz.NonEmptyLists
|
||||
|
||||
sealed class Theme private (val name: String, val image: Boolean = false) {
|
||||
|
||||
override def toString = name
|
||||
|
@ -9,7 +7,7 @@ sealed class Theme private (val name: String, val image: Boolean = false) {
|
|||
def cssClass = name + image.fold(" txtr", "")
|
||||
}
|
||||
|
||||
object Theme extends NonEmptyLists {
|
||||
object Theme extends scalaz.NonEmptyLists {
|
||||
|
||||
val all = nel(
|
||||
"brown" -> false,
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import views._
|
||||
|
||||
object ForumCateg extends LilaController with forum.Controller {
|
||||
|
||||
private def categApi = env.forum.categApi
|
||||
private def teamCache = env.team.cached
|
||||
|
||||
val index = Open { implicit ctx ⇒
|
||||
IOk(categApi list ~ctx.me.map(teamCache.teamIds) map {
|
||||
html.forum.categ.index(_)
|
||||
})
|
||||
}
|
||||
|
||||
def show(slug: String, page: Int) = Open { implicit ctx ⇒
|
||||
CategGrantRead(slug) {
|
||||
IOptionOk(categApi.show(slug, page)) {
|
||||
case (categ, topics) ⇒ html.forum.categ.show(categ, topics)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import views._
|
||||
import site.Captcha
|
||||
import http.Context
|
||||
import http.LilaCookie
|
||||
|
||||
import play.api.data.Form
|
||||
import i18n._
|
||||
|
||||
object I18n extends LilaController {
|
||||
|
||||
private def transInfos = env.i18n.transInfos
|
||||
private def pool = env.i18n.pool
|
||||
private def translator = env.i18n.translator
|
||||
private def forms = env.i18n.forms
|
||||
private def i18nKeys = env.i18n.keys
|
||||
private def repo = env.i18n.translationRepo
|
||||
|
||||
val contribute = Open { implicit ctx ⇒
|
||||
val mines = (pool fixedReqAcceptLanguages ctx.req map { lang ⇒
|
||||
transInfos get lang
|
||||
}).toList.flatten
|
||||
Ok(html.i18n.contribute(transInfos.all, mines))
|
||||
}
|
||||
|
||||
def translationForm(lang: String) = Open { implicit ctx ⇒
|
||||
OptionOk(transInfos get lang) { info ⇒
|
||||
val (form, captcha) = forms.translationWithCaptcha
|
||||
renderTranslationForm(form, info, captcha)
|
||||
}
|
||||
}
|
||||
|
||||
def translationPost(lang: String) = OpenBody { implicit ctx ⇒
|
||||
OptionResult(transInfos get lang) { info ⇒
|
||||
implicit val req = ctx.body
|
||||
val data = forms.decodeTranslationBody
|
||||
FormIOResult(forms.translation) { form ⇒
|
||||
renderTranslationForm(form, info, forms.captchaCreate, data)
|
||||
} { metadata ⇒
|
||||
forms.process(lang, metadata, data) map { _ ⇒
|
||||
Redirect(routes.I18n.contribute).flashing("success" -> "1")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def renderTranslationForm(form: Form[_], info: TransInfo, captcha: Captcha.Challenge, data: Map[String, String] = Map.empty)(implicit ctx: Context) =
|
||||
html.i18n.translationForm(
|
||||
info,
|
||||
form,
|
||||
i18nKeys,
|
||||
pool.default,
|
||||
translator.rawTranslation(info.lang) _,
|
||||
captcha,
|
||||
data)
|
||||
|
||||
def fetch(from: Int) = Open { implicit ctx ⇒
|
||||
JsonOk((repo findFrom from map {
|
||||
_ map (_.toJson)
|
||||
}).unsafePerformIO)
|
||||
}
|
||||
|
||||
val hideCalls = Open { implicit ctx ⇒
|
||||
implicit val req = ctx.req
|
||||
val cookie = LilaCookie.cookie(
|
||||
env.i18n.hideCallsCookieName,
|
||||
"1",
|
||||
maxAge = env.i18n.hideCallsCookieMaxAge.some)
|
||||
Redirect(routes.Lobby.home()) withCookies cookie
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import views._
|
||||
|
||||
import play.api.mvc._
|
||||
import play.api.mvc.Results._
|
||||
import play.api.data._
|
||||
import play.api.data.Forms._
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.iteratee._
|
||||
import play.api.libs.concurrent.Akka
|
||||
|
||||
import scalaz.effects._
|
||||
|
||||
object Main extends LilaController {
|
||||
|
||||
private lazy val runCommand = lila.app.cli.Main.main(env) _
|
||||
|
||||
def websocket = WebSocket.async[JsValue] { implicit req ⇒
|
||||
implicit val ctx = reqToCtx(req)
|
||||
env.site.socket.join(
|
||||
uidOption = get("sri"),
|
||||
username = ctx.me map (_.username),
|
||||
flag = get("flag")
|
||||
)
|
||||
}
|
||||
|
||||
def cli = OpenBody { implicit ctx ⇒
|
||||
implicit val req = ctx.body
|
||||
IOResult {
|
||||
Form(single(
|
||||
"c" -> nonEmptyText
|
||||
)).bindFromRequest.fold(
|
||||
err ⇒ putStrLn("bad command") inject BadRequest(),
|
||||
command ⇒ for {
|
||||
_ ← putStrLn(command)
|
||||
res ← runCommand(command.split(" "))
|
||||
_ ← putStrLn(res)
|
||||
} yield Ok(res)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
def captchaCheck(id: String) = Open { implicit ctx ⇒
|
||||
Ok(env.site.captcha get id valid ~get("solution") fold (1, 0))
|
||||
}
|
||||
|
||||
def embed = Open { implicit ctx ⇒
|
||||
JsOk("""document.write("<iframe src='%s?embed=" + document.domain + "' class='lichess-iframe' allowtransparency='true' frameBorder='0' style='width: %dpx; height: %dpx;' title='Lichess free online chess'></iframe>");"""
|
||||
.format(env.settings.NetBaseUrl, getInt("w") | 820, getInt("h") | 650),
|
||||
CACHE_CONTROL -> "max-age=86400"
|
||||
)
|
||||
}
|
||||
|
||||
def developers = Open { implicit ctx ⇒
|
||||
Ok(views.html.site.developers())
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package controllers
|
||||
|
||||
import play.api.mvc._
|
||||
import play.api.libs.Comet
|
||||
import play.api.libs.concurrent._
|
||||
import play.api.libs.json._
|
||||
import akka.pattern.ask
|
||||
import scala.concurrent.duration._
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
import akka.util.Timeout
|
||||
|
||||
import lila.app._
|
||||
import socket.GetNbMembers
|
||||
import monitor._
|
||||
|
||||
object Monitor extends LilaController {
|
||||
|
||||
private def reporting = env.monitor.reporting
|
||||
private def usernameMemo = env.user.usernameMemo
|
||||
private def userRepo = env.user.userRepo
|
||||
private def gameRepo = env.game.gameRepo
|
||||
private implicit def timeout = Timeout(500 millis)
|
||||
|
||||
def index = Action {
|
||||
Ok(views.html.monitor.monitor())
|
||||
}
|
||||
|
||||
def websocket = WebSocket.async[JsValue] { implicit req ⇒
|
||||
env.monitor.socket.join(uidOption = get("sri", req))
|
||||
}
|
||||
|
||||
def status = Open { implicit ctx ⇒
|
||||
Async {
|
||||
import lila.common.Futuristic.ioToFuture
|
||||
(~get("key") match {
|
||||
case "elo" ⇒
|
||||
userRepo.idsAverageElo(usernameMemo.keys).toFuture zip
|
||||
gameRepo.recentAverageElo(5).toFuture map {
|
||||
case (users, (rated, casual)) ⇒ List(users, rated, casual) mkString " "
|
||||
}
|
||||
case "moves" ⇒ (reporting ? GetNbMoves).mapTo[Int]
|
||||
case "players" ⇒ (reporting ? GetNbMembers).mapTo[Int] map { "%d %d".format(_, usernameMemo.preciseCount) }
|
||||
case _ ⇒ (reporting ? GetStatus).mapTo[String]
|
||||
}) map { x ⇒ Ok(x.toString) }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package controllers
|
||||
|
||||
import lila.app._
|
||||
import views._
|
||||
import http.{ Context, BodyContext, Setting ⇒ HttpSetting }
|
||||
|
||||
import play.api.data.Form
|
||||
import play.api.mvc.{ Result, Cookie }
|
||||
import scalaz.effects._
|
||||
|
||||
object Setting extends LilaController {
|
||||
|
||||
private def userRepo = env.user.userRepo
|
||||
private def forms = user.DataForm
|
||||
|
||||
def set(name: String) = OpenBody { implicit ctx ⇒
|
||||
implicit val req = ctx.body
|
||||
(setters get name).fold(NotFound: Result) {
|
||||
case (form, process) ⇒
|
||||
FormResult(form) { value ⇒
|
||||
Ok() withCookies process(HttpSetting(ctx), value).unsafePerformIO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private type Setter = (Form[String], (HttpSetting, String) ⇒ IO[Cookie])
|
||||
|
||||
private lazy val setters = Map(
|
||||
"theme" -> setTheme,
|
||||
"sound" -> setSound,
|
||||
"chat" -> setChat,
|
||||
"bg" -> setBg)
|
||||
|
||||
private val setTheme: Setter = forms.theme -> {
|
||||
(setting, v) ⇒ setting.theme(v)(userRepo)
|
||||
}
|
||||
|
||||
private val setSound: Setter = forms.sound -> {
|
||||
(setting, v) ⇒ setting.sound(v)(userRepo)
|
||||
}
|
||||
|
||||
private val setChat: Setter = forms.chat -> {
|
||||
(setting, v) ⇒ setting.chat(v)(userRepo)
|
||||
}
|
||||
|
||||
private val setBg: Setter = forms.bg -> {
|
||||
(setting, v) ⇒ setting.bg(v)(userRepo)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue