コード例 #1
0
ファイル: Blog.php プロジェクト: jbeyer1984/ownFramework
 public function show()
 {
     // login/show switch with session
     if (!$this->components->get('session')->isLoggedIn()) {
         HTTP::redirect('blog/login');
     }
     //user is logged in
     //    Components::getInstance()->get('logger')->log('$_SESSION', $_SESSION);
     $db = $this->components->get('db');
     $sql = "select nick, prename, aftername from User";
     //    $dump = print_r($sql, true);
     //    error_log("\n" . '-$- in ' . __FILE__ . ':' . __LINE__ . ' in ' . __METHOD__ . "\n" . '*** $sql ***' . "\n = " . $dump);
     $resultUser = $db->execute($sql)->getData();
     $user = UserFactory::getInstance()->retCreatedUser($_SESSION['id_user']);
     $resultMessagesOwn = $user->getRepository()->getMessages();
     $messageRepo = new MessageRepository();
     $resultMessagesAll = $messageRepo->getAllMessagesWithNick();
     $resultMessagesByNick = $this->packMessagesByNick($resultMessagesAll);
     //    Components::getInstance()->get('logger')->log('$resultMessage', $resultMessagesOwn);
     $template = 'Blog/' . strtolower(__FUNCTION__) . '/' . strtolower(__FUNCTION__);
     $serverRequestMethod = HTTP::getMethod();
     //    Components::getInstance()->get('logger')->log('$serverRequestMethod', $serverRequestMethod);
     if ('post' == $serverRequestMethod || isset($_GET['ajax'])) {
         $template .= '_rendered.twig';
     } else {
         $template .= '.twig';
     }
     echo $this->components->get('view')->render($template, array('users' => $resultUser, 'messagesOwn' => $resultMessagesOwn, 'messagesAllByNick' => $resultMessagesByNick, 'templateContext' => 'show'));
 }
コード例 #2
0
ファイル: Session.php プロジェクト: jbeyer1984/ownFramework
 public function isLoggedIn()
 {
     if (PHP_SESSION_NONE == session_status()) {
         //      Components::getInstance()->get('logger')->log('"session will start"', "true");
         session_start();
     }
     if (!isset($_SESSION['id_user'])) {
         return false;
     }
     $user = UserFactory::getInstance()->retCreatedUser($_SESSION['id_user']);
     $logout = !isset($_SESSION['id_user']) || !isset($_SESSION['password']) || $_SESSION['password'] != hash('sha512', $user->getPassword() . $this->salt);
     if ($logout) {
         //      if (isset($_COOKIE[session_name()])) {
         setcookie(session_name(), "", time() - 3600, "/");
         //clear session from globals
         $_SESSION = array();
         //clear session from disk
         session_destroy();
         return false;
     }
     return true;
 }