HomeController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\Controllers;
  3. use app\Exceptions\UnauthenticatedException;
  4. use app\Types\WebhookMessage;
  5. use Pecee\SimpleRouter\SimpleRouter;
  6. use app\Interfaces\IRouteController;
  7. use app\Hajeebtok;
  8. class HomeController implements IRouteController
  9. {
  10. public static function redirect(): void {
  11. if(Hajeebtok::$Config->GetByDotKey("Instance.DebugMode")) return;
  12. response()->redirect("https://" . Hajeebtok::$Config->GetByDotKey("Instance.URL"));
  13. }
  14. public static function contact(): string {
  15. $signed_in = signed_in(request());
  16. if(!$signed_in) throw new UnauthenticatedException(0, 401);
  17. $message = input("message");
  18. $email = input("email");
  19. $name = input("name");
  20. $webhook = new WebhookMessage();
  21. $webhook->SetContent("this is ground control to major tom");
  22. $webhook->AddEmbed([
  23. "description" => $message,
  24. "fields" => [],
  25. "title" => "New message from $name",
  26. "footer" => [
  27. "text" => $email,
  28. ],
  29. "color" => 16711680 // red
  30. ]);
  31. $webhook->Send();
  32. CORSHelper();
  33. return api_json([
  34. "message" => "sent successfully. we will try to answer in less than 15 days."
  35. ]);
  36. }
  37. public static function RegisterRoutes(): void
  38. {
  39. SimpleRouter::group([
  40. "prefix" => "/",
  41. ], function () {
  42. SimpleRouter::get("/", [HomeController::class, "redirect"]);
  43. SimpleRouter::post("/contact", [HomeController::class, "contact"]);
  44. });
  45. }
  46. }