src/Controller/MainController.php line 132

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Bot\TelegramBot;
  4. use App\Entity\{UserUserProfile};
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  12. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  13. use Symfony\Contracts\Cache\CacheInterface;
  14. class MainController extends AbstractController{
  15.     /**
  16.      * @Route("/dev/graphqlVoyager/", name="_dev_graphqlVoyager")
  17.      */
  18.     public function devGraphqlVoyagerAction(){
  19.         return $this->render('graphqlVoyager.html.twig');
  20.     }
  21.     /**
  22.      * @Route("/dev/graphiql/", name="_dev_graphiql")
  23.      */
  24.     public function devGraphiqlAction(Request $request){
  25.         return $this->render('graphiql.html.twig');
  26.     }
  27.     /**
  28.      * @Route("/s93imo2ZN23N1/", name="_tb", methods={"POST"})
  29.      */
  30.     public function main(
  31.         Request $request,
  32.         CacheInterface $cache
  33.     ){
  34.         $tb = new TelegramBot(
  35.             '5159671633:AAFPSK-izXwORNJySA7UyDmO2u6oYl3S_3M',
  36.             $cache
  37.         );
  38.         $tb->setNotFoundRoute(function($data$chatId) use($tb){
  39.             $tb->messageSend($chatId'Незнаю такой команды. попробуй сначала /start');
  40.             return 'start';
  41.         });
  42.         $tb->addRoute('start', function($data$chatId$userName) use($tb){
  43.             $tb->messageSend(
  44.                 $chatId,
  45.                 'Привет, '.$userName.', бот позволит оформить подписку на следующие сервисы:',
  46.                 ['inline_keyboard' => [
  47.                     [['text' => 'Spotify''callback_data' => 'spotify']],
  48.                     //['text' => 'Apple One', 'callback_data' => 'spotify'],
  49.                     //['text' => 'Google One', 'callback_data' => 'spotify'],
  50.                 ]]
  51.             );
  52.             return 'start';
  53.         });
  54.         $tb->addRoute('spotify', function($data$chatId) use($tb){
  55.             $tb->addUserData($chatId'service''Spotify');
  56.             $tb->messageSend($chatId'Доступны следующие подписки для Spotify:',
  57.                 ['inline_keyboard' => [
  58.                     [['text' => 'Отмена''callback_data' => 'start']],
  59.                     [['text' => '1 месяц - 100 RUB''callback_data' => 'spotify1']],
  60.                     [['text' => '3 месяц - 300 RUB''callback_data' => 'spotify3']],
  61.                     [['text' => '6 месяц - 600 RUB''callback_data' => 'spotify6']],
  62.                 ]]
  63.             );
  64.             return 'start';
  65.         });
  66.         $tb->addRoute('spotify1', function($data$chatId) use($tb){
  67.             $tb->addUserData($chatId'month'1);
  68.             $tb->messageSend($chatId'Выбрана подписка: Spotify 1 месяц'.PHP_EOL.'Напиши логин от сервиса');
  69.             return 'spotifyLogin';
  70.         });
  71.         $tb->addRoute('spotify3', function($data$chatId) use($tb){
  72.             $tb->addUserData($chatId'month'3);
  73.             $tb->messageSend($chatId'Выбрана подписка: Spotify 3 месяц'.PHP_EOL.'Напиши логин от сервиса');
  74.             return 'spotifyLogin';
  75.         });
  76.         $tb->addRoute('spotify6', function($data$chatId) use($tb){
  77.             $tb->addUserData($chatId'month'6);
  78.             $tb->messageSend($chatId'Выбрана подписка: Spotify 6 месяц'.PHP_EOL.'Напиши логин от сервиса');
  79.             return 'spotifyLogin';
  80.         });
  81.         $tb->addRoute('spotifyLogin', function($data$chatId) use($tb){
  82.             $tb->addUserData($chatId'login'$data->message->text);
  83.             $tb->messageSend($chatId'Напиши пароль от сервиса Spotify');
  84.             return 'spotifyConfirm';
  85.         });
  86.         $tb->addRoute('spotifyConfirm', function($data$chatId) use($tb){
  87.             $tb->addUserData($chatId'pass'$data->message->text);
  88.             $userData $tb->getUserData($chatId);
  89.             $tb->messageSend(
  90.                 $chatId,
  91.                 'Подтвердите данные:'.PHP_EOL.
  92.                 'Сервис: '.$userData['service'].PHP_EOL.
  93.                 'Подписка: '.$userData['month'].PHP_EOL.
  94.                 'Логин: '.$userData['login'].PHP_EOL.
  95.                 'Пароль: '.$userData['pass'].PHP_EOL,
  96.                 ['inline_keyboard' => [
  97.                     [['text' => 'Отмена''callback_data' => 'start']],
  98.                     [['text' => 'Подтвердить''callback_data' => 'spotifyRequest']]
  99.                 ]]
  100.             );
  101.             return 'start';
  102.         });
  103.         $tb->addRoute('spotifyRequest', function($data$chatId) use($tb){
  104.             $userData $tb->getUserData($chatId);
  105.             $tb->deleteUserData($chatId);
  106.             $tb->messageSend(190319499$userData['login'].' - '.$userData['pass']);
  107.             $tb->messageSend($chatId'Заявка оформлена.'.PHP_EOL.'Мы сообщим тебе когда подписка будет совершена!');
  108.             return 'start';
  109.         });
  110.         $tb->run($request);
  111.         return $this->json([]);
  112.     }
  113.     /**
  114.      * @Route("/", name="_main")
  115.      * @Route("/schedule")
  116.      * @Route("/appointment")
  117.      */
  118.     public function mainAction(
  119.         Request $request,
  120.         EntityManagerInterface $em){
  121.         if(!is_object($this->getUser())) {
  122.             $user $em->getRepository(User::class)->findOneBy(['id' => $this->getUser()->getId()]);
  123.             $this->get('security.token_storage')->setToken(new UsernamePasswordToken(
  124.                 $user,
  125.                 $user->getPassword('1234'),
  126.                 'secured_area',
  127.                 $user->getRoles()
  128.             ));
  129.         }
  130.         throw new NotFoundHttpException();
  131.         return new Response(file_get_contents($_SERVER['DOCUMENT_ROOT'].'/index.html'));
  132.     }
  133.     /**
  134.      * @Route("/panel/", name="_panel")
  135.      * @Route("/panel/{path<.+>}", name="_panel_all")
  136.      */
  137.     public function frontAction(Request $requestEntityManagerInterface $em){
  138.         return new Response(file_get_contents($_SERVER['DOCUMENT_ROOT'].'/panel/index.html'));
  139.     }
  140.     /**
  141.      * @Route("/reg/", name="_reg")
  142.      */
  143.     public function regAction(
  144.         Request $request,
  145.         EntityManagerInterface $em,
  146.         UserPasswordEncoderInterface $passwordEncoder){
  147.         $us = [
  148.             'Сокотухина',
  149.             'Якубова',
  150.             'Чербняк',
  151.             'Фаткуллина',
  152.             'Хабибуллина',
  153.             'Хафизова',
  154.             'Голованова',
  155.             'Иванова',
  156.             'Петрова',
  157.         ];
  158.         foreach($us as $u){
  159.             $userProfile = new UserProfile();
  160.             $userProfile->setFirstName('Ира');
  161.             $userProfile->setLastName($u);
  162.             $userProfile->setSecondName('Разумеева');
  163.             $user = new User();
  164.             $user->setUsername($userProfile->getName());
  165.             $user->setPhone('891234567890');
  166.             $user->setPassword($passwordEncoder->encodePassword($user'1234'));
  167.             $em->persist($user);
  168.             $em->flush();
  169.             $userProfile->setUser($user);
  170.             $em->persist($userProfile);
  171.             $em->flush();
  172.         }
  173.         /*
  174.         $user = new User();
  175.         $user->setType(User::TYPE_ADMIN);
  176.         $user->setUsername("Андрей А. М.");
  177.         $user->setPhone(81234567890);
  178.         $user->setPassword($passwordEncoder->encodePassword($user, '1234'));
  179.         $em->persist($user);
  180.         $em->flush();
  181.         */
  182.         return $this->render('main.html.twig', [
  183.         ]);
  184.     }
  185.     /**
  186.      * @Route("/wstest/", name="_wstest")
  187.      */
  188.     public function wstestAction(Request $request){
  189.         return $this->render('wstest.html.twig', [
  190.         ]);
  191.     }
  192. }