src/Controller/MainController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Admin;
  4. use App\Entity\Payment;
  5. use App\Entity\Subscription;
  6. use App\Enum\Payment\Type;
  7. use App\Enum\Site\Domain;
  8. use App\Enum\Site\Lang;
  9. use App\Form\Type\LoginType;
  10. use App\Library\Utils\FrontLinks;
  11. use App\Security\FormAuthenticator;
  12. use App\Service\Ads\AdsService;
  13. use App\Service\Image\ImageService;
  14. use App\Service\Mail\MailService;
  15. use App\Service\Mail\SubscriptionMailService;
  16. use App\Service\Payment\PaymentService;
  17. use App\Service\SendLog\SendLogService;
  18. use App\Service\User\UserRatingService;
  19. use App\Service\User\UserService;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use Psr\Log\LoggerInterface;
  22. use Symfony\Component\HttpFoundation\RedirectResponse;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  25. use Symfony\Component\Security\Core\Security;
  26. class MainController extends AbstractController
  27. {
  28.     public function index(Request $requestSecurity $securityUserService $userServiceImageService $imageService)
  29.     {
  30.         if (!$security->getUser()) {
  31.             return $this->redirectToRoute('login');
  32.         }
  33.         /** @var Admin $admin */
  34.         $admin $security->getUser()->getAssociatedUser();
  35.         if ($admin->getDomain() && $admin->getDomain() != $request->getLocale()) {
  36.             return $this->redirectToRoute('main', ['_locale' => $admin->getDomain()]);
  37.         }
  38.         $params $userService->getDomainStatParams($request->getLocale());
  39.         return $this->render('main.html.twig'$params);
  40.     }
  41.     public function login(Request $requestSecurity $securityMailService $mailService)
  42.     {
  43.         if ($security->getUser()) {
  44. //            return $this->redirectToRoute('main');
  45.             return new RedirectResponse('/');
  46.         }
  47.         $code $request->get('code''');
  48.         if (in_array($code, ['code''tapak'])) {
  49.             $codeTxt rand(100000999999);
  50.             $request->getSession()->set(FormAuthenticator::CODE_CACHE_KEY $request->getClientIp(), $codeTxt);
  51.             if ($code == 'code') {
  52.                 $email 'jevgeniya.yan@gmail.com';
  53.             } else {
  54.                 /** @var Admin $admin */
  55.                 $admin $this->getDoctrine()->getManager()->getRepository(Admin::class)->findOneBy(['username' => $code]);
  56.                 if (!$admin || !$admin instanceof Admin) {
  57.                     throw new \Exception('Error');
  58.                 }
  59.                 $email $admin->getEmail();
  60.                 $code 'code';
  61.             }
  62.             $mailService->sendMail($email'Auth code'$codeTxtDomain::GRIBU_LV);
  63.         }
  64.         $admin = new Admin();
  65.         $loginForm $this->createForm(LoginType::class, $admin);
  66.         $error $request->getSession()->get(Security::AUTHENTICATION_ERROR);
  67.         if ($error) {
  68.             $request->getSession()->set(Security::AUTHENTICATION_ERRORnull);
  69.         }
  70.         return $this->render('login.html.twig', [
  71.             'login_form' => $loginForm->createView(),
  72.             'error' => $error,
  73.             'code' => $code,
  74.         ]);
  75.     }
  76.     public function logout()
  77.     {
  78.         //
  79.     }
  80.     public function lastLog(int $idSecurity $securitySendLogService $sendLogServiceRequest $request)
  81.     {
  82.         if (!$security->getUser()) {
  83.             return $this->redirectToRoute('login');
  84.         }
  85.         if ($id) {
  86.             return $this->render('last_log.html.twig', [
  87.                 'log' => $sendLogService->get($id)
  88.             ]);
  89.         }
  90.         return $this->render('last_logs.html.twig', [
  91.             'logs' => $sendLogService->getAll($request->getLocale(), $request->get('email'null)),
  92.         ]);
  93.     }
  94.     public function testAction(MailService $mailServiceAdsService $adsServiceSubscriptionMailService $subscriptionMailServiceUserService $userServiceEntityManagerInterface $emUserRatingService $userRatingService)
  95.     {
  96. //        $userRatingService->checkRatingDateUser();
  97. //        $user = $userService->get(3564);
  98. //        $userService->userRatingEnd($user);
  99. //        $this->addFlash('success', 'User rating end');
  100. //        return new RedirectResponse('/');
  101. //        $ads = $adsService->get(323781);
  102. //        $mailService->priorityEndMessage($ads->getEmail(), $ads);
  103. //        $lang = Domain::getFirstLang($domain);
  104.         $user $userService->get(199596);
  105.         $subscriptionPayment $em->getRepository(Payment::class)->findOneBy(['id' => 551]);
  106.         $invoiceNum '199596-28-buy-user-rating-172854613';
  107.         $invoiceFilename '199596_199596-28-buy-user-rating-172854613-01-48_1728546135';
  108.         $userSubscription $em->getRepository(Subscription::class)->findOneBy(['id' => 64]);
  109.         $userRating $userSubscription->getRating();
  110. //        $user = $userService->get(3565);
  111. //        $subscriptionPayment = $em->getRepository(Payment::class)->findOneBy(['id' => 16219]);
  112. //        $invoiceNum = '3565-26-buy-user-rating-1728480681';
  113. //        $invoiceFilename = '3565_3565-26-buy-user-rating-1728480681-01-47_1728480684';
  114. //        $userSubscription = $em->getRepository(Subscription::class)->findOneBy(['id' => 47]);
  115. //        $userRating = $userSubscription->getRating();
  116.         $subscriptionMailService->approveEmail($user$subscriptionPayment$userRating$invoiceFilename$invoiceNum);
  117.         sleep(1);
  118.         $subscriptionMailService->invoice($user$subscriptionPayment$userRating$invoiceFilename$invoiceNum);
  119.         sleep(1);
  120.         $subscriptionMailService->notify7Days($user$userRating);
  121.         sleep(1);
  122.         $subscriptionMailService->cardExpiresSoon($user);
  123.         sleep(1);
  124.         $subscriptionMailService->cardInvalid($user);
  125.         sleep(1);
  126.         $subscriptionMailService->termsChange($user);
  127.         sleep(1);
  128.         $subscriptionMailService->cardProcessingIssue($user);
  129.         return new RedirectResponse('/');
  130.         /** 1 message approve email */
  131. //        $lang = Lang::LANG_EN;
  132. //        $domain = Domain::KLUB_SE;
  133. //        $domainName = Domain::changeStringCaseByDomain($domain);
  134. //
  135. //        switch ($lang) {
  136. //            case Lang::LANG_EN:
  137. //            default:
  138. //                $subject = "Welcome to VIP membership: All about your benefits";
  139. //        }
  140. //
  141. //        return  $this->render('/email/subscription/' . $lang . '/approve_email.html.twig', [
  142. ////            'name' => $user->getUsername(),
  143. //            'domainName' => $domainName,
  144. //            'domain' => $domain,
  145. //            'color' => Domain::getColorForEmailByDomain($domain),
  146. //
  147. //            'faqLink' => FrontLinks::faq($domain, $lang),
  148. //            'aboutVipLink' => FrontLinks::memberAccount($domain, $lang),
  149. //            'changeSubscriptionInfoLink' => FrontLinks::memberAccount($domain, $lang),
  150. //            'changePaymentInfoLink' => FrontLinks::accountSettings($domain, $lang),
  151. //            'cancelSubscriptionInfoLink' => FrontLinks::terms($domain, $lang),
  152. //            'helpLink' => FrontLinks::contacts($domain, $lang)
  153. //        ]);
  154.         /** 2 message invoice (after successful payment) */
  155. //        $lang = Lang::LANG_EN;
  156. //        $domain = Domain::KLUB_SE;
  157. //        $domainName = Domain::changeStringCaseByDomain($domain);
  158. //
  159. //        switch ($lang) {
  160. //            case Lang::LANG_EN:
  161. //            default:
  162. //                $subject = "Congratulations. Payment successful";
  163. //        }
  164. //
  165. //        return  $this->render('/email/subscription/' . $lang . '/invoice.html.twig', [
  166. //            'domainName' => $domainName,
  167. //            'domain' => $domain,
  168. //            'color' => Domain::getColorForEmailByDomain($domain),
  169. //            'faqLink' => FrontLinks::faq($domain, $lang),
  170. //            'currentSubscriptionPlanLink' => FrontLinks::accountSettings($domain, $lang),
  171. //            'changeSubscriptionInfoLink' => FrontLinks::memberAccount($domain, $lang),
  172. //            'changePaymentInfoLink' => FrontLinks::accountSettings($domain, $lang),
  173. //            'cancelSubscriptionInfoLink' => FrontLinks::terms($domain, $lang),
  174. //            'helpLink' => FrontLinks::contacts($domain, $lang)
  175. //        ]);
  176.         /** 3 message 7 days notification */
  177. //        $lang = Lang::LANG_EN;
  178. //        $domain = Domain::KLUB_SE;
  179. //        $domainName = Domain::changeStringCaseByDomain($domain);
  180. //
  181. //        switch ($lang) {
  182. //            case Lang::LANG_EN:
  183. //            default:
  184. //                $subject = "Important Information About Upcoming Charges to Your Account";
  185. //        }
  186. //
  187. //        return  $this->render('/email/subscription/' . $lang . '/7_days_notification.html.twig', [
  188. //            'domainName' => $domainName,
  189. //            'domain' => $domain,
  190. //            'color' => Domain::getColorForEmailByDomain($domain),
  191. //            'faqLink' => FrontLinks::faq($domain, $lang),
  192. //            'currentSubscriptionPlanLink' => FrontLinks::accountSettings($domain, $lang),
  193. //            'changeSubscriptionInfoLink' => FrontLinks::memberAccount($domain, $lang),
  194. //            'changePaymentInfoLink' => FrontLinks::accountSettings($domain, $lang),
  195. //            'cancelSubscriptionInfoLink' => FrontLinks::terms($domain, $lang),
  196. //            'helpLink' => FrontLinks::contacts($domain, $lang)
  197. //        ]);
  198.         /** 4 card expires soon */
  199. //        $lang = Lang::LANG_EN;
  200. //        $domain = Domain::KLUB_SE;
  201. //        $domainName = Domain::changeStringCaseByDomain($domain);
  202. //
  203. //        switch ($lang) {
  204. //            case Lang::LANG_EN:
  205. //            default:
  206. //                $subject = "Credit card expired reminder";
  207. //        }
  208. //
  209. //        return  $this->render('/email/subscription/' . $lang . '/card_expires_soon.html.twig', [
  210. //            'domainName' => $domainName,
  211. //            'domain' => $domain,
  212. //            'color' => Domain::getColorForEmailByDomain($domain),
  213. //            'faqLink' => FrontLinks::faq($domain, $lang),
  214. //            'helpLink' => FrontLinks::contacts($domain, $lang)
  215. //        ]);
  216.         /** 5 card invalid */
  217. //        $lang = Lang::LANG_EN;
  218. //        $domain = Domain::KLUB_SE;
  219. //        $domainName = Domain::changeStringCaseByDomain($domain);
  220. //
  221. //        switch ($lang) {
  222. //            case Lang::LANG_EN:
  223. //            default:
  224. //                $subject = "Update your payment method";
  225. //        }
  226. //
  227. //        return  $this->render('/email/subscription/' . $lang . '/card_invalid.html.twig', [
  228. //            'domainName' => $domainName,
  229. //            'domain' => $domain,
  230. //            'color' => Domain::getColorForEmailByDomain($domain),
  231. //            'faqLink' => FrontLinks::faq($domain, $lang),
  232. //            'helpLink' => FrontLinks::contacts($domain, $lang)
  233. //        ]);
  234.         /** 6 terms changes */
  235. //        $lang = Lang::LANG_EN;
  236. //        $domain = Domain::KLUB_SE;
  237. //        $domainName = Domain::changeStringCaseByDomain($domain);
  238. //
  239. //        switch ($lang) {
  240. //            case Lang::LANG_EN:
  241. //            default:
  242. //                $subject = "Update your payment method";
  243. //        }
  244. //
  245. //        return  $this->render('/email/subscription/' . $lang . '/terms_changes.html.twig', [
  246. //            'domainName' => $domainName,
  247. //            'domain' => $domain,
  248. //            'color' => Domain::getColorForEmailByDomain($domain),
  249. //            'faqLink' => FrontLinks::faq($domain, $lang),
  250. //            'helpLink' => FrontLinks::contacts($domain, $lang),
  251. //            'termsLink' => FrontLinks::terms($domain, $lang)
  252. //        ]);
  253.     }
  254. }