From 01dfa2988856043a71974bc509d05c8c267f0d6e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 25 Jan 2010 20:40:44 -0800 Subject: Make some exceptions for guests: 1) They don't require email 2) Guest users aren't in the everybody group. --- modules/user/models/user.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'modules/user/models') diff --git a/modules/user/models/user.php b/modules/user/models/user.php index c43ee9a1..7c97bae7 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -67,7 +67,8 @@ class User_Model extends ORM implements User_Definition { if (!$array) { $this->rules = array( "admin" => array("callbacks" => array(array($this, "valid_admin"))), - "email" => array("rules" => array("length[1,255]", "required", "valid::email")), + "email" => array("rules" => array("length[1,255]", "valid::email"), + "callbacks" => array(array($this, "valid_email"))), "full_name" => array("rules" => array("length[0,255]")), "locale" => array("rules" => array("length[2,10]")), "name" => array("rules" => array("length[1,32]", "required"), @@ -90,7 +91,9 @@ class User_Model extends ORM implements User_Definition { if (!$this->loaded()) { // New user $this->add(group::everybody()); - $this->add(group::registered_users()); + if (!$this->guest) { + $this->add(group::registered_users()); + } parent::save(); module::event("user_created", $this); @@ -129,6 +132,10 @@ class User_Model extends ORM implements User_Definition { * Validate the password. */ public function valid_password(Validation $v, $field) { + if ($this->guest) { + return; + } + if (!$this->loaded() || $this->password_length) { $minimum_length = module::get_var("user", "mininum_password_length", 5); if ($this->password_length < $minimum_length) { @@ -145,4 +152,17 @@ class User_Model extends ORM implements User_Definition { $v->add_error("admin", "locked"); } } + + /** + * Validate the email field. + */ + public function valid_email(Validation $v, $field) { + if ($this->guest) { // guests don't require an email address + return; + } + + if (empty($this->email)) { + $v->add_error("email", "required"); + } + } } -- cgit v1.2.3