src/Controller/UserController.php line 827

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\File\UploadedFile;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  11. use Doctrine\ODM\MongoDB\DocumentManager;
  12. use App\Document\User;
  13. use App\Document\Wallet;
  14. use App\Document\Bank;
  15. use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
  16. use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
  17. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  18. use Symfony\Contracts\Translation\TranslatorInterface;
  19. use Symfony\Contracts\HttpClient\HttpClientInterface;
  20. use App\Document\Order ;
  21. use App\Document\MarketOrder ;
  22. use Symfony\Component\String\Slugger\SluggerInterface;
  23. class UserController extends AbstractController
  24. {
  25.  
  26.     private $translator;
  27.     
  28.     private  $slug
  29.     private $client;
  30.     private $doctrine;
  31.     private $slugger;
  32.     private $logger;
  33.     private $doc ;
  34.       
  35.     public function __construct(TranslatorInterface $translator   HttpClientInterface $client ,  DocumentManager $doctrine  SluggerInterface $slugger )
  36.     {
  37.        
  38.         $this->translator $translator ;
  39.         $this->client $client ;
  40.         $this->doc $doctrine ;
  41.         
  42.         $this->slug $slugger ;
  43.         
  44.       
  45.        
  46.     }
  47.     #[Route('/api/admin/users',methods: ['POST'], name'admin_get_users')]
  48.     public function AdminGetUsers(DocumentManager  $doctrine Request $request): JsonResponse
  49.     {
  50.         $users $doctrine->createQueryBuilder(User::class)
  51.         ->field('roles')->in(['ROLE_USER'])
  52.         ->hydrate(false)
  53.         ->getQuery()
  54.         ->execute()
  55.         ->toArray();
  56.         
  57.         
  58. $persianMonthsCount array_fill(1120); // Initialize counts for each Persian month
  59. foreach ($users as $user) {
  60.     // Check if 'registerDate' exists and is valid
  61.     if (!isset($user['registerdate']) || !is_numeric($user['registerdate'])) {
  62.         continue; // Skip invalid dates
  63.     }
  64.     
  65.     $registerDate = (new \DateTime())->setTimestamp($user['registerdate']);
  66.     $gregorianMonth = (int) $registerDate->format('m'); // Get Gregorian month
  67.     // Determine the corresponding Persian month based on the Gregorian month and day
  68.     $dayOfMonth = (int) $registerDate->format('d');
  69.     $persianMonth 0;
  70.     // Mapping Gregorian month ranges to Persian months
  71.     if ($gregorianMonth === && $dayOfMonth >= 21 || $gregorianMonth === && $dayOfMonth <= 20) {
  72.         $persianMonth 1// Farvardin
  73.     } elseif ($gregorianMonth === && $dayOfMonth >= 21 || $gregorianMonth === && $dayOfMonth <= 20) {
  74.         $persianMonth 2// Ordibehesht
  75.     } elseif ($gregorianMonth === && $dayOfMonth >= 21 || $gregorianMonth === && $dayOfMonth <= 20) {
  76.         $persianMonth 3// Khordad
  77.     } elseif ($gregorianMonth === && $dayOfMonth >= 21 || $gregorianMonth === && $dayOfMonth <= 22) {
  78.         $persianMonth 4// Tir
  79.     } elseif ($gregorianMonth === && $dayOfMonth >= 23 || $gregorianMonth === && $dayOfMonth <= 22) {
  80.         $persianMonth 5// Mordad
  81.     } elseif ($gregorianMonth === && $dayOfMonth >= 23 || $gregorianMonth === && $dayOfMonth <= 22) {
  82.         $persianMonth 6// Shahrivar
  83.     } elseif ($gregorianMonth === && $dayOfMonth >= 23 || $gregorianMonth === 10 && $dayOfMonth <= 22) {
  84.         $persianMonth 7// Mehr
  85.     } elseif ($gregorianMonth === 10 && $dayOfMonth >= 23 || $gregorianMonth === 11 && $dayOfMonth <= 21) {
  86.         $persianMonth 8// Aban
  87.     } elseif ($gregorianMonth === 11 && $dayOfMonth >= 22 || $gregorianMonth === 12 && $dayOfMonth <= 21) {
  88.         $persianMonth 9// Azar
  89.     } elseif ($gregorianMonth === 12 && $dayOfMonth >= 22 || $gregorianMonth === && $dayOfMonth <= 20) {
  90.         $persianMonth 10// Dey
  91.     } elseif ($gregorianMonth === && $dayOfMonth >= 21 || $gregorianMonth === && $dayOfMonth <= 19) {
  92.         $persianMonth 11// Bahman
  93.     } elseif ($gregorianMonth === && $dayOfMonth >= 20 || $gregorianMonth === && $dayOfMonth <= 20) {
  94.         $persianMonth 12// Esfand
  95.     }
  96.     // Increment the count for the identified Persian month
  97.     if ($persianMonth 0) {
  98.         $persianMonthsCount[$persianMonth]++;
  99.     }
  100. }
  101.         $res = ["status" => "200" "msg" => "admin get users" "users" =>$users  "regcount" => array_values($persianMonthsCount) ];
  102.         return new JsonResponse($res); 
  103.     }
  104.     
  105.      #[Route('/api/admin/kyc_location',methods: ['POST'], name'admin_kyc_location')]
  106.     public function AdminKycLocation(DocumentManager  $doctrine Request $request): JsonResponse
  107.     {
  108.         
  109.         $data =  json_decode($request->getContent(), false);
  110.         $user_id $data[0]->id  ;
  111.         
  112.         $user $doctrine->getRepository(User::class)->findOneBy(['id' => $user_id]);
  113.         
  114.         $kyc_address_status $user->getKycaddress();
  115.         
  116.         
  117.         if(is_null($kyc_address_status) || $kyc_address_status != true ) {
  118.             
  119.             $user->setKycaddress(true);
  120.             $user->setLevel('3');
  121.         } else {
  122.             $user->setKycaddress(false);
  123.            
  124.         }
  125.         
  126.         
  127.         
  128.         
  129.         $doctrine->persist($user);
  130.         $doctrine->flush();
  131.         
  132.         $res = ["status" => "200" "msg" => "location status changed" 'test' => $kyc_address_status ];
  133.         return new JsonResponse($res); 
  134.         
  135.     }
  136.     
  137.       #[Route('/api/admin/getuser',methods: ['POST'], name'admin_get_user')]
  138.     public function AdminGetUser(DocumentManager  $doctrine Request $request): JsonResponse
  139.     {
  140.         $data =  json_decode($request->getContent(), false);
  141.         $user_id $data[0]->id  ;
  142.         $user $doctrine->createQueryBuilder(User::class)
  143.         ->field('id')->equals($user_id)
  144.         ->hydrate(false)
  145.         ->getQuery()
  146.         ->execute()
  147.         ->toArray();
  148.         
  149.         
  150.          $cards $doctrine->createQueryBuilder(Bank::class)
  151.         ->field('user')->equals($user_id)
  152.         ->hydrate(false)
  153.         ->getQuery()
  154.         ->execute()
  155.         ->toArray();
  156.         
  157.         
  158.          $market_order $doctrine->createQueryBuilder(MarketOrder::class)
  159.         ->field('userid')->equals($user_id)
  160.         ->hydrate(false)
  161.         ->getQuery()
  162.         ->execute()
  163.         ->toArray();
  164.          $otc_order $doctrine->createQueryBuilder(Order::class)
  165.         ->field('userid')->equals($user_id)
  166.         ->hydrate(false)
  167.         ->getQuery()
  168.         ->execute()
  169.         ->toArray();
  170.        
  171.         $res = ["status" => "200" "msg" => "admin get user" "user" => $user "cards" => $cards "market" => $market_order "otc" => $otc_order];
  172.         return new JsonResponse($res); 
  173.     }
  174.     
  175.     
  176.     #[Route('/api/admin/updatestatus',methods: ['POST'], name'update_status')]
  177.     public function updatestatus(DocumentManager  $doctrine Request $request ): JsonResponse
  178.     {
  179.         $data =  json_decode($request->getContent(), false);
  180.         $user_id $data->id ;
  181.         $user_exist $doctrine->getRepository(User::class)->findOneBy(['id' => $user_id]);
  182.        $live_status $user_exist->getStatus();
  183.    
  184.        if($live_status === "1") {
  185.         $status ;
  186.        } else {
  187.         $status ;
  188.        }
  189.         $user_exist->setStatus($status);
  190.         $doctrine->persist($user_exist);
  191.         $doctrine->flush();
  192.         $res = ["status" => "200" "msg" => "Profile Updated"] ;
  193.         return new JsonResponse($res);
  194.     }
  195.     #[Route('/api/passwordresetrequest',methods: ['POST'], name'password_reset_request')]
  196.     public function passwordresetrequest(DocumentManager  $doctrine Request $request): JsonResponse
  197.     {
  198.         
  199.         $data =  json_decode($request->getContent(), false);
  200.         $mobile $data->mobile ;
  201.         $user $doctrine->getRepository(User::class)->findOneBy(['username' => $mobile]);
  202.         $otp random_int(1000099999);
  203.         $otptime date('H:i:s \O\n d/m/Y');
  204.         if($user) {
  205.             $finduser $doctrine->createQueryBuilder(User::class)
  206.             ->findAndUpdate()
  207.             ->field('id')->equals($user->getId())
  208.             ->sort('priority''desc')
  209.             ->field('otp')->set($otp)
  210.             ->field('otptime')->set($otptime)
  211.             ->getQuery()
  212.             ->execute();
  213.         } 
  214.         $res = ["status" => "200" "msg" => "otp code sent"] ;
  215.         return new JsonResponse($res);
  216.     }   
  217.     #[Route('/api/passwordreset',methods: ['POST'], name'password_reset')]
  218.     public function passwordreset(DocumentManager  $doctrine Request $request ,GoogleAuthenticatorInterface $twofactorUserPasswordHasherInterface $passwordHasher): JsonResponse
  219.     {
  220.         
  221.         $data =  json_decode($request->getContent(), false);
  222.         $mobile $data->mobile ;
  223.         $otp $data->otp ;
  224.         $gauthcode $data->gauth ;
  225.         $password $data->password ;
  226.         $user $doctrine->getRepository(User::class)->findOneBy(['username' => $mobile]);
  227.   
  228.         if($user) {
  229.             $google_auth_secret $user->getGoogleAuthenticatorSecret();
  230.             if($google_auth_secret) {
  231.             $google_auth_check $twofactor->checkCode($user,$gauthcode);
  232.             if($google_auth_check) {
  233.             if($user->getOtp() === $otp) {
  234.                 $hashedPassword $passwordHasher->hashPassword(
  235.                     $user,
  236.                     $password
  237.                 );
  238.                 $user->setPassword($hashedPassword);
  239.                 $doctrine->persist($user);
  240.                 $doctrine->flush();
  241.                 $res = ["status" => "200" "msg" => "New Password Set"] ;
  242.             } else {
  243.                 $res = ["status" => "400" "msg" => "Wrong Otp Code" ,"token" => null] ;
  244.             } 
  245.         } else {
  246.             $res = ["status" => "400" "msg" => "Wrong Google Auth Code" "token" => null] ;
  247.         }
  248.         } else {
  249.             if($user->getOtp() === $otp) {
  250.                 $hashedPassword $passwordHasher->hashPassword(
  251.                     $user,
  252.                     $password
  253.                 );
  254.                 $user->setPassword($hashedPassword);
  255.                 $doctrine->persist($user);
  256.                 $doctrine->flush();
  257.                 $res = ["status" => "200" "msg" => "New Password Set"] ;
  258.             } else {
  259.                 $res = ["status" => "400" "msg" => "Wrong Otp Code" ,"token" => null] ;
  260.             } 
  261.         }
  262.         } 
  263.         
  264.         return new JsonResponse($res);
  265.     }  
  266.     
  267.     
  268.     // #[Route('/api/register',methods: ['POST'], name: 'user_register')]
  269.     // public function userregister(DocumentManager  $doctrine , Request $request , UserPasswordHasherInterface $passwordHasher): JsonResponse
  270.     // {
  271.         
  272.     //     $data =  json_decode($request->getContent(), false);
  273.     //     $mobile = $data->mobile ;
  274.     //     $password = $data->password ;
  275.     //     $name = $data->name ;
  276.     //     $family = $data->family ;
  277.     //     $user_exist = $doctrine->getRepository(User::class)->findOneBy(['username' => $mobile]);
  278.     //     if (($user_exist)) {
  279.            
  280.     //         $res = ["status" => "400" , "msg" => "Username Exsit" ,] ;
  281.     //         return new JsonResponse($res);
  282.     //     } else {
  283.    
  284.        
  285.     //     $otp = random_int(10000, 99999);
  286.     //     $otptime = date('H:i:s \O\n d/m/Y');
  287.        
  288.     //     $user = new User() ;
  289.     //     $user->setUsername($mobile);
  290.     //    $hashedPassword = $passwordHasher->hashPassword(
  291.     //         $user,
  292.     //         $password
  293.     //     );
  294.     //     $user->setPassword($hashedPassword);
  295.     //     $user->setRoles(["ROLE_USER"]);
  296.     //     $user->setFirstname($name);
  297.     //     $user->setLastname($family);
  298.     //     $user->setOtp($otp);
  299.     //     $user->setOtptime($otptime);
  300.     //     $user->setStatus(0);
  301.     //     $user->setLevel(0);
  302.     //     $result =   $doctrine->persist($user);
  303.     //     $doctrine->flush();
  304.         
  305.     //     $res = ["status" => "200" , "msg" => "User Registered"] ;
  306.     //     return new JsonResponse($res);
  307.    
  308.     // }
  309.     // }
  310.     public function Ref_code_Gen() {
  311.       $code strtoupper(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'));
  312.       $ref_code substr($code,0,8) ;
  313.       $ref_code_exist $this->doc->getRepository(User::class)->findOneBy(['referralcode' => $ref_code ]);
  314.      
  315.       if($ref_code_exist) {
  316.         Ref_code_Gen();
  317.       } else {
  318.         return $ref_code ;
  319.       }
  320.     }
  321.     #[Route('/api/otpsend',methods: ['POST'], name'otp_send')]
  322.     public function onetimepassword(DocumentManager  $doctrine Request $request): JsonResponse
  323.     {
  324.         
  325.         $data =  json_decode($request->getContent(), false);
  326.         $mobile $data->mobile ;
  327.         $two_step_active False  ;
  328.        if(!preg_match("/^09[0-9]{9}$/"$mobile)) {
  329.     
  330.            $translated $this->translator->trans('Invalid Mobile');
  331.      
  332.           $res = ["status" => "400" "msg" => $translated] ;
  333.              return new JsonResponse($res);
  334.           }
  335.         
  336.         $user $doctrine->getRepository(User::class)->findOneBy(['username' => $mobile]);
  337.         $otp random_int(1000099999);
  338.         $otptime date('H:i:s \O\n d/m/Y');
  339.         if(is_null($user)) {
  340.         $ref_code $this->Ref_code_Gen();
  341.         $user = new User() ;
  342.         $user->setUsername($mobile);
  343.         $user->setStatus(0);
  344.         $user->setRoles(["ROLE_USER"]);
  345.         $user->setOtp($otp);
  346.         $user->setFata(false);
  347.         $user->setReferralCode($ref_code);
  348.         $user->setOtptime($otptime);
  349.         $user->setRegisterdate(time());
  350.         $doctrine->persist($user);
  351.         $doctrine->flush();
  352.         } else {
  353.             $finduser $doctrine->createQueryBuilder(User::class)
  354.             ->findAndUpdate()
  355.             ->field('id')->equals($user->getId())
  356.             ->sort('priority''desc')
  357.             ->field('otp')->set($otp)
  358.             ->field('otptime')->set($otptime)
  359.             ->getQuery()
  360.             ->execute();
  361.             $two_step_active $user->getGauthstatus();
  362.         }
  363.         $response $this->forward('App\Controller\NotificationController::sms_send_otp', [
  364.             'msg' => $otp,
  365.             'number' =>$mobile,
  366.         ]);
  367.         $content json_decode($response->getContent()) ;
  368.         $ret $content ;
  369.         
  370.         $res = ["status" => 200 "msg" => "otp sent" "gauth" => $two_step_active ] ;
  371.         return new JsonResponse($res);
  372.     }
  373.     
  374.     
  375.     
  376.     
  377.     #[Route('/api/user/fataseen',methods: ['POST'], name'fata_seen')]
  378.        public function FataSeen(DocumentManager  $doctrine Request $request ): JsonResponse
  379.     {  
  380.         
  381.         
  382.  
  383.       $user $this->getUser();
  384.         
  385.         
  386.         $fata $user->getFata();
  387.         
  388.         if(($fata) === "" || $fata ) {
  389.         
  390.         $user->setFata(true);
  391.         $doctrine->persist($user);
  392.         $doctrine->flush();
  393.         
  394.         }
  395.         
  396.         
  397.         
  398.         $res = ["status" => "200" "msg" => "fata seen"  ] ;
  399.         
  400.         return new JsonResponse($res);
  401.         
  402.         
  403.     }
  404.     
  405.     
  406.     
  407.     #[Route('/api/otpcheck',methods: ['POST'], name'otp_check')]
  408.     public function onetimepasswordcheck(DocumentManager  $doctrine Request $request ,GoogleAuthenticatorInterface $twofactorJWTTokenManagerInterface $JWTManager): JsonResponse
  409.     {
  410.         
  411.         $data =  json_decode($request->getContent(), false);
  412.         $mobile $data->username ;
  413.         $otp $data->password ;
  414.         $gauthcode $data->gauth ;
  415.         $user $doctrine->getRepository(User::class)->findOneBy(['username' => $mobile]);
  416.   
  417.         if($user) {
  418.             
  419.             
  420.              $google_auth_status $user->getGauthstatus();
  421.         
  422.         
  423.         if(!$google_auth_status) {
  424.             
  425.             $secret $twofactor->generateSecret($user);
  426.             $user->setGoogleAuthenticatorSecret($secret);
  427.             
  428.             $doctrine->persist($user);
  429.             $doctrine->flush();
  430.                                   } 
  431.        
  432.       
  433.      
  434.         //     $wallets_exist = $doctrine->createQueryBuilder(Wallet::class)
  435.         //     ->field('userid')->equals($user->getId())
  436.         //     ->field('pair')->in(['RIAL', 'USDT'])
  437.         //     ->hydrate(false)
  438.         //     ->getQuery()
  439.         //     ->execute()
  440.         //     ->toArray();
  441.         //  if(!$wallets_exist)   {
  442.                
  443.         //       $need_wallets = array("RIAL","USDT", "BTC", "ETH", "DOGE", "ADA", "SOL", "DOT", "TRX", "BNB", "LTC"); 
  444.         //         foreach($need_wallets as $need_wallet) {
  445.         //     $wall = new Wallet();
  446.         //     $wall->setuserid($user->getId());
  447.         //     $wall->setAddress('');
  448.         //     $wall->setnetwork('main');
  449.         //     $wall->setpair($need_wallet);
  450.         //     $wall->setballance(0);
  451.     
  452.         //     $doctrine->persist($wall);
  453.         //     $doctrine->flush();
  454.         //             }
  455.           
  456.     
  457.         //               }
  458.            
  459.             if($google_auth_status) {
  460.             $google_auth_check $twofactor->checkCode($user,$gauthcode);
  461.             if($google_auth_check) {
  462.             if($user->getOtp() === $otp) {
  463.                 $res = ["status" => "200" "msg" => "success""userlevel" => $user->getLevel()  , "token" => $JWTManager->create($user)] ;
  464.             } else {
  465.                 $res = ["status" => "400" "msg" => "Wrong Otp Code" ,"token" => null] ;
  466.             } 
  467.         } else {
  468.             $res = ["status" => "400" "msg" => "Wrong Google Auth Code" "token" => null] ;
  469.         }
  470.         } else {
  471.             if($user->getOtp() === $otp) {
  472.                 $res = ["status" => "200" "msg" => "success",  "userlevel" => $user->getLevel()   ,"userstatus" => $user->getStatus()  , "token" => $JWTManager->create($user)] ;
  473.             } else {
  474.                 $res = ["status" => "400" "msg" => "Wrong Otp Code" ,"token" => null] ;
  475.             }  
  476.         }
  477.         } 
  478.      
  479.         
  480.         return new JsonResponse($res);
  481.     }
  482.     #[Route('/api/gauth/activation',methods: ['POST'], name'google_auth_activation')]
  483.     public function googleauthactivator(DocumentManager  $doctrine Request $request GoogleAuthenticatorInterface $twofactor): JsonResponse
  484.     {  
  485.         
  486.         
  487.         $data =  json_decode($request->getContent(), false);
  488.         $user $this->getUser();
  489.         
  490.         $two_code $data->gauth ;
  491.         
  492.         $google_auth_status $user->getGauthstatus();
  493.         
  494.         
  495.         $google_auth_check $twofactor->checkCode($user,$two_code);
  496.         
  497.         
  498.         
  499.         if($google_auth_check) {
  500.             
  501.             
  502.            if($google_auth_status) { 
  503.         $user->setGauthstatus(False);
  504.            } else {
  505.                  $user->setGauthstatus(True); 
  506.            }
  507.                    
  508.         $doctrine->persist($user);
  509.         $doctrine->flush();
  510.         
  511.        $res = ["status" => "200" "msg" =>  "gauth activation"] ;
  512.             
  513.         } else {
  514.             
  515.             
  516.                     $res = ["status" => "400" "msg" => "Wrong Code"  ] ;
  517.         }
  518.         
  519.         
  520.         
  521.         
  522.         
  523.         
  524.         
  525.         
  526.  
  527.         
  528.         
  529.         
  530.         return new JsonResponse($res);
  531.         
  532.         
  533.     }
  534.     #[Route('/api/gauth',methods: ['POST'], name'google_auth')]
  535.     public function googleauth(DocumentManager  $doctrine Request $request GoogleAuthenticatorInterface $twofactor): JsonResponse
  536.     {
  537.         
  538.         $data =  json_decode($request->getContent(), false);
  539.         $user $this->getUser();
  540.         $google_auth_status $user->isGoogleAuthenticatorEnabled();
  541.         if($google_auth_status) {
  542.            $user->setGoogleAuthenticatorSecret(null);
  543.         } 
  544.        
  545.        else {
  546.             $secret $twofactor->generateSecret($user);
  547.             $user->setGoogleAuthenticatorSecret($secret);
  548.         }
  549.         
  550.         $doctrine->persist($user);
  551.         $doctrine->flush();
  552.         
  553.         $res = ["status" => "400" "gauthsecret" => $user->getGoogleAuthenticatorSecret()] ;
  554.         
  555.         return new JsonResponse($res);
  556.     }   
  557.     #[Route('/api/updateprofile',methods: ['POST'], name'update_profile')]
  558.     public function updateprofile(DocumentManager  $doctrine Request $request ): JsonResponse
  559.     {
  560.         
  561.         $data =  json_decode($request->getContent(), false);
  562.         $user $this->getUser();
  563.         $firstname $data->firstname ;
  564.         $lastname $data->lastname ;
  565.         $nationalid $data->nationalid ;
  566.         $country $data->country ;
  567.         $birthdate $data->birthdate ;
  568.         $identitydocument $data->identitydocument 
  569.         $user->setFirstname($firstname);
  570.         $user->setLastname($lastname);
  571.         $user->setNationalid($nationalid);
  572.         $user->setCountry($country);
  573.         $user->setBirthdate($birthdate);
  574.         $user->setIdentitydocument($identitydocument);
  575.         
  576.         $doctrine->persist($user);
  577.         $doctrine->flush();
  578.         
  579.         $res = ["status" => "200" "msg" => "Profile Updated"] ;
  580.         
  581.         return new JsonResponse($res);
  582.     }   
  583.     
  584.     
  585.     #[Route('/api/user/profile',methods: ['POST'], name'user_profile')]
  586.     public function userprofile(DocumentManager  $doctrine Request $request ): JsonResponse
  587.     {
  588.         $data =  json_decode($request->getContent(), false);
  589.         $user $this->getUser();
  590.         $result = array(
  591.          
  592.             "fullname" => $user->getFirstname() . " " $user->getLastname() ,
  593.             "mobile" => $user->getUsername(),
  594.             "status" => $user->getStatus() ,
  595.             "nid" =>    $user->getNationalid() ,
  596.             "level" => $user->getLevel(),
  597.             "fata" => $user->getFata(),
  598.             "email" => $user->getEmail(),
  599.             "twofa" => $user->getGoogleAuthenticatorSecret(),
  600.             "gauth" => $user->getGauthstatus(),
  601.             "referralcode" => $user->getReferralCode(),
  602.             "telphone" => $user->getTelphone(),
  603.             "address" => $user->getAddress()
  604.         );
  605.         $res = ["status" => "200" "msg" => "get Profile" "user" => $result] ;
  606.         return new JsonResponse($res);
  607.     }
  608.    public function getfinotoken(){
  609.     $curl curl_init();
  610.     curl_setopt_array($curl, array(
  611.       CURLOPT_URL => 'https://trusttether.org/api/auth',
  612.       CURLOPT_RETURNTRANSFER => true,
  613.       CURLOPT_ENCODING => '',
  614.       CURLOPT_MAXREDIRS => 10,
  615.       CURLOPT_TIMEOUT => 0,
  616.       CURLOPT_FOLLOWLOCATION => true,
  617.       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  618.       CURLOPT_CUSTOMREQUEST => 'POST',
  619.       CURLOPT_POSTFIELDS =>'{
  620.         "username" : "hamed",
  621.         "password" : "hamed110"
  622.     }',
  623.       CURLOPT_HTTPHEADER => array(
  624.         'Content-Type: application/json'
  625.       ),
  626.     ));
  627.     
  628.     $response curl_exec($curl);
  629.     
  630.     curl_close($curl);
  631. return json_decode($response) ;
  632.    }
  633.    #[Route('/api/kyc/location',methods: ['POST'], name'user_kyc_location')]
  634.    public function kyclocation(DocumentManager  $doctrine Request $request ): JsonResponse
  635.    
  636.        
  637.        
  638.        
  639.     $user $this->getUser();
  640.     $data =  json_decode($request->getContent(), false);
  641.     
  642.     $file $request->files->get('file');
  643.     
  644.     
  645.     
  646.         if (!$file) {
  647.             
  648.         $translated $this->translator->trans('bill not  found');
  649.         $res = ["status" => "400" "msg" => $translated  ] ;
  650.         return new JsonResponse($res);
  651.                 }
  652.     
  653.     
  654.     $address =$request->get('address') ;
  655.     $telphone $request->get('telphone') ; 
  656.     
  657.    $doc $this->saveFile($file);
  658.        
  659.     $user->setTelphone($telphone);
  660.     $user->setAddress($address);
  661.     $user->setKycdocument($doc);
  662.     $doctrine->persist($user);
  663.     $doctrine->flush();
  664.        
  665.        
  666.       $translated $this->translator->trans('location registerd');
  667.       $res = ["status" => "200" "msg" => $translated    ] ;
  668.        return new JsonResponse($res);
  669.        
  670.    }
  671.    #[Route('/api/kyc/infocheck',methods: ['POST'], name'user_kyc_info')]
  672.    public function infocheck(DocumentManager  $doctrine Request $request ): JsonResponse
  673.    {    
  674.      $server_token "c736234831ab9805856a7239e5a7acec6145901f";
  675.      
  676.     $user $this->getUser();
  677.     
  678.     $data =  json_decode($request->getContent(), false);
  679.     $name $data->name ;
  680.     $family $data->family 
  681.     $birthdate $data->birthday ;
  682.     $email $data->email ;
  683.     $referral $data->referral 
  684.     $nid $user->getNationalid() ;
  685.       $curl curl_init();
  686.       
  687.       curl_setopt_array($curl, array(
  688.         CURLOPT_URL => 'https://service.zohal.io/api/v0/services/inquiry/national_identity_inquiry',
  689.         CURLOPT_RETURNTRANSFER => true,
  690.         CURLOPT_ENCODING => '',
  691.         CURLOPT_MAXREDIRS => 10,
  692.         CURLOPT_TIMEOUT => 0,
  693.         CURLOPT_FOLLOWLOCATION => true,
  694.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  695.         CURLOPT_CUSTOMREQUEST => 'POST',
  696.         CURLOPT_POSTFIELDS =>'{
  697.       
  698.           "national_code" : "'.$nid.'",
  699.           "birth_date" : "'.$birthdate.'"
  700.       
  701.       }',
  702.         CURLOPT_HTTPHEADER => array(
  703.           'Content-Type: application/json',
  704.           'Authorization: Bearer '.$server_token.''
  705.         ),
  706.       ));
  707.       
  708.       $response curl_exec($curl);
  709.       
  710.       curl_close($curl);
  711.       
  712.       
  713.       $responseArray json_decode($responsetrue);
  714.     
  715.   
  716.       
  717.       
  718.       if (isset($responseArray['response_body']['data']['matched']) && $responseArray['response_body']['data']['matched'] === true) {
  719.           
  720.     $user->setLastname($family);
  721.     $user->setFirstname($name);
  722.     $user->setEmail($email);
  723.     $user->setReferral($referral);
  724.     $user->setBirthdate($birthdate);
  725.     $user->setLevel(1);
  726.     $user->setStatus(1);
  727.     
  728.     $doctrine->persist($user);
  729.     $doctrine->flush();
  730. }
  731.   
  732.    
  733.     
  734.     
  735. $res = ["status" => "200" "msg" => "اطلاعات شما جهت بررسی ارسال گردید"  "res" => $responseArray['response_body']['data']['matched']  ] ;
  736.                     return new JsonResponse($res);
  737.    }
  738.    #[Route('/api/bank/add',methods: ['POST'], name'user_kyc_card')]
  739.    public function cardcheck(DocumentManager  $doctrine Request $request ): JsonResponse
  740.    {
  741.  //   $server_token = ($this->getfinotoken())->token;
  742.     $user $this->getUser();
  743.     $data =  json_decode($request->getContent(), false);
  744.     $card_number $data->number ;
  745.     $nid $user->getNationalid() ;
  746.     $birthdate $user->getBirthday() ;
  747.     
  748.     
  749.     
  750.     
  751.     
  752.         if(!$nid || !$birthdate ) {
  753.         
  754.         
  755.           $res = ["status" => "400"   "msg" =>  "ابتدا اطلاعات هویتی خود را تکمیل نمایید" ];
  756.           
  757.             return new JsonResponse($res);
  758.         
  759.     }
  760.     
  761.     
  762.     
  763.     if(strlen($card_number) != 16) {
  764.         
  765.         
  766.          $res = ["status" => "400"   "msg" =>  "شماره کارت اشتباه  می باشد" ];
  767.           
  768.             return new JsonResponse($res);
  769.            
  770.         
  771.         
  772.     }
  773.     
  774.     
  775.     
  776.     
  777.     $card_exist  =  $doctrine->getRepository(Bank::class)->findOneBy(['number' => $card_number ]);
  778.     
  779.     
  780.     if($card_exist) {
  781.         
  782.         
  783.           $res = ["status" => "400"   "msg" =>  "شماره کارت تکراری می باشد" ];
  784.           
  785.             return new JsonResponse($res);
  786.         
  787.     }
  788.     
  789.         
  790.             $wall = new Bank();
  791.             $wall->setUser($user->getId());
  792.             $wall->setName('');
  793.             $wall->setBank('');
  794.             $wall->setNumber($card_number);
  795.             $wall->setIban('');
  796.             $wall->setStatus('1');
  797.     
  798.             $doctrine->persist($wall);
  799.             $doctrine->flush();
  800.             
  801.             
  802.     
  803.             
  804.              $res = ["status" => "200"    "msg" =>  "کارت بانکی تایید و اضافه گردید"  ] ;
  805.                 
  806.             return new JsonResponse($res);
  807.    }
  808.    #[Route('/api/kyc/idcardcheck',methods: ['POST'], name'user_kyc_idcard')]
  809.    public function idcardcheck(DocumentManager  $doctrine Request $request ): JsonResponse
  810.    {   
  811.        
  812.        
  813.       $server_token "c736234831ab9805856a7239e5a7acec6145901f";
  814.       $user $this->getUser();
  815.       
  816.       $data =  json_decode($request->getContent(), false);
  817.       $nid $user->getNationalid();
  818.       
  819.       
  820.           
  821.       $file $request->files->get('file');
  822.       
  823.              
  824.       $file2 $request->files->get('file2');
  825.       
  826.       
  827.       $temp_file $request->files->get('file');
  828.       
  829.       $temp_file2 =  $request->files->get('file2');
  830.       
  831.       
  832.       
  833.           if (!$file) {
  834.         $res = ["status" => "400" "msg" => "id card not  found" ] ;
  835.         return new JsonResponse($res);
  836.                 }
  837.       
  838.             $tempFile $file->getPathname();
  839.         
  840.             $tempFile2 $file2->getPathname();
  841.  
  842.         
  843.         
  844.         $front $tempFile ;
  845.         
  846.         $back $tempFile2 ;
  847.         
  848.      
  849.       
  850. // API URL
  851. $url 'https://service.zohal.io/api/v0/services/inquiry/national_card_ocr';
  852. // Initialize cURL session
  853. $ch curl_init();
  854. // Set cURL options
  855. curl_setopt($chCURLOPT_URL$url);
  856. curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  857. curl_setopt($chCURLOPT_POSTtrue);
  858. $headers = array(
  859.     'Content-Type: multipart/form-data',
  860.     'Authorization: Bearer ' $server_token
  861. );
  862. curl_setopt($chCURLOPT_HTTPHEADER$headers);
  863. // Prepare file uploads
  864. $postData = [
  865.     'national_card_back' => new \CURLFile($back$temp_file2->getMimeType(), $temp_file2->getClientOriginalName()),
  866.     'national_card_front' => new \CURLFile($front$temp_file->getMimeType(), $temp_file->getClientOriginalName())
  867. ];
  868. curl_setopt($chCURLOPT_POSTFIELDS$postData);
  869. // Execute cURL request
  870. $response curl_exec($ch);
  871. curl_close($ch);
  872.      $responseArray json_decode($responsetrue);
  873.      
  874.      $flag false ;
  875.      
  876.      if(isset($responseArray['response_body']['data']['front']) && isset($responseArray['response_body']['data']['front'])) {
  877.          
  878.          
  879.          $nid_back =  $responseArray['response_body']['data']['back']['nationalCode'];
  880.          
  881.          $nid_front $responseArray['response_body']['data']['front']['nationalCode']; 
  882.          
  883.          
  884.          
  885.           if ($nid_front === $nid_back && $nid === $nid_front) {
  886.               
  887.               $flag true ;
  888.               
  889.           }
  890.          
  891.          
  892.          
  893.          
  894.          
  895.          
  896.      }
  897.    
  898.    
  899.    
  900.           $doc $this->saveFile($file);
  901.        
  902.        
  903.               
  904.        $doc2 $this->saveFile($file2);
  905.        
  906.    
  907.        
  908.        
  909.        
  910.        $docs = [$doc,$doc2];
  911.   
  912.       if ($flag){
  913.      
  914.       $user->setLevel("2");
  915.       $user->setIdentitydocument(json_encode($docs));
  916.       $doctrine->persist($user);
  917.       $doctrine->flush();
  918.       }
  919.       
  920.       
  921.       
  922.       
  923.         
  924.                     
  925.         
  926.        $res = ["status" => "200" "msg" => "اطلاعات شما جهت بررسی ارسال گردید"  "res" =>  $flag  ] ;
  927.     
  928.     return new JsonResponse($res);
  929.        
  930.        
  931.    }
  932.    #[Route('/api/kyc/videocheck',methods: ['POST'], name'user_kyc_video')]
  933.    public function videocheck(DocumentManager  $doctrine Request $request ): JsonResponse
  934.    {   
  935.     $server_token = ($this->getfinotoken())->token;
  936.     $user $this->getUser();
  937.  
  938.     $file $request->files->get('file');
  939.    
  940.   
  941.     if (!$file) {
  942.         $res = ["status" => "200" "msg" => "video not  found" ] ;
  943.         return new JsonResponse($res);
  944.     }
  945.     $videoFile $this->saveFile($file);
  946.     $nid $user->getNationalid() ;
  947.     $birthdate $user->getBirthday() ;
  948.     $serial "1" 
  949.     $parameters = [
  950.     "nid" => $nid ,
  951.     "serial" => $serial,
  952.     "birth" => $birthdate 
  953.                   ];
  954.     
  955.     $postData =   http_build_query($parameters);
  956.     $url 'https://trusttether.org/api/finotech/videocheck?'.$postData ;
  957.     $curl curl_init();
  958.       
  959.     curl_setopt_array($curl, array(
  960.       CURLOPT_URL => $url,
  961.       CURLOPT_RETURNTRANSFER => true,
  962.       CURLOPT_ENCODING => '',
  963.       CURLOPT_MAXREDIRS => 10,
  964.       CURLOPT_TIMEOUT => 0,
  965.       CURLOPT_FOLLOWLOCATION => true,
  966.       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  967.       CURLOPT_CUSTOMREQUEST => 'POST',
  968.       CURLOPT_POSTFIELDS => [],
  969.       CURLOPT_HTTPHEADER => array(
  970.         'Content-Type: multipart/form-data',
  971.         'Authorization: Bearer '.$server_token.''
  972.       ),
  973.     ));
  974.     
  975.     $response curl_exec($curl);
  976.     
  977.     curl_close($curl);
  978.     $res = ["status" => "200" "msg" => "video checked"  "res" => json_decode($response)   ] ;
  979.     return new JsonResponse($res);
  980.    }
  981.    private function saveFile(UploadedFile $file ): string
  982.     {
  983.         $directory 'docss'// Specify the directory to save the file
  984.         try {
  985.       
  986.           
  987.           
  988.             $safeFilename $this->slug->slug($file);
  989.             $newFilename $safeFilename.'-'.uniqid().'.'.$file->guessExtension();
  990.             $file->move($directory,$newFilename);
  991.             return $newFilename;
  992.         } catch (Exception $e) {
  993.             throw new \RuntimeException('Failed to save file: ' $e->getMessage());
  994.         }
  995.     }
  996.     #[Route('/api/kyc/nidcheck',methods: ['POST'], name'user_kyc_nid')]
  997.     public function nidcheck(DocumentManager  $doctrine Request $request ): JsonResponse
  998.     {    
  999.      $server_token "c736234831ab9805856a7239e5a7acec6145901f";
  1000.       $user $this->getUser();
  1001.       
  1002.       $data =  json_decode($request->getContent(), false);
  1003.  
  1004.       $nid $data->nid ;
  1005.       $mobile $data->mobile ;
  1006.       $curl curl_init();
  1007.       
  1008.       curl_setopt_array($curl, array(
  1009.         CURLOPT_URL => 'https://service.zohal.io/api/v0/services/inquiry/shahkar',
  1010.         CURLOPT_RETURNTRANSFER => true,
  1011.         CURLOPT_ENCODING => '',
  1012.         CURLOPT_MAXREDIRS => 10,
  1013.         CURLOPT_TIMEOUT => 0,
  1014.         CURLOPT_FOLLOWLOCATION => true,
  1015.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1016.         CURLOPT_CUSTOMREQUEST => 'POST',
  1017.         CURLOPT_POSTFIELDS =>'{
  1018.       
  1019.           "national_code" : "'.$nid.'",
  1020.           "mobile" : "'.$mobile.'"
  1021.       
  1022.       }',
  1023.         CURLOPT_HTTPHEADER => array(
  1024.           'Content-Type: application/json',
  1025.           'Authorization: Bearer '.$server_token.''
  1026.         ),
  1027.       ));
  1028.       
  1029.       $response curl_exec($curl);
  1030.       
  1031.       curl_close($curl);
  1032.       
  1033.       
  1034.       $responseArray json_decode($responsetrue);
  1035.       
  1036.       
  1037.       
  1038.       if (isset($responseArray['response_body']['data']['matched']) && $responseArray['response_body']['data']['matched'] === true) {
  1039.           
  1040.       $user->setNationalid($nid);
  1041.       $doctrine->persist($user);
  1042.       $doctrine->flush();
  1043.       
  1044.       
  1045.       
  1046.       
  1047. }
  1048.       
  1049.     
  1050.         $res = ["status" => "200" "msg" => "کد ملی شما جهت بررسی ارسال شد" "res" =>$responseArray['response_body']['data']['matched']  ] ;
  1051.         return new JsonResponse($res);
  1052.     }
  1053.     #[Route('/api/userkyc',methods: ['POST'], name'user_kyc')]
  1054.     public function userkyc(DocumentManager  $doctrine Request $request ): JsonResponse
  1055.     {
  1056.         // $data =  json_decode($request->getContent(), false);
  1057.         // $user = $this->getUser();
  1058.         // $type_of_kyc = $data->type ;
  1059.         // switch ($type_of_kyc) {
  1060.         //     case 'mobile':
  1061.         //         # code...
  1062.         //         break;
  1063.         //     case 'email':
  1064.         //             # code...
  1065.         //         break;
  1066.         //     case 'documnet':
  1067.         //             # code...
  1068.         //         break;    
  1069.             
  1070.         //     default:
  1071.         //         # code...
  1072.         //         break;
  1073.         // }
  1074.         
  1075.         $curl curl_init();
  1076.         
  1077.         curl_setopt_array($curl, array(
  1078.           CURLOPT_URL => 'https://apibeta.finnotech.ir/kyc/v2/clients/trusttether/ibanOwnerBirthdateVerification?birthDate=1368%2F06%2F21&nid=0011095891&iban=IR280560611828005163309401',
  1079.           CURLOPT_RETURNTRANSFER => true,
  1080.           CURLOPT_ENCODING => '',
  1081.           CURLOPT_MAXREDIRS => 10,
  1082.           CURLOPT_TIMEOUT => 0,
  1083.           CURLOPT_FOLLOWLOCATION => true,
  1084.           CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1085.           CURLOPT_CUSTOMREQUEST => 'GET',
  1086.           CURLOPT_HTTPHEADER => array(
  1087.             'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbklkIjoiOGQzMTViNzAtMzVjMi00YzZlLWE0MmYtNTVlMjI3OWI1ODcwIiwicmVmcmVzaFRva2VuIjoiUXdMa2xudUxFSFhuY2JnbU10Q3VGNFZUOGwwZmRlcFFyYk1oSE42MHdzTkFJSWo3Uk5kbFpMaXZmbmRYWjV3QWc1SmRXY2c1cGxXekJDQm5GQVp4MGpxSmwxczg5aDU5U2xiWTlhSGZ0MjJyT1JWbjFGUjdyYlcyVmViM1k0TFMwUG5hSWVYTlphR2hzdXd6RHpJa3dWNTA4dUIzV3laZ0FHbkxSRkNHTUZqdkZ1WFNZM1BLT0NLZTBRSzhBRDJRVjZ5MG5rd2Y1RURvWk9Ha2hRVjN5TkVuekxtM1VlT1RxSGtJY3N5Wko0emRMZDhyTmdrbHVoWDNZdFpzM1p0UyIsImNyZWF0aW9uRGF0ZSI6IjE0MDIwOTEzMDQ0NDI3IiwibGlmZVRpbWUiOjg2NDAwMDAwMCwiY2xpZW50SWQiOiJ0cnVzdHRldGhlciIsInVzZXJJZCI6IjAwNzU0MjY3MzAiLCJhY3RpdmUiOnRydWUsInNjb3BlcyI6WyJreWM6aWJhbi1vd25lci1iaXJ0aGRhdGUtdmVyaWZpY2F0aW9uOmdldCJdLCJ0eXBlIjoiQ0xJRU5ULUNSRURFTlRJQUwiLCJjbGllbnRJbmZvIjoiVjFqSjFrSExHWDJFZXMzS29ZekF6TlNBWXRKMFUwbmx5MHlMWVVDczlHN0gwc0VsOHlPTndyZ1dqdXFFVzQvWCIsImJhbmsiOiIwNjIiLCJpYXQiOjE3MDE2NTI0NjcsImV4cCI6MTcwMjUxNjQ2N30.dOdZlpimz0rM_uXEFK5moCT3v-cbmz1FYvbfKQtAwIt9O1w0XAWF_6H7tCn2YnV0Z1XmxnupJi5t1oJ4uZhbcz43S7WCxDPbYH9_k58eHzO1UH40WdR7Pw2QW5dx5oj_Bog4SrUvkmdhs0EyXgpQVrfW-zf6CLil-PuGp-J8ao82ouXLG-TwuNwpxqwnf3-TNU4Xj3Yn1nTLWbIa4Mh1YQ-p5osMf-HDZGYLW82Nk3RXnZPvSjSpANxqW2vACBaA8jhebzLzyvWYiLuKrcmNFIg71Grby1vqt0IEgMOQYQtqOuVvlHqiGoh67to-rdhNjfwXALfTarCZTt0rI-6mgg'
  1088.           ),
  1089.         ));
  1090.         
  1091.         $response curl_exec($curl);
  1092.         
  1093.         curl_close($curl);
  1094.       
  1095.         
  1096.         $res = ["status" => "200" "msg" => ($response) ] ;
  1097.     }
  1098. }