parent
321f41c391
commit
71d2cdf46a
|
@ -19,20 +19,16 @@ object OAuthToken extends LilaController {
|
|||
}
|
||||
|
||||
def create = Auth { implicit ctx => me =>
|
||||
lila.user.UserRepo.isBot(me) map { isBot =>
|
||||
Ok(html.oAuth.token.create(env.forms.token.create(isBot)))
|
||||
}
|
||||
Ok(html.oAuth.token.create(env.forms.token.create)).fuccess
|
||||
}
|
||||
|
||||
def createApply = AuthBody { implicit ctx => me =>
|
||||
implicit val req = ctx.body
|
||||
lila.user.UserRepo.isBot(me) flatMap { isBot =>
|
||||
env.forms.token.create(isBot).bindFromRequest.fold(
|
||||
err => BadRequest(html.oAuth.token.create(err)).fuccess,
|
||||
setup => env.tokenApi.create(setup make me) inject
|
||||
Redirect(routes.OAuthToken.index)
|
||||
)
|
||||
}
|
||||
env.forms.token.create.bindFromRequest.fold(
|
||||
err => BadRequest(html.oAuth.token.create(err)).fuccess,
|
||||
setup => env.tokenApi.create(setup make me) inject
|
||||
Redirect(routes.OAuthToken.index)
|
||||
)
|
||||
}
|
||||
|
||||
def delete(id: String) = Auth { implicit ctx => me =>
|
||||
|
|
|
@ -7,20 +7,17 @@ import play.api.data.validation.Constraints._
|
|||
|
||||
object OAuthForm {
|
||||
|
||||
private def scopesField(isBot: Boolean) = list(nonEmptyText.verifying { scope =>
|
||||
OAuthScope.byKey get scope exists {
|
||||
case OAuthScope.Bot.Play => isBot
|
||||
case _ => true
|
||||
}
|
||||
})
|
||||
private val scopesField = list(nonEmptyText.verifying(OAuthScope.byKey.contains _))
|
||||
|
||||
object token {
|
||||
|
||||
def create(isBot: Boolean) = Form(mapping(
|
||||
val form = Form(mapping(
|
||||
"description" -> nonEmptyText(minLength = 3, maxLength = 140),
|
||||
"scopes" -> scopesField(isBot)
|
||||
"scopes" -> scopesField
|
||||
)(Data.apply)(Data.unapply))
|
||||
|
||||
def create = form
|
||||
|
||||
case class Data(
|
||||
description: String,
|
||||
scopes: List[String]
|
||||
|
|
Loading…
Reference in New Issue