forbid tournaments to engine users

This commit is contained in:
Thibault Duplessis 2012-09-22 13:47:47 +02:00
parent 6170498e05
commit eba4c8138a
3 changed files with 32 additions and 14 deletions

View file

@ -74,6 +74,9 @@ trait LilaController
}
)
protected def NoEngine[A <: Result](a: A)(implicit ctx: Context): Result =
ctx.me.fold(_.engine, false).fold(Forbidden(views.html.site.noEngine()), a)
protected def JsonOk(map: Map[String, Any]) = Ok(toJson(map)) as JSON
protected def JsonOk(list: List[Any]) = Ok(Json generate list) as JSON

View file

@ -76,13 +76,15 @@ object Tournament extends LilaController {
version = version(tour.id),
games = games)
def join(id: String) = Auth { implicit ctx
def join(id: String) = AuthBody { implicit ctx
implicit me
IOptionIORedirect(repo createdById id) { tour
api.join(tour, me).fold(
err putStrLn(err.shows) map (_ routes.Tournament.home()),
res res map (_ routes.Tournament.show(tour.id))
)
NoEngine {
IOptionIORedirect(repo createdById id) { tour
api.join(tour, me).fold(
err putStrLn(err.shows) map (_ routes.Tournament.home()),
res res map (_ routes.Tournament.show(tour.id))
)
}
}
}
@ -124,18 +126,22 @@ object Tournament extends LilaController {
def form = Auth { implicit ctx
me
Ok(html.tournament.form(forms.create, forms))
NoEngine {
Ok(html.tournament.form(forms.create, forms))
}
}
def create = AuthBody { implicit ctx
implicit me
IOResult {
implicit val req = ctx.body
forms.create.bindFromRequest.fold(
err io(BadRequest(html.tournament.form(err, forms))),
setup api.createTournament(setup, me) map { tour
Redirect(routes.Tournament.show(tour.id))
})
NoEngine {
IOResult {
implicit val req = ctx.body
forms.create.bindFromRequest.fold(
err io(BadRequest(html.tournament.form(err, forms))),
setup api.createTournament(setup, me) map { tour
Redirect(routes.Tournament.show(tour.id))
})
}
}
}

View file

@ -0,0 +1,9 @@
@()(implicit ctx: Context)
@site.layout(
title = "No engine area") {
<div class="content_box small_box">
Sorry, engines are not allowed in this area.
</div>
}