team names can't contain "lichess"

pull/9538/head
Thibault Duplessis 2021-08-06 11:11:06 +02:00
parent 974ec1d99b
commit 0cb6b4e0be
2 changed files with 12 additions and 9 deletions

View File

@ -90,8 +90,6 @@ object Form {
object eventName {
private val blockList = List("lichess", "liсhess") // it's not a 'c'.
def apply(minLength: Int, maxLength: Int, verifiedUser: Boolean) =
cleanText.verifying(
Constraints minLength minLength,
@ -100,15 +98,20 @@ object Form {
regex = """[\p{L}\p{N}-\s:.,;'\+]+""".r,
error = "Invalid characters; only letters, numbers, and common punctuation marks are accepted."
),
Constraint[String] { (t: String) =>
if (blockList.exists(t.toLowerCase.contains) && !verifiedUser)
V.Invalid(V.ValidationError("Must not contain \"lichess\""))
else V.Valid
}
mustNotContainLichess(verifiedUser)
)
}
object mustNotContainLichess {
private val blockList = List("lichess", "liсhess") // it's not a 'c'.
def apply(verifiedUser: Boolean) = Constraint[String] { (t: String) =>
if (blockList.exists(t.toLowerCase.contains) && !verifiedUser)
V.Invalid(V.ValidationError("Must not contain \"lichess\""))
else V.Valid
}
}
def stringIn(choices: Options[String]) =
text.verifying(mustBeOneOf(choices.map(_._1)), hasKey(choices, _))

View File

@ -4,7 +4,7 @@ import play.api.data._
import play.api.data.Forms._
import scala.concurrent.duration._
import lila.common.Form.{ cleanNonEmptyText, cleanText, numberIn }
import lila.common.Form.{ cleanNonEmptyText, cleanText, mustNotContainLichess, numberIn }
import lila.db.dsl._
final private[team] class TeamForm(
@ -15,7 +15,7 @@ final private[team] class TeamForm(
extends lila.hub.CaptchedForm {
private object Fields {
val name = "name" -> cleanText(minLength = 3, maxLength = 60)
val name = "name" -> cleanText(minLength = 3, maxLength = 60).verifying(mustNotContainLichess(false))
val location = "location" -> optional(cleanText(minLength = 3, maxLength = 80))
val password = "password" -> optional(cleanText(maxLength = 60))
def passwordCheck(team: Team) = "password" -> optional(text).verifying(