From ad0e7254eb6e6a763c9b4d0a7252dc5982a814be Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 14 May 2010 16:19:53 -0700 Subject: Require a well-formed email address for all comments. --- modules/comment/models/comment.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'modules/comment/models') diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index 48084340..fb70c79a 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -61,7 +61,7 @@ class Comment_Model extends ORM { if (!$array) { $this->rules = array( "guest_name" => array("callbacks" => array(array($this, "valid_author"))), - "guest_email" => array("rules" => array("email")), + "guest_email" => array("callbacks" => array(array($this, "valid_email"))), "guest_url" => array("rules" => array("url")), "item_id" => array("callbacks" => array(array($this, "valid_item"))), "state" => array("rules" => array("Comment_Model::valid_state")), @@ -144,6 +144,19 @@ class Comment_Model extends ORM { } } + /** + * Make sure that the email address is legal. + */ + public function valid_email(Validation $v, $field) { + if ($this->author_id == identity::guest()->id) { + if (empty($v->guest_email)) { + $v->add_error("guest_email", "required"); + } else if (!valid::email($v->guest_email)) { + $v->add_error("guest_email", "invalid"); + } + } + } + /** * Make sure we have a valid associated item id. */ -- cgit v1.2.3