Created
April 19, 2011 21:32
-
-
Save micrypt/929747 to your computer and use it in GitHub Desktop.
Validate username uniqueness (to-do: extend with test for predefined path list)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User extends MongoRecord[User] with MongoId[User] { | |
| def meta = User | |
| protected def valUnique(msg: String)(value: String): | |
| List[FieldError] = { | |
| Console.println("Not the overloaded.") | |
| Nil | |
| } | |
| object userName extends StringField(this, "") { | |
| override def validations = | |
| meta.valUnique("Username already taken.") _ :: | |
| valMinLen(6, "Username cannot be shorter than 6 characters.") _ :: super.validations | |
| } | |
| } | |
| object User extends User with MongoMetaRecord[User] { | |
| override def valUnique(msg: String)(value: String): List[FieldError] = { | |
| Console.println("Overloaded.") | |
| if (this.find("userName", value).isDefined) | |
| List(FieldError(this.userName, msg)) | |
| else | |
| Nil | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment