Ejemplo n.º 1
0
 /**
  * @brief Assign a user to the current session.
  *
  * @param $id The user id to assign
  */
 protected function setUser($id)
 {
     // Check if the user is active
     $u = user::getUser($id);
     if ($u == null) {
         throw new UserException("Unassociated user id / Integrity failure", UserException::ERR_USER_UNASSOCIATED);
     }
     if (!$u->active) {
         throw new UserException("User is not active, check audit log", UserException::ERR_USER_INACTIVE);
     }
     // TODO: Assign to session
     if (ModuleManager::has('lepton.mvc.session')) {
         session::set(User::KEY_USER_AUTH, $id);
     }
     if (class_exists('request')) {
         $db = new DatabaseConnection();
         $db->updateRow("UPDATE users SET lastlogin=NOW(), lastip=%s WHERE id=%d", request::getRemoteIp(), $id);
     }
     if (class_exists('UserEvents')) {
         event::invoke(UserEvents::EVENT_USER_LOGIN, array('id' => $id));
     }
 }
Ejemplo n.º 2
0
 /**
  *
  */
 static function load($module, $optional = false)
 {
     // Check if the path is globbed
     if (strpos($module, '*') == strlen($module) - 1) {
         $path = self::_mangleModulePath($module);
         Console::debugEx(LOG_EXTENDED, __CLASS__, "Looking for modules matching %s from %s", $module, $path);
         $f = glob($path);
         sort($f);
         $failed = false;
         foreach ($f as $file) {
             if (!ModuleManager::load(str_replace('*', basename($file, '.php'), $module))) {
                 $failed = true;
             }
         }
         return !$failed;
     }
     // Check if the module is already loaded
     if (ModuleManager::has($module)) {
         logger::debug("Already loaded %s.", $module);
         return true;
     }
     // Otherwise mangle the path
     $path = self::_mangleModulePath($module);
     /*
      if (file_exists(APP_PATH.$modpath)) {
      $path = APP_PATH.$modpath;
      } elseif (file_exists(SYS_PATH.$modpath)) {
      $path = SYS_PATH.$modpath;
      } else {
      $path = null;
      }
     */
     if ($path) {
         if (file_exists(basename($path, '.php') . '.class.php')) {
             $path = basename($path, '.php') . '.class.php';
         }
         if (file_exists($path)) {
             self::$_lastmodule = $module;
             Console::debugEx(LOG_BASIC, __CLASS__, "Loading %s (%s).", $module, str_replace(BASE_PATH, '', $path));
             try {
                 ModuleManager::$_modules[strtolower($module)] = array();
                 ModuleManager::$_order[] = strtolower($module);
                 // Console::debugEx(LOG_DEBUG2,__CLASS__,"  path = %s", $path);
                 require $path;
                 array_pop(ModuleManager::$_order);
             } catch (ModuleException $e) {
                 Console::debugEx(LOG_BASIC, __CLASS__, "Exception loading %s!", $module);
                 throw $e;
                 return false;
             }
             return true;
         } else {
             throw new ModuleException("Could not load module " . $module . ": Path not found");
             return false;
         }
     } else {
         Console::debugEx(LOG_BASIC, __CLASS__, "Failed to load %s.", $module);
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * @brief Return the user record of the active user
  * 
  * Returns null if no user is authenticated
  * 
  * @todo Gracefully handle situations where the session is not available
  * @return UserRecord The UserRecord of the active user
  */
 static function getActiveUser()
 {
     if (ModuleManager::has('lepton.mvc.session')) {
         $uid = session::get(User::KEY_USER_AUTH, null);
         if ($uid) {
             return user::getUser($uid);
         }
         throw new UserException("No active user", UserException::ERR_NO_ACTIVE_USER);
     }
 }