<?php
namespace App\Controller;
use App\Entity\Admin;
use App\Entity\Payment;
use App\Entity\Subscription;
use App\Enum\Payment\Type;
use App\Enum\Site\Domain;
use App\Enum\Site\Lang;
use App\Form\Type\LoginType;
use App\Library\Utils\FrontLinks;
use App\Security\FormAuthenticator;
use App\Service\Ads\AdsService;
use App\Service\Image\ImageService;
use App\Service\Mail\MailService;
use App\Service\Mail\SubscriptionMailService;
use App\Service\Payment\PaymentService;
use App\Service\SendLog\SendLogService;
use App\Service\User\UserRatingService;
use App\Service\User\UserService;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Core\Security;
class MainController extends AbstractController
{
public function index(Request $request, Security $security, UserService $userService, ImageService $imageService)
{
if (!$security->getUser()) {
return $this->redirectToRoute('login');
}
/** @var Admin $admin */
$admin = $security->getUser()->getAssociatedUser();
if ($admin->getDomain() && $admin->getDomain() != $request->getLocale()) {
return $this->redirectToRoute('main', ['_locale' => $admin->getDomain()]);
}
$params = $userService->getDomainStatParams($request->getLocale());
return $this->render('main.html.twig', $params);
}
public function login(Request $request, Security $security, MailService $mailService)
{
if ($security->getUser()) {
// return $this->redirectToRoute('main');
return new RedirectResponse('/');
}
$code = $request->get('code', '');
if (in_array($code, ['code', 'tapak'])) {
$codeTxt = rand(100000, 999999);
$request->getSession()->set(FormAuthenticator::CODE_CACHE_KEY . $request->getClientIp(), $codeTxt);
if ($code == 'code') {
$email = 'jevgeniya.yan@gmail.com';
} else {
/** @var Admin $admin */
$admin = $this->getDoctrine()->getManager()->getRepository(Admin::class)->findOneBy(['username' => $code]);
if (!$admin || !$admin instanceof Admin) {
throw new \Exception('Error');
}
$email = $admin->getEmail();
$code = 'code';
}
$mailService->sendMail($email, 'Auth code', $codeTxt, Domain::GRIBU_LV);
}
$admin = new Admin();
$loginForm = $this->createForm(LoginType::class, $admin);
$error = $request->getSession()->get(Security::AUTHENTICATION_ERROR);
if ($error) {
$request->getSession()->set(Security::AUTHENTICATION_ERROR, null);
}
return $this->render('login.html.twig', [
'login_form' => $loginForm->createView(),
'error' => $error,
'code' => $code,
]);
}
public function logout()
{
//
}
public function lastLog(int $id, Security $security, SendLogService $sendLogService, Request $request)
{
if (!$security->getUser()) {
return $this->redirectToRoute('login');
}
if ($id) {
return $this->render('last_log.html.twig', [
'log' => $sendLogService->get($id)
]);
}
return $this->render('last_logs.html.twig', [
'logs' => $sendLogService->getAll($request->getLocale(), $request->get('email', null)),
]);
}
public function testAction(MailService $mailService, AdsService $adsService, SubscriptionMailService $subscriptionMailService, UserService $userService, EntityManagerInterface $em, UserRatingService $userRatingService)
{
// $userRatingService->checkRatingDateUser();
// $user = $userService->get(3564);
// $userService->userRatingEnd($user);
// $this->addFlash('success', 'User rating end');
// return new RedirectResponse('/');
// $ads = $adsService->get(323781);
// $mailService->priorityEndMessage($ads->getEmail(), $ads);
// $lang = Domain::getFirstLang($domain);
$user = $userService->get(199596);
$subscriptionPayment = $em->getRepository(Payment::class)->findOneBy(['id' => 551]);
$invoiceNum = '199596-28-buy-user-rating-172854613';
$invoiceFilename = '199596_199596-28-buy-user-rating-172854613-01-48_1728546135';
$userSubscription = $em->getRepository(Subscription::class)->findOneBy(['id' => 64]);
$userRating = $userSubscription->getRating();
// $user = $userService->get(3565);
// $subscriptionPayment = $em->getRepository(Payment::class)->findOneBy(['id' => 16219]);
// $invoiceNum = '3565-26-buy-user-rating-1728480681';
// $invoiceFilename = '3565_3565-26-buy-user-rating-1728480681-01-47_1728480684';
// $userSubscription = $em->getRepository(Subscription::class)->findOneBy(['id' => 47]);
// $userRating = $userSubscription->getRating();
$subscriptionMailService->approveEmail($user, $subscriptionPayment, $userRating, $invoiceFilename, $invoiceNum);
sleep(1);
$subscriptionMailService->invoice($user, $subscriptionPayment, $userRating, $invoiceFilename, $invoiceNum);
sleep(1);
$subscriptionMailService->notify7Days($user, $userRating);
sleep(1);
$subscriptionMailService->cardExpiresSoon($user);
sleep(1);
$subscriptionMailService->cardInvalid($user);
sleep(1);
$subscriptionMailService->termsChange($user);
sleep(1);
$subscriptionMailService->cardProcessingIssue($user);
return new RedirectResponse('/');
/** 1 message approve email */
// $lang = Lang::LANG_EN;
// $domain = Domain::KLUB_SE;
// $domainName = Domain::changeStringCaseByDomain($domain);
//
// switch ($lang) {
// case Lang::LANG_EN:
// default:
// $subject = "Welcome to VIP membership: All about your benefits";
// }
//
// return $this->render('/email/subscription/' . $lang . '/approve_email.html.twig', [
//// 'name' => $user->getUsername(),
// 'domainName' => $domainName,
// 'domain' => $domain,
// 'color' => Domain::getColorForEmailByDomain($domain),
//
// 'faqLink' => FrontLinks::faq($domain, $lang),
// 'aboutVipLink' => FrontLinks::memberAccount($domain, $lang),
// 'changeSubscriptionInfoLink' => FrontLinks::memberAccount($domain, $lang),
// 'changePaymentInfoLink' => FrontLinks::accountSettings($domain, $lang),
// 'cancelSubscriptionInfoLink' => FrontLinks::terms($domain, $lang),
// 'helpLink' => FrontLinks::contacts($domain, $lang)
// ]);
/** 2 message invoice (after successful payment) */
// $lang = Lang::LANG_EN;
// $domain = Domain::KLUB_SE;
// $domainName = Domain::changeStringCaseByDomain($domain);
//
// switch ($lang) {
// case Lang::LANG_EN:
// default:
// $subject = "Congratulations. Payment successful";
// }
//
// return $this->render('/email/subscription/' . $lang . '/invoice.html.twig', [
// 'domainName' => $domainName,
// 'domain' => $domain,
// 'color' => Domain::getColorForEmailByDomain($domain),
// 'faqLink' => FrontLinks::faq($domain, $lang),
// 'currentSubscriptionPlanLink' => FrontLinks::accountSettings($domain, $lang),
// 'changeSubscriptionInfoLink' => FrontLinks::memberAccount($domain, $lang),
// 'changePaymentInfoLink' => FrontLinks::accountSettings($domain, $lang),
// 'cancelSubscriptionInfoLink' => FrontLinks::terms($domain, $lang),
// 'helpLink' => FrontLinks::contacts($domain, $lang)
// ]);
/** 3 message 7 days notification */
// $lang = Lang::LANG_EN;
// $domain = Domain::KLUB_SE;
// $domainName = Domain::changeStringCaseByDomain($domain);
//
// switch ($lang) {
// case Lang::LANG_EN:
// default:
// $subject = "Important Information About Upcoming Charges to Your Account";
// }
//
// return $this->render('/email/subscription/' . $lang . '/7_days_notification.html.twig', [
// 'domainName' => $domainName,
// 'domain' => $domain,
// 'color' => Domain::getColorForEmailByDomain($domain),
// 'faqLink' => FrontLinks::faq($domain, $lang),
// 'currentSubscriptionPlanLink' => FrontLinks::accountSettings($domain, $lang),
// 'changeSubscriptionInfoLink' => FrontLinks::memberAccount($domain, $lang),
// 'changePaymentInfoLink' => FrontLinks::accountSettings($domain, $lang),
// 'cancelSubscriptionInfoLink' => FrontLinks::terms($domain, $lang),
// 'helpLink' => FrontLinks::contacts($domain, $lang)
// ]);
/** 4 card expires soon */
// $lang = Lang::LANG_EN;
// $domain = Domain::KLUB_SE;
// $domainName = Domain::changeStringCaseByDomain($domain);
//
// switch ($lang) {
// case Lang::LANG_EN:
// default:
// $subject = "Credit card expired reminder";
// }
//
// return $this->render('/email/subscription/' . $lang . '/card_expires_soon.html.twig', [
// 'domainName' => $domainName,
// 'domain' => $domain,
// 'color' => Domain::getColorForEmailByDomain($domain),
// 'faqLink' => FrontLinks::faq($domain, $lang),
// 'helpLink' => FrontLinks::contacts($domain, $lang)
// ]);
/** 5 card invalid */
// $lang = Lang::LANG_EN;
// $domain = Domain::KLUB_SE;
// $domainName = Domain::changeStringCaseByDomain($domain);
//
// switch ($lang) {
// case Lang::LANG_EN:
// default:
// $subject = "Update your payment method";
// }
//
// return $this->render('/email/subscription/' . $lang . '/card_invalid.html.twig', [
// 'domainName' => $domainName,
// 'domain' => $domain,
// 'color' => Domain::getColorForEmailByDomain($domain),
// 'faqLink' => FrontLinks::faq($domain, $lang),
// 'helpLink' => FrontLinks::contacts($domain, $lang)
// ]);
/** 6 terms changes */
// $lang = Lang::LANG_EN;
// $domain = Domain::KLUB_SE;
// $domainName = Domain::changeStringCaseByDomain($domain);
//
// switch ($lang) {
// case Lang::LANG_EN:
// default:
// $subject = "Update your payment method";
// }
//
// return $this->render('/email/subscription/' . $lang . '/terms_changes.html.twig', [
// 'domainName' => $domainName,
// 'domain' => $domain,
// 'color' => Domain::getColorForEmailByDomain($domain),
// 'faqLink' => FrontLinks::faq($domain, $lang),
// 'helpLink' => FrontLinks::contacts($domain, $lang),
// 'termsLink' => FrontLinks::terms($domain, $lang)
// ]);
}
}