Kohana_Auth_ORM::logged_in PHP Method

logged_in() public method

Checks if a session is active.
public logged_in ( $role = NULL, $all_required = TRUE ) : boolean
return boolean
    public function logged_in($role = NULL, $all_required = TRUE)
    {
        $status = FALSE;
        // Get the user from the session
        $user = $this->get_user();
        if (is_object($user) and $user instanceof Model_User and $user->loaded()) {
            // Everything is okay so far
            $status = TRUE;
            if (!empty($role)) {
                // Multiple roles to check
                if (is_array($role)) {
                    // set initial status
                    $status = (bool) $all_required;
                    // Check each role
                    foreach ($role as $_role) {
                        if (!is_object($_role)) {
                            $_role = ORM::factory('role', array('name' => $_role));
                        }
                        // If the user doesn't have the role
                        if (!$user->has('roles', $_role)) {
                            // Set the status false and get outta here
                            $status = FALSE;
                            if ($all_required) {
                                break;
                            }
                        } elseif (!$all_required) {
                            $status = TRUE;
                            break;
                        }
                    }
                } else {
                    if (!is_object($role)) {
                        // Load the role
                        $role = ORM::factory('role', array('name' => $role));
                    }
                    // Check that the user has the given role
                    $status = $user->has('roles', $role);
                }
            }
        }
        return $status;
    }

Usage Example

Example #1
0
 public function logged_in($role = NULL)
 {
     $settings = Kohana_Config::instance()->load("mmdb");
     if (!empty($settings->localMachine)) {
         return parent::logged_in($role);
     }
     if (parent::logged_in($role)) {
         $user = $this->get_user();
         if (!empty($user->kids_id)) {
             $kidsUser = Helper_Mmdb::getSessionUser();
             if (!$kidsUser || $kidsUser->id != $user->kids_id) {
                 $this->logout();
                 return false;
             }
             return true;
         }
     } else {
         return false;
     }
 }
All Usage Examples Of Kohana_Auth_ORM::logged_in