public function Map()
 {
     $this->Route('GET', '', function () {
         if (AuthRepository::Autherize()) {
             $mediaRepository = new MediaRepository();
             $this->Send($mediaRepository->LoadAll([["UploadUserId" => "user"]]));
         }
     });
     $this->Route('GET', '/[i:id]', function ($id) {
         $mediaRepository = new MediaRepository();
         $media = $mediaRepository->LoadWhere("Id = {$id}")[0];
         $path = "images/gallery/full/" . $media["Path"];
         $imageRepository = new ImageRepository();
         $imageRepository->CacheImage($path);
         header("Content-Type: image/" . pathinfo($path)["extension"]);
         header("Content-Length: " . filesize($path));
         $fp = fopen($path, 'rb');
         fpassthru($fp);
         exit;
     });
     $this->Route('GET', '/[i:id]/thumbnail', function ($id) {
         $mediaRepository = new MediaRepository();
         $media = $mediaRepository->LoadWhere("Id = {$id}")[0];
         $path = "images/gallery/thumbnail/" . $media["Path"];
         $imageRepository = new ImageRepository();
         $imageRepository->CacheImage($path);
         header("Content-Type: image/" . pathinfo($path)["extension"]);
         header("Content-Length: " . filesize($path));
         $fp = fopen($path, 'rb');
         fpassthru($fp);
         exit;
     });
 }
 public function Map()
 {
     $this->Route('POST', '/login', function () {
         $request = $this->GetRequestData();
         if (isset($request->username) && isset($request->password)) {
             $authCallback = AuthRepository::Login($request->username, $request->password);
             if ($authCallback != false) {
                 $this->Send($authCallback);
             } else {
                 $this->Unauthorized();
             }
         } else {
             $this->NotFound();
         }
     });
     $this->Route('POST', '/changepassword', function () {
         $request = $this->GetRequestData();
         if (isset($request->oldPassword) && isset($request->newPassword)) {
             if (AuthRepository::Autherize()) {
                 $this->Send(["Status" => AuthRepository::ChangePassword($request->oldPassword, $request->newPassword)]);
             }
         } else {
             $this->NotFound();
         }
     });
     $this->Route('GET', '/[i:id]/profilepicture', function ($id) {
         $userRepository = new UserRepository();
         $user = $userRepository->LoadWhere("Id = {$id}")[0];
         $img = imagecreatefromjpeg("images/profilepictures/" . $user["Profilepicture"]);
         $imageRepository = new ImageRepository();
         $imageRepository->CacheImage("images/profilepictures/" . $user["Profilepicture"]);
         header("Content-Type: image/jpg");
         imagejpeg($img);
         imagedestroy($img);
         exit;
     });
 }