Exemplo n.º 1
1
 /**
  * Checks if the user has a certain permission
  * Proxy Method for ACL::checkPermission()
  *
  * Two values are necessary the modulname and the name of the permission,
  * which is often the actionname.
  *
  * @param $modulename string The modulename, e.g. 'news'.
  * @param $permission string The permission name, e.g. 'action_show'.
  * @return boolean True if the user has the permission, false otherwise.
  */
 public static function hasAccess($modulename = '', $permission = '')
 {
     return Koch\ACL::checkPermission($modulename, $permission);
 }
Exemplo n.º 2
1
Arquivo: User.php Projeto: ksst/kf
 /**
  * Creates the User-Object and the $session['user'] Array.
  *
  * @param $user_id The ID of the User.
  * @param $email The email of the User.
  * @param $nick The nick of the User.
  */
 public function createUserSession($user_id = '', $email = '', $nick = '')
 {
     // Initialize the User Object
     $this->user = null;
     /*
      * Get User via DB Queries
      *
      * 1) user_id
      * 2) email
      * 3) nick
      */
     if (empty($user_id) === false) {
         // Get the user from the user_id
         $this->user = Doctrine_Query::create()->from('CsUsers u')->leftJoin('u.CsOptions o')->where('u.user_id = ?')->fetchOne([$user_id], Doctrine::HYDRATE_ARRAY);
     } elseif (empty($email) === false) {
         // Get the user from the email
         $this->user = Doctrine_Query::create()->from('CsUsers u')->leftJoin('u.CsOptions o')->where('u.email = ?')->fetchOne([$email], Doctrine::HYDRATE_ARRAY);
     } elseif (empty($nick) === false) {
         // Get the user from the nick
         $this->user = Doctrine_Query::create()->from('CsUsers u')->leftJoin('u.CsOptions o')->where('u.nick = ?')->fetchOne([$nick], Doctrine::HYDRATE_ARRAY);
     }
     /*
      * Check if this user is activated,
      * else reset cookie, session and redirect
      */
     if (is_array($this->user) and $this->user['activated'] === 0) {
         $this->logoutUser();
         // redirect
         $message = _('Your account is not yet activated.');
         \Koch\Http\HttpResponse::redirect('/account/activation_email', 5, 403, $message);
     }
     /*
      * Create $_SESSION['user'] array, containing user data
      */
     if (is_array($this->user)) {
         /*
          * Transfer User Data into Session
          */
         #\Koch\Debug\Debug::firebug($_SESSION);
         #\Koch\Debug\Debug::firebug($this->config);
         $_SESSION['user']['authed'] = 1;
         $_SESSION['user']['user_id'] = $this->user['user_id'];
         $_SESSION['user']['passwordhash'] = $this->user['passwordhash'];
         $_SESSION['user']['email'] = $this->user['email'];
         $_SESSION['user']['nick'] = $this->user['nick'];
         $_SESSION['user']['disabled'] = $this->user['disabled'];
         $_SESSION['user']['activated'] = $this->user['activated'];
         /*
          * SetLanguage
          *
          * At this position the language might already by set by
          * the language_via_get filter. the language value set via GET
          * precedes over the user config and the general config
          * the full order is
          * a) language_via_get filter
          * a) user['language'] from database / personal user setting
          * b) standard language / fallback as defined by $this->config['locale']['locale']
          */
         if (false === isset($_SESSION['user']['language_via_url'])) {
             $_SESSION['user']['language'] = false === empty($this->user['language']) ? $this->user['language'] : $this->config['locale']['default'];
         }
         /**
          * Frontend-Theme.
          *
          * first take standard theme as defined by $config->theme
          *
          * @todo remove $_REQUEST, frontend theme is selectable via frontend
          */
         if (false === isset($_REQUEST['theme'])) {
             $_SESSION['user']['frontend_theme'] = !empty($this->user['frontend_theme']) ? $this->user['frontend_theme'] : $this->config['template']['frontend_theme'];
         }
         /*
          * Backend-Theme
          */
         if (empty($this->user['backend_theme']) === false) {
             $_SESSION['user']['backend_theme'] = $this->user['backend_theme'];
         } else {
             $_SESSION['user']['backend_theme'] = $this->config['template']['backend_theme'];
         }
         /*
          * Permissions
          *
          * Get Group & Rights of user_id
          */
         /*
          User-Datensatz beinhaltet ein CsGroups-Array
          user => Array (
          [user_id] => 1
          ...
          [CsGroups] => Array (
          [0] => Array (
          [group_id] => 3
          ...
          [role_id] => 5
          )
          )
          )
         */
         // Initialize User Session Arrays
         $_SESSION['user']['group'] = '';
         $_SESSION['user']['rights'] = '';
         if (false === empty($this->user['CsGroups'])) {
             $_SESSION['user']['group'] = $this->user['CsGroups'][0]['group_id'];
             $_SESSION['user']['role'] = $this->user['CsGroups'][0]['role_id'];
             $_SESSION['user']['rights'] = Koch\ACL::createRightSession($_SESSION['user']['role'], $this->user['user_id']);
         }
         #\Koch\Debug\Debug::firebug($_SESSION);
     } else {
         // this resets the $_SESSION['user'] array
         GuestUser::instantiate();
         #Koch\Debug\Debug::printR($_SESSION);
     }
 }