class form validation

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

View file

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

View file

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

View file

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