Changeset 2261 for trunk/modules/auth/models/user.php
- Timestamp:
- 03/10/2008 12:18:12 AM (10 months ago)
- Files:
-
- 1 modified
-
trunk/modules/auth/models/user.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/auth/models/user.php
r1766 r2261 8 8 9 9 // User roles 10 protected $roles = array(); 11 12 public function __construct($id = FALSE) 13 { 14 parent::__construct($id); 15 16 if ($this->object->id != 0) 17 { 18 // Preload the roles, so that we can optimize has_role 19 foreach($this->find_related_roles() as $role) 20 { 21 $this->roles[$role->id] = $role->name; 22 } 23 } 24 } 10 protected $roles = NULL; 25 11 26 12 public function __get($key) 27 13 { 28 // Allow roles to be fetched as a rray(id => name)14 // Allow roles to be fetched as a simple array 29 15 if ($key === 'roles') 16 { 17 // Force the roles to load if they are empty 18 ($this->roles === NULL) and $this->has_role('login'); 19 30 20 return $this->roles; 21 } 31 22 32 23 return parent::__get($key); … … 39 30 if ($key === 'password') 40 31 { 41 if ($auth === NULL)42 {43 // Load Auth, attempting to use the controller copy44 $auth = isset(Kohana::instance()->auth) ? Kohana::instance()->auth : new Auth();45 }46 47 32 // Use Auth to hash the password 48 $value = $auth->hash_password($value);33 $value = Auth::instance()->hash_password($value); 49 34 } 50 35 … … 60 45 if (is_object($role)) 61 46 return parent::has_role($role); 47 48 if ($this->roles === NULL) 49 { 50 // Make the roles into an array. This serves a dual purpose 51 // of preventing the roles from being re-queried unnecessarily 52 // as well as optimizing has_role() calls. 53 $this->roles = array(); 54 55 if ($this->id > 0) 56 { 57 foreach($this->find_related_roles() as $r) 58 { 59 // Load all the user roles 60 $this->roles[$r->id] = $r->name; 61 } 62 } 63 } 62 64 63 65 // Make sure the role name is a string
