Example #1
0
 /**
  * @Route("/{round}/register", name="register", requirements={"round": "\d+"})
  * @Template()
  */
 public function registerAction(Request $request, $round = null)
 {
     $round = $round ? $this->roundRepo->find($round) : $this->roundRepo->findCurrent();
     $address = $request->get('address', null);
     if (!$address) {
         $this->getSession()->getFlashBag()->set('error', 'Address is required');
     } else {
         $validation = $this->manager->validateAddress($address);
         if (!$validation->isValid()) {
             $this->getSession()->getFlashBag()->set('error', 'Invalid address');
         } else {
             if (!($account = $this->accountRepo->findOneBy(['withdrawAddress' => $address]))) {
                 $depositAddress = $this->manager->getNewAddress($round->getWalletAccount());
                 $account = new Account();
                 $account->setWithdrawAddress($address);
                 $account->setDepositAddress($depositAddress);
                 if (($ref = $this->getSession()->get('ref')) || ($ref = $request->cookies->get('ref'))) {
                     if ($refAccount = $this->accountRepo->find($ref)) {
                         $account->setReferrer($refAccount);
                         $refAccount->addReferralRegistersCount();
                     }
                 }
                 $this->getDoctrine()->getManager()->persist($account);
                 $this->getDoctrine()->getManager()->flush();
             }
             $this->getSession()->set('account', $account->getId());
         }
     }
     return $this->redirect($this->generateUrl('stats', ['round' => $round->getId()]));
 }