diff options
| author | Bharat Mediratta <bharat@menalto.com> | 2010-01-16 21:15:12 -0800 | 
|---|---|---|
| committer | Bharat Mediratta <bharat@menalto.com> | 2010-01-16 21:15:12 -0800 | 
| commit | 6a4dda9bdef81bcf79abe5601fd7309e593078f3 (patch) | |
| tree | 6b6dbe69481ec3f1bbb783b7ce5c843c03090180 /modules/user/models/user.php | |
| parent | a691dcc63cb6403784e061997cc85606a8f953b3 (diff) | |
Convert Admin_Users_Controller, User_Model and Group_Model to use
model based validation.
Diffstat (limited to 'modules/user/models/user.php')
| -rw-r--r-- | modules/user/models/user.php | 18 | 
1 files changed, 15 insertions, 3 deletions
| 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");      }    }  } | 
