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 sendActivationLink()
 {
     $userId = Input::get('user_id');
     $user = $this->userRepository->findById($userId);
     if ($user) {
         $this->service->processActivation($user);
         return Redirect::back()->with('success', trans('auth.alerts.account_activation_link_sent'));
     }
     return Redirect::back()->with('error', trans('auth.alerts.invalid_user'));
 }
 public function Map()
 {
     $this->Route('POST', '/create', function () {
         if (AuthRepository::Autherize()) {
             $request = $this->GetRequestData();
             if (isset($request->Message)) {
                 $entryOfTheDayRepository = new EntryOfTheDayRepository();
                 $entries = $entryOfTheDayRepository->Save(array("Message" => $request->Message, "UserId" => AuthRepository::GetUserId()));
                 $this->Send($entries);
             } else {
                 $this->NotFound();
             }
         }
     });
 }
 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;
     });
 }
 public static function Autherize()
 {
     $appSettings = new AppSettings();
     if ($appSettings->GetConfig()->Mode == "Debug") {
         $authHeader = getallheaders()["authorization"];
     } else {
         $authHeader = $_SERVER["REDIRECT_Authorization"];
     }
     if (isset($authHeader)) {
         $token = $authHeader;
         $rememberRepository = new RememberRepository();
         $remembers = $rememberRepository->LoadWhere("Token = '{$token}'");
         if (count($remembers) == 0) {
             header('HTTP/1.0 401 Unauthorized');
             return false;
         } else {
             self::$userId = $remembers[0]["UserId"];
             return true;
         }
     } else {
         header('HTTP/1.0 401 Unauthorized');
         return false;
     }
 }
 public function Map()
 {
     $this->Route('GET', '', function () {
         if (AuthRepository::Autherize()) {
             $todoEntryRepository = new TodoEntryRepository();
             $voteRepository = new VoteRepository();
             $entries = $todoEntryRepository->LoadAll([["CreatorUserId" => "user"], ["ProofPhotoId" => "media"]]);
             $counter = 0;
             while ($counter < count($entries)) {
                 $votes = $voteRepository->LoadWhere("TodoEntryId = " . $entries[$counter]["Id"]);
                 $voteCounter = 0;
                 $hasUserUpVoted = null;
                 if (count($votes) > 0) {
                     foreach ($votes as $vote) {
                         if ($vote["UpVote"] == "1") {
                             $voteCounter++;
                         } else {
                             $voteCounter--;
                         }
                         if ($vote["UserId"] == AuthRepository::GetUserId()) {
                             $hasUserUpVoted = $vote["UpVote"] == "1";
                         }
                     }
                 }
                 $entries[$counter]["Karma"] = $voteCounter;
                 //null = not votet
                 //true = upvoted
                 //false = downvoted
                 $entries[$counter]["HasUserUpVoted"] = $hasUserUpVoted;
                 $counter++;
             }
             $this->Send($entries);
         }
     });
     $this->Route('POST', '/delete', function () {
         $request = $this->GetRequestData();
         if (AuthRepository::Autherize()) {
             if (isset($request->entryId)) {
                 $todoEntryRepository = new TodoEntryRepository();
                 $todoEntryRepository->Delete($request->entryId);
                 $this->Send(["Status" => $todoEntryRepository->GetQueryError() == "", "Error" => $todoEntryRepository->GetQueryError()]);
             } else {
                 $this->NotFound();
             }
         }
     });
     $this->Route('POST', '/create', function () {
         $request = $this->GetRequestData();
         if (AuthRepository::Autherize()) {
             if (isset($request->Title)) {
                 $todoEntryRepository = new TodoEntryRepository();
                 $callback = $todoEntryRepository->Save(array("Title" => isset($request->Title) ? $request->Title : NULL, "Message" => isset($request->Message) ? $request->Message : NULL, "Destination" => isset($request->Destination) ? $request->Destination : NULL, "ApplicationDate" => isset($request->ApplicationDate) ? $request->ApplicationDate : NULL, "MaxPersonNumber" => isset($request->MaxPersonNumber) ? $request->MaxPersonNumber : NULL, "ProofPhotoRequired" => isset($request->ProofPhotoRequired) ? $request->ProofPhotoRequired : NULL, "Public" => isset($request->Public) ? $request->Public : NULL, "CreatorUserId" => AuthRepository::GetUserId(), "Active" => true, "Finished" => false));
                 $this->Send(["Status" => $callback != 0, "Error" => $todoEntryRepository->GetQueryError(), "Record" => $todoEntryRepository->GetById($todoEntryRepository->GetLastInsertedId(), [["CreatorUserId" => "user"], ["ProofPhotoId" => "photo"]])]);
             } else {
                 $this->NotFound();
             }
         }
     });
     $this->Route('POST', '/vote', function () {
         if (AuthRepository::Autherize()) {
             $request = $this->GetRequestData();
             if (isset($request->UpVoted) && isset($request->TodoEntryId)) {
                 $voteRepository = new VoteRepository();
                 if (count($voteRepository->LoadWhere("UserId = " . AuthRepository::GetUserId() . " AND TodoEntryId = " . $request->TodoEntryId)) > 0) {
                     $voteRepository->UpdateWhere("UserId = " . AuthRepository::GetUserId() . " AND TodoEntryId = " . $request->TodoEntryId, ["UpVote" => $request->UpVoted]);
                 } else {
                     $voteRepository->Save(["UpVote" => $request->UpVoted, "TodoEntryId" => $request->TodoEntryId, "UserId" => AuthRepository::GetUserId()]);
                 }
                 $this->Send(["Status" => $voteRepository->GetQueryError() == "", "Error" => $voteRepository->GetQueryError()]);
             } else {
                 $this->NotFound();
             }
         }
     });
     $this->Route('POST', '/finish', function () {
         if (AuthRepository::Autherize()) {
             $request = $this->GetRequestData();
             $todoEntryRepository = new TodoEntryRepository();
             if (isset($_POST["entryId"]) && isset($_FILES['file'])) {
                 $media = $_FILES['file'];
                 $entryId = $_POST["entryId"];
                 $mediaRepository = new MediaRepository();
                 $uniqid = uniqid();
                 $newMediaName = $uniqid . ".jpg";
                 $entry = $todoEntryRepository->LoadWhere("Id = {$entryId}")[0];
                 $uploadFile = false;
                 $imageRepository = new ImageRepository();
                 $exception;
                 try {
                     $imageRepository->SaveImage($media, $uniqid);
                     $uploadFile = true;
                 } catch (Exception $ex) {
                     $uploadFile = false;
                 }
                 if ($uploadFile) {
                     $mediaRepository->Save(["UploadUserId" => AuthRepository::GetUserId(), "Description" => "Bewisfoti vom Bitrag \"" . $entry["Title"] . "\"", "Destination" => $entry["Destination"] != null ? $entry["Destination"] : null, "Path" => $newMediaName]);
                     $todoEntryRepository->UpdateWhere("Id = {$entryId}", ["ProofPhotoId" => $mediaRepository->GetLastInsertedId(), "Finished" => true, "FinishedUserId" => AuthRepository::GetUserId()]);
                     $this->Send(["Status" => true]);
                 } else {
                     $this->Send(["Status" => false, "Message" => "Couldn't upload file", "Exception" => $exception]);
                 }
             } else {
                 if (isset($request->entryId)) {
                     $entryId = $request->entryId;
                     $todoEntryRepository->UpdateWhere("Id = {$entryId}", ["Finished" => true, "FinishedUserId" => AuthRepository::GetUserId()]);
                     $this->Send(["Status" => true]);
                 } else {
                     $this->NotFound();
                 }
             }
         }
     });
 }