123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\Controllers;
- use app\Exceptions\UnauthenticatedException;
- use app\Types\WebhookMessage;
- use Pecee\SimpleRouter\SimpleRouter;
- use app\Interfaces\IRouteController;
- use app\Hajeebtok;
- class HomeController implements IRouteController
- {
- public static function redirect(): void {
- if(Hajeebtok::$Config->GetByDotKey("Instance.DebugMode")) return;
- response()->redirect("https://" . Hajeebtok::$Config->GetByDotKey("Instance.URL"));
- }
- public static function contact(): string {
- $signed_in = signed_in(request());
- if(!$signed_in) throw new UnauthenticatedException(0, 401);
- $message = input("message");
- $email = input("email");
- $name = input("name");
- $webhook = new WebhookMessage();
- $webhook->SetContent("this is ground control to major tom");
- $webhook->AddEmbed([
- "description" => $message,
- "fields" => [],
- "title" => "New message from $name",
- "footer" => [
- "text" => $email,
- ],
- "color" => 16711680 // red
- ]);
- $webhook->Send();
- CORSHelper();
- return api_json([
- "message" => "sent successfully. we will try to answer in less than 15 days."
- ]);
- }
- public static function RegisterRoutes(): void
- {
- SimpleRouter::group([
- "prefix" => "/",
- ], function () {
- SimpleRouter::get("/", [HomeController::class, "redirect"]);
- SimpleRouter::post("/contact", [HomeController::class, "contact"]);
- });
- }
- }
|