class form validation

pull/5938/head
Thibault Duplessis 2020-01-18 20:09:11 -06:00
parent 84b359ce7f
commit 2ad1a4c635
4 changed files with 10 additions and 11 deletions

View File

@ -134,7 +134,7 @@ final class Clas(
html.clas.student.form(
clas,
students,
env.clas.forms.student.invite,
env.clas.forms.student.invite(clas),
createForm,
created
)
@ -156,7 +156,7 @@ final class Clas(
html.clas.student.form(
clas,
students,
env.clas.forms.student.invite,
env.clas.forms.student.invite(clas),
err
)
).fuccess,
@ -174,7 +174,8 @@ final class Clas(
def studentInvite(id: String) = SecureBody(_.Teacher) { implicit ctx => me =>
WithClassAndStudents(me, id) { t => (clas, students) =>
env.clas.forms.student.invite
env.clas.forms.student
.invite(clas)
.bindFromRequest()(ctx.body)
.fold(
err =>

View File

@ -5,7 +5,7 @@ import play.api.data.Form
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.clas.{ Clas, Student }
import lila.clas.Clas
import lila.clas.ClasForm.ClasData
import controllers.routes

View File

@ -8,7 +8,6 @@ case class Clas(
name: String,
desc: String,
teachers: NonEmptyList[Teacher.Id], // first is owner
nbStudents: Int,
created: Clas.Recorded,
viewedAt: DateTime,
archived: Option[Clas.Recorded]
@ -29,7 +28,6 @@ object Clas {
name = name,
desc = desc,
teachers = NonEmptyList(teacher.id),
nbStudents = 0,
created = Recorded(teacher.id, DateTime.now),
viewedAt = DateTime.now,
archived = none

View File

@ -28,7 +28,7 @@ final class ClasForm(
object student {
def create: Form[NewStudent] =
val create: Form[NewStudent] =
Form(
mapping(
"create-username" -> securityForms.signup.username,
@ -44,12 +44,12 @@ final class ClasForm(
)
}
def invite =
def invite(c: Clas) =
Form(
mapping(
"username" -> lila.user.DataForm.historicalUsernameField.verifying("Unknown username", {
blockingFetchUser(_).isDefined
}),
"username" -> lila.user.DataForm.historicalUsernameField
.verifying("Unknown username", { blockingFetchUser(_).isDefined })
.verifying("This is a teacher", u => !c.teachers.toList.contains(u.toLowerCase)),
"realName" -> nonEmptyText
)(NewStudent.apply)(NewStudent.unapply)
)