HomeController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controllers;
  4. use App\Services\Auth;
  5. use App\Utils\Telegram\Process;
  6. use Exception;
  7. use Psr\Http\Message\ResponseInterface;
  8. use Slim\Http\Response;
  9. use Slim\Http\ServerRequest;
  10. use Telegram\Bot\Exceptions\TelegramSDKException;
  11. /**
  12. * HomeController
  13. */
  14. final class HomeController extends BaseController
  15. {
  16. /**
  17. * @throws Exception
  18. */
  19. public function index(ServerRequest $request, Response $response, array $args): ResponseInterface
  20. {
  21. return $response->write($this->view()->fetch('index.tpl'));
  22. }
  23. /**
  24. * @throws Exception
  25. */
  26. public function tos(ServerRequest $request, Response $response, array $args): ResponseInterface
  27. {
  28. return $response->write($this->view()->fetch('tos.tpl'));
  29. }
  30. /**
  31. * @throws Exception
  32. */
  33. public function staff(ServerRequest $request, Response $response, array $args): ResponseInterface
  34. {
  35. $user = Auth::getUser();
  36. if (! $user->isLogin) {
  37. return $response->withStatus(404)->write($this->view()->fetch('404.tpl'));
  38. }
  39. return $response->write($this->view()->fetch('staff.tpl'));
  40. }
  41. /**
  42. * @throws TelegramSDKException
  43. */
  44. public function telegram(ServerRequest $request, Response $response, array $args): ResponseInterface
  45. {
  46. $token = $request->getQueryParam('token');
  47. if ($_ENV['enable_telegram'] && $token === $_ENV['telegram_request_token']) {
  48. Process::index();
  49. $result = '1';
  50. } else {
  51. $result = '0';
  52. }
  53. return $response->write($result);
  54. }
  55. }