Example #1
0
 /**
  * DELETE method: Close current session.
  *
  * @param Request $request
  * @throws Exception
  * @return mixed
  */
 public function delete($request)
 {
     switch (count($request->url_elements)) {
         case 1:
             if (Common::checkAuthorization()) {
                 $session = Session::find_by_id($_SESSION['session']);
                 if ($session) {
                     $session->delete();
                     session_destroy();
                     setcookie("u", '', time() - 3600);
                     setcookie("s", '', time() - 3600);
                     return json_decode($session->to_json());
                 } else {
                     throw new Exception("Session not found.", 404);
                 }
             } else {
                 throw new Exception("Authorisation required.", 403);
             }
         default:
             throw new Exception("Unknown request.", 500);
     }
 }