2018-03-09 14:55:11 -07:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import lila.app._
|
|
|
|
import lila.oauth.AccessToken
|
|
|
|
import views._
|
|
|
|
|
2019-12-04 16:39:16 -07:00
|
|
|
final class OAuthToken(env: Env) extends LilaController(env) {
|
2018-03-09 14:55:11 -07:00
|
|
|
|
2019-12-04 18:47:46 -07:00
|
|
|
private val tokenApi = env.oAuth.tokenApi
|
2018-03-09 14:55:11 -07:00
|
|
|
|
|
|
|
def index = Auth { implicit ctx => me =>
|
2019-12-04 18:47:46 -07:00
|
|
|
tokenApi.list(me) map { tokens =>
|
2018-03-31 22:57:57 -06:00
|
|
|
Ok(html.oAuth.token.index(tokens))
|
2018-03-09 14:55:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def create = Auth { implicit ctx => me =>
|
2019-12-04 18:47:46 -07:00
|
|
|
Ok(html.oAuth.token.create(env.oAuth.forms.token.create, me)).fuccess
|
2018-03-09 14:55:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
def createApply = AuthBody { implicit ctx => me =>
|
|
|
|
implicit val req = ctx.body
|
2019-12-04 18:47:46 -07:00
|
|
|
env.oAuth.forms.token.create.bindFromRequest.fold(
|
2018-04-16 07:36:31 -06:00
|
|
|
err => BadRequest(html.oAuth.token.create(err, me)).fuccess,
|
2019-12-04 18:47:46 -07:00
|
|
|
setup => tokenApi.create(setup make me) inject
|
2018-04-15 18:18:55 -06:00
|
|
|
Redirect(routes.OAuthToken.index)
|
|
|
|
)
|
2018-03-09 14:55:11 -07:00
|
|
|
}
|
|
|
|
|
2019-12-04 18:47:46 -07:00
|
|
|
def delete(id: String) = Auth { _ => me =>
|
|
|
|
tokenApi.deleteBy(AccessToken.Id(id), me) inject
|
2018-03-09 14:55:11 -07:00
|
|
|
Redirect(routes.OAuthToken.index)
|
|
|
|
}
|
|
|
|
}
|