diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-01-25 20:40:44 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-01-25 20:40:44 -0800 |
commit | 01dfa2988856043a71974bc509d05c8c267f0d6e (patch) | |
tree | 9ad41e21a664fd96d7a8619a10768ef549631d4d /modules | |
parent | b65baa522b20c8e8366d63cf77b3a659a3b541e1 (diff) |
Make some exceptions for guests:
1) They don't require email
2) Guest users aren't in the everybody group.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/user/models/user.php | 24 |
1 files changed, 22 insertions, 2 deletions
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"); + } + } } |