/** * Try to Login * * @example $strong->login('username', 'password') * @param object string login * @param string password * @return boolean */ public function login($user, $password) { if (!is_object($user)) { // Load the user $user = Vaspasian_Model::factory('user', array('username' => $user)); } if (empty($password)) { return FALSE; } // Create a hashed password $password = $this->hash_password($password); if ($user->has_role('login') and $password === $user->password) { $this->complete_login($user); return TRUE; } return FALSE; }
/** * Check the role the user has * @param string integer */ public function has_role($role) { // Don't mess with these calls, they are too complex if (is_object($role)) { return parent::has_role($role); } if ($this->roles === NULL) { $this->roles = array(); if ($this->id > 0) { foreach ($this->related_roles() as $r) { // Load all the user roles $this->roles[$r['id']] = $r['name']; } } } // Make sure the role name is a string $role = (string) $role; if (ctype_digit($role)) { // Find by id return isset($this->roles[$role]); } else { // Find by name return in_array($role, $this->roles); } }