예제 #1
0
 public function testCanSetAndDestroySession()
 {
     $session = new Model\Session();
     $expectedArray = array("login" => "jh222xk");
     $session->set("login", "jh222xk");
     $this->assertEquals($expectedArray["login"], $session->get("login"));
     $session->destroy("login");
     $this->assertNull($session->get("login"));
 }
예제 #2
0
파일: Auth.php 프로젝트: jh222xk/pophub
 /**
  * Logged in action, get's the session, current user,
  * those the user follow and activity
  * @param String $accessToken
  * @return View showLoggedIn
  */
 public function loggedInUser($accessToken)
 {
     $user = $this->model->getLoggedInUser($accessToken);
     $session = new Session();
     // If we can't find the user, just destroy it.
     if ($user === null) {
         $session->destroy($this->token);
         return;
     }
     $auth = $session->get($this->token);
     $followers = $this->followers->getFollowers($user->getLogin());
     $events = null;
     // Get events
     if ($followers !== null) {
         foreach ($followers as $follower) {
             $events[] = $this->model->getUserActivity($follower["user"]);
         }
     }
     $context = array($this->view->getFollowersField() => $followers, $this->view->getUserField() => $user, $this->view->getEventField() => $events, $this->view->getAuthField() => $auth, $this->view->getSearchField() => $this->search->getSearchFieldName());
     return $this->view->showLoggedIn($context);
 }
예제 #3
0
파일: Router.php 프로젝트: jh222xk/pophub
 public function doRoute()
 {
     $klein = new Klein();
     $this->config = new Config("../app/config/app.php");
     $klein->respond("GET", $this->homePath, function () {
         $controller = new Home(new View\Home());
         $controller->index();
     });
     $klein->respond("GET", $this->loginPath . "?", function ($request, $response) {
         $url = $this->auth->index();
         $response->redirect($url);
     });
     $klein->respond("GET", "/github-callback/?", function ($request, $response) {
         if ($request->code) {
             $this->auth->getToken($request->code);
             return $response->redirect($this->userPath);
         }
         return $response->redirect($this->homePath);
     });
     $klein->respond("GET", $this->userPath . "?", function ($request, $response) {
         $session = new Session();
         $token = $session->get($this->auth->getTokenSessionName());
         if ($token) {
             return $this->auth->loggedInUser($token);
         }
         return $response->redirect($this->homePath);
     });
     $klein->respond("GET", $this->logoutPath . "?", function ($request, $response) {
         $session = new Session();
         $session->destroy($this->auth->getTokenSessionName());
         return $response->redirect($this->homePath);
     });
     $klein->with($this->usersPath, function () use($klein) {
         $klein->respond("GET", "/?", function ($request, $response) {
             $controller = new Users();
             $controller->index($request->fetchFromID);
         });
         $klein->respond("GET", "/[:username]/?", function ($request, $response) {
             $controller = new Users();
             $controller->show($request->username);
         });
     });
     $klein->respond("GET", $this->searchPath . "?", function ($request, $response) {
         $controller = new Users();
         $controller->search();
     });
     $klein->respond("GET", $this->followPath . "[:username]/?", function ($request, $response) {
         $controller = new Users();
         $controller->follow($request->username);
     });
     $klein->respond("GET", $this->unFollowPath . "[:username]/?", function ($request, $response) {
         $controller = new Users();
         $controller->unFollow($request->username);
     });
     $klein->respond("404", function ($request) {
         $page = $request->uri();
         $controller = new Error(new View\Error());
         $controller->pageNotFoundError($page);
     });
     $klein->onError(function ($klein, $err_msg) {
         if ($this->config->get("DEBUG") === true) {
             throw new \Exception($err_msg);
         } else {
             $controller = new Error(new View\Error());
             $controller->serverError();
             error_log($err_msg, 3, $this->config->get("ERROR_LOG"));
         }
     });
     $klein->dispatch();
 }