Example #1
0
 public static function route(\Request $request)
 {
     $method = $request->getRequestMethod();
     $req = $request->getRequestedUri();
     $routes = new \Config("routes");
     $routes = $routes->{$method};
     foreach ($routes as $url => $handler) {
         $url = preg_replace("|\\:([a-z0-9\\_\\-]+)|iu", "(?P<\$1>.*)", $url);
         if (preg_match("|{$url}|iu", $request->getRequestedUri(), $params)) {
             list($controller, $method) = explode("::", $handler);
             $request->setParams($params);
             break;
         }
     }
     if (!isset($controller)) {
         $controller = "Controller\\BadRequest";
         $method = "output404";
     }
     $controller = new $controller();
     $auth = new Authentication\Auth();
     if ($controller instanceof Controller\AbAuthController && !$auth->isLoggedIn()) {
         return array($controller, "checkLogin");
     }
     return array($controller, $method);
 }
 public function checkLogin(\Request $req, \Response $res)
 {
     //check if login is required first.
     $auth = new \Authentication\Auth();
     if (!$auth->isLoggedIn()) {
         $res->json(array("flash" => "You must login!"), "401");
     }
 }
Example #3
0
 public function login(\Request $req, \Response $res)
 {
     $auth = new \Authentication\Auth();
     $admin = $auth->Authenticate($req->username, $req->password);
     if ($admin) {
         $res->Json(array("flash" => "login successful"));
         return;
     }
     $res->Json(array("flash" => "bad username or password"), "401");
 }