<commit_before>package views.html.oAuth.token

import play.api.data.Form

import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._

import controllers.routes

object create {

  def apply(form: Form[lila.oauth.OAuthForm.token.Data], me: lila.user.User)(implicit ctx: Context) = {

    val title = "New personal API access token"

    views.html.account.layout(title = title, active = "oauth.token")(
      div(cls := "account oauth box box-pad")(
        h1(title),
        postForm(cls := "form3", action := routes.OAuthToken.create())(
          div(cls := "form-group")(
            "Personal access tokens function like ordinary Lichess OAuth access tokens. ",
            "They can be used to authenticate to the API over Basic Authentication."
          ),
          form3.group(
            form("description"),
            raw("Token description"),
            help = raw("For you to remember what this token is for").some
          )(form3.input(_)(autofocus)),
          br,
          br,
          h2("Scopes define the access for personal tokens:"),
          div(cls := "scopes")(
            lila.oauth.OAuthScope.all.map { scope =>
              val disabled = {
                me.noBot && scope == lila.oauth.OAuthScope.Bot.Play && me.count.game > 0
              } || {
                me.isBot && scope == lila.oauth.OAuthScope.Board.Play
              }
              val id = s"oauth-scope-${scope.key.replace(":", "_")}"
              div(
                span(
                  form3.cmnToggle(
                    id,
                    s"${form("scopes").name}[]",
                    value = scope.key,
                    checked = form.value.exists(_.scopes.contains(scope.key)),
                    disabled = disabled
                  )
                ),
                label(`for` := id, st.title := disabled.option("You already have played games!"))(scope.name)
              )
            }
          ),
          form3.actions(
            a(href := routes.OAuthToken.index())("Cancel"),
            form3.submit(trans.apply())
          )
        )
      )
    )
  }
}<commit_msg>mention pre-filling on the oauth token form<commit_after>package views.html.oAuth.token

import controllers.routes
import play.api.data.Form

import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._

object create {

  def apply(form: Form[lila.oauth.OAuthForm.token.Data], me: lila.user.User)(implicit ctx: Context) = {

    val title = "New personal API access token"

    views.html.account.layout(title = title, active = "oauth.token")(
      div(cls := "account oauth box box-pad")(
        h1(title),
        postForm(cls := "form3", action := routes.OAuthToken.create())(
          div(cls := "form-group")(
            "Personal access tokens function like ordinary Lichess OAuth access tokens. ",
            "They can be used to authenticate to the API over Basic Authentication."
          ),
          form3.group(
            form("description"),
            raw("Token description"),
            help = raw("For you to remember what this token is for").some
          )(form3.input(_)(autofocus)),
          br,
          br,
          h2("Scopes define the access for personal tokens:"),
          div(cls := "scopes")(
            lila.oauth.OAuthScope.all.map { scope =>
              val disabled = {
                me.noBot && scope == lila.oauth.OAuthScope.Bot.Play && me.count.game > 0
              } || {
                me.isBot && scope == lila.oauth.OAuthScope.Board.Play
              }
              val id = s"oauth-scope-${scope.key.replace(":", "_")}"
              div(
                span(
                  form3.cmnToggle(
                    id,
                    s"${form("scopes").name}[]",
                    value = scope.key,
                    checked = form.value.exists(_.scopes.contains(scope.key)),
                    disabled = disabled
                  )
                ),
                label(`for` := id, st.title := disabled.option("You already have played games!"))(scope.name)
              )
            }
          ),
          form3.actions(
            a(href := routes.OAuthToken.index())("Cancel"),
            form3.submit(trans.apply())
          ),
          br,
          div {
            val url =
              s"${netBaseUrl}${routes.OAuthToken.create()}?scopes[]=challenge:write&scopes[]=puzzle:read&description=Prefilled+token+example"
            frag(
              h2("Note for the attention of developers only:"),
              p(
                "It is possible to pre-fill this form by tweaking the query parameters of the URL.",
                br,
                "For example: ",
                a(href := url)(url),
                br,
                "ticks the challenge:create and puzzle:read permissions, and sets the token description.",
                br,
                "The permission codes can be found in the HTML code of the form.",
                br,
                "Giving these pre-filled URLs to your users will help them get the right token permissions."
              )
            )
          }
        )
      )
    )
  }
}
{'fraction_non_alphanumeric': 0.12097542389026482, 'fraction_numerical': 0.003619737092779577, 'mean_word_length': 1.5862068965517242, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5880322', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1417, 'n_words': 342}