Esempio n. 1
1
File: User.php Progetto: 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);
     }
 }
Esempio n. 2
0
 /**
  * modulecontroller->display();
  *
  * All Output is done via the Response Object.
  * ModelData -> View -> Response Object
  *
  * 1. getTemplateName() - get the template to render.
  * 2. getView() - gets an instance of the render engine.
  * 3. assign model data to that view object (a,b,c)
  * 5. set data to response object
  *
  * @param $templates mixed|array|string Array with keys 'layout_template' / 'content_template' and templates as values or just content template name.
  */
 public function display($templates = null)
 {
     // get the view
     $this->view = $this->getView();
     // get the view mapper
     $view_mapper = $this->view->getViewMapper();
     // set layout and content template by parameter array
     if (is_array($templates) === true) {
         if ($templates['layout_template'] !== null) {
             $view_mapper->setLayoutTemplate($templates['layout_template']);
         }
         if ($templates['content_template'] !== null) {
             $view_mapper->setTemplate($templates['content_template']);
         }
     }
     // only the "content template" is set
     if (is_string($templates)) {
         $view_mapper->setTemplate($templates);
     }
     // get the templatename
     $template = $view_mapper->getTemplateName();
     // Debug display of Layout Template and Content Template
     #Koch_Debug::firebug('Layout/Wrapper Template: ' . $this->view->getLayoutTemplate() . '<br />');
     #Koch_Debug::firebug('Template Name: ' . $templatename . '<br />');
     // render the content / template
     $content = $this->view->render($template);
     // push content to the response object
     $this->response->setContent($content);
     unset($content, $template);
 }
Esempio n. 3
0
 /**
  * Redirects to a new URL.
  * It's a proxy method using the HttpResponse Object.
  *
  * @param string $url        Redirect to this URL.
  * @param int    $time       Seconds before redirecting (for the html tag "meta refresh")
  * @param int    $statusCode Http status code, default: '303' => 'See other'
  * @param string $message    Text of redirect message.
  * @param string $mode       The redirect mode: LOCATION, REFRESH, JS, HTML.
  */
 public function redirect($url, $time = 0, $statusCode = 303, $message = null, $mode = null)
 {
     $this->response->redirect($url, $time, $statusCode, $message, $mode);
 }
Esempio n. 4
0
File: Json.php Progetto: ksst/kf
 /**
  * Render PHP data as JSON (through BODY)
  * This method returns the json encoded string.
  *
  * @param $data array
  * @param string $template
  *
  * @return $json_encoded_data
  */
 public function render($template = null, $viewdata = null)
 {
     if ($viewdata !== null) {
         $this->viewdata = $viewdata;
     }
     /*
      * Defense against MIME content-sniffing attacks. Supported by IE and Chrome only.
      * For all other browsers: escape properly or force content disposition header,
      * to open a download box on client side (as a warning).
      */
     \Koch\Http\HttpResponse::addHeader('X-Content-Type-Options', 'nosniff');
     /*
      * The MIME media type for JSON text is application/json.
      * @see http://www.ietf.org/rfc/rfc4627
      */
     \Koch\Http\HttpResponse::addHeader('Content-Type', 'application/json; charset=UTF-8');
     $json = $this->jsonEncode($this->viewdata);
     \Koch\Http\HttpResponse::addHeader('Content-Length', mb_strlen($json));
     return $json;
 }
Esempio n. 5
0
 public function testProperty_DefaultStatusIs200()
 {
     #$this->assertEquals(200, $this->response->getStatus());
     #$this->assertEqual(200, $this->response->statusCode);
     $this->assertEqual(200, HttpResponse::getStatusCode());
 }