Example #1
0
 /**
  * @param UserInterface|SmallUserInterface $user
  * @return boolean
  */
 protected function handleAuth4UserLogin(SmallUserInterface $user)
 {
     if ($this->isRegisterDynamicImport()) {
         /** @var \PServerCore\Entity\Repository\User $userRepository */
         $userRepository = $this->entityManager->getRepository($this->collectionOptions->getEntityOptions()->getUser());
         if (!$userRepository->getUser4UserName($user->getUsername())) {
             /** @var UserInterface $backendUser */
             if ($backendUser = $this->gameDataService->getUser4Login($user)) {
                 if (!$backendUser->getCreateIp()) {
                     $backendUser->setCreateIp($this->ipService->getIp());
                 }
                 // we only save valid names
                 try {
                     if (!(new EmailAddress())->isValid($backendUser->getEmail())) {
                         $backendUser->setEmail('');
                     }
                 } catch (\Exception $e) {
                     $backendUser->setEmail('');
                 }
                 $backendUser->setPassword($this->bCrypt($user->getPassword()));
                 $entityManager = $this->entityManager;
                 $entityManager->persist($backendUser);
                 $entityManager->flush();
                 $this->setAvailableCountries4User($backendUser, $this->ipService->getIp());
                 $this->addDefaultRole($backendUser);
                 $this->doAuthentication($backendUser);
                 return true;
             }
         }
     }
     return parent::handleAuth4UserLogin($user);
 }
Example #2
0
 /**
  * @param $data
  * @param $userId
  * @param UserInterface $adminUser
  * @return bool
  */
 public function addCoinsForm($data, $userId, UserInterface $adminUser)
 {
     $form = $this->adminCoinForm;
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     $user = $this->getUser4Id($userId);
     if ($user) {
         $data = $form->getData();
         $this->addCoins($user, $data['coins']);
         $class = $this->entityOptions->getDonateLog();
         /** @var \PServerCore\Entity\DonateLog $donateEntity */
         $donateEntity = new $class();
         $donateEntity->setTransactionId('AdminPanel: ' . $adminUser->getUsername())->setCoins($data['coins'])->setIp($this->ipService->getIp())->setSuccess($donateEntity::STATUS_SUCCESS)->setType($donateEntity::TYPE_INTERNAL)->setUser($user);
         $this->entityManager->persist($donateEntity);
         $this->entityManager->flush();
     }
     return true;
 }