diff --git a/app/controllers/Team.scala b/app/controllers/Team.scala index 7a56672bff..8f3f3bbabc 100644 --- a/app/controllers/Team.scala +++ b/app/controllers/Team.scala @@ -308,7 +308,7 @@ final class Team( def requestForm(id: String) = Auth { implicit ctx => me => OptionFuOk(api.requestable(id, me)) { team => - fuccess(html.team.request.requestForm(team, forms.request)) + fuccess(html.team.request.requestForm(team, forms.request(team))) } } @@ -316,7 +316,8 @@ final class Team( AuthBody { implicit ctx => me => OptionFuResult(api.requestable(id, me)) { team => implicit val req = ctx.body - forms.request + forms + .request(team) .bindFromRequest() .fold( err => BadRequest(html.team.request.requestForm(team, err)).fuccess, diff --git a/app/views/team/request.scala b/app/views/team/request.scala index ff03cc1e47..051b74b798 100644 --- a/app/views/team/request.scala +++ b/app/views/team/request.scala @@ -31,6 +31,7 @@ object request { form3.group(form("password"), teamPassword(), help = teamPasswordDescriptionForRequester().some)( form3.input(_) ), + form3.globalError(form), p(willBeReviewed()), form3.actions( a(href := routes.Team.show(t.slug))(trans.cancel()), diff --git a/modules/team/src/main/TeamForm.scala b/modules/team/src/main/TeamForm.scala index 24dbbbd5af..055ff6fc26 100644 --- a/modules/team/src/main/TeamForm.scala +++ b/modules/team/src/main/TeamForm.scala @@ -56,12 +56,17 @@ final private[team] class TeamForm( chat = team.chat ) - val request = Form( + def request(team: Team) = Form( mapping( - "message" -> clean(text(minLength = 30, maxLength = 2000)) - )(RequestSetup.apply)(RequestSetup.unapply) + "message" -> clean(text(minLength = 30, maxLength = 2000)), + "password" -> text() + )(RequestSetup.apply)(RequestSetup.unapply).verifying( + "Wrong team password", + d => passwordMatches(d, team.password).await(2 seconds, "passwordMatches") + ) ) fill RequestSetup( - message = "Hello, I would like to join the team!" + message = "Hello, I would like to join the team!", + password = "" ) val apiRequest = Form(single("message" -> optional(clean(text(minLength = 30, maxLength = 2000))))) @@ -93,6 +98,13 @@ final private[team] class TeamForm( private def teamExists(setup: TeamSetup) = teamRepo.coll.exists($id(Team nameToId setup.trim.name)) + + private def passwordMatches(setup: RequestSetup, password: Option[String]) = { + if (password == None) fuTrue + else if (password.get == setup.password) fuTrue + else + fuFalse + } } private[team] case class TeamSetup( @@ -133,5 +145,6 @@ private[team] case class TeamEdit( } private[team] case class RequestSetup( - message: String + message: String, + password: String )