From 6a4dda9bdef81bcf79abe5601fd7309e593078f3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 16 Jan 2010 21:15:12 -0800 Subject: Convert Admin_Users_Controller, User_Model and Group_Model to use model based validation. --- modules/user/models/user.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'modules/user/models/user.php') diff --git a/modules/user/models/user.php b/modules/user/models/user.php index 12da5784..c45f88ac 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -78,6 +78,7 @@ class User_Model extends ORM implements User_Definition { } $this->rules["password"]["callbacks"] = array(array($this, "valid_password")); + $this->rules["admin"]["callbacks"] = array(array($this, "valid_admin")); parent::validate($array); } @@ -131,9 +132,20 @@ class User_Model extends ORM implements User_Definition { * Validate the password. */ public function valid_password(Validation $v, $field) { - $minimum_length = module::get_var("user", "mininum_password_length", 5); - if ($this->password_length < $minimum_length || $this->password_length > 40) { - $v->add_error("password", "length"); + if (!$this->loaded() || $this->password_length) { + $minimum_length = module::get_var("user", "mininum_password_length", 5); + if ($this->password_length < $minimum_length || $this->password_length > 40) { + $v->add_error("password", "length"); + } + } + } + + /** + * Validate the admin bit. + */ + public function valid_admin(Validation $v, $field) { + if ($this->id == identity::active_user()->id && !$this->admin) { + $v->add_error("admin", "locked"); } } } -- cgit v1.2.3