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