/**
  * @param string $login
  * @param string $password
  * @param bool $rememberMe
  * @return Token
  */
 public function login($login, $password, $rememberMe = true)
 {
     try {
         $account = $this->accountService->getRepository()->findByLogin($login);
         if ($rememberMe === true) {
             $config = Game::getInstance()->getConfig();
             $rememberDays = $config["app"]["remember_days"];
             $endTime = time() + 3600 * 24 * $rememberDays;
         } else {
             $endTime = time() + 600;
         }
         $endDate = new \DateTime();
         $endDate->setTimestamp($endTime);
         if (is_null($account->getAuthToken())) {
             $token = $this->tokenService->generateToken($account, $endDate);
             $account->setAuthToken($token);
         } elseif (!$this->tokenService->isValid($account->getAuthToken()->getValue())) {
             $token = $this->tokenService->generateToken($account, $endDate);
             $account->setAuthToken($token);
         }
         $this->accountService->getRepository()->save($account);
         return $account->getAuthToken();
     } catch (EntityNotFoundException $e) {
         return false;
     }
 }
 /**
  * @param \Likedimion\Tools\Helper\PlayerDataHelper $playerData
  * @throws \Likedimion\Exception\RegistrationException
  * @return Player
  */
 public function createPlayer(PlayerDataHelper $playerData)
 {
     try {
         $findPlayer = $this->playerService->getRepository()->findPlayerByName($playerData->name);
         throw new RegistrationException("player_name_exists");
     } catch (EntityNotFoundException $e) {
         $player = new Player();
         $player->setName($playerData->name);
         $player->setSex($playerData->sex);
         $player->setClass($playerData->class);
         $player->setRace($playerData->race);
         $stats = $player->getStats();
         $cfg = Game::getInstance()->getConfig();
         $stats->setStrenge($cfg["new_player"][$player->getClass()]["str"]);
         $stats->setDexterity($cfg["new_player"][$player->getClass()]["dex"]);
         $stats->setIntelligence($cfg["new_player"][$player->getClass()]["int"]);
         $stats->setSpirituality($cfg["new_player"][$player->getClass()]["spr"]);
         $stats->setEndurance($cfg["new_player"][$player->getClass()]["end"]);
         $player->setStats($stats);
         $this->playerCalculatingService->calculate($player);
         $this->playerService->getRepository()->save($player);
         $account = $this->authService->getAccount(Game::getInstance()->getAuthToken()->getValue());
         $player->setAccount($account);
         $this->accountService->getRepository()->save($account);
         $this->playerService->getRepository()->save($player);
         return $player;
     }
 }
 public function testAccount()
 {
     try {
         $account = $this->accountService->getRepository()->findByEmail($this->email);
         $this->assertInstanceOf($this->entityAccountClass, $account);
     } catch (EntityNotFoundException $e) {
         $this->fail($e->getMessage());
     }
 }
Ejemplo n.º 4
0
 public function testRemoveAccount()
 {
     try {
         $account = $this->accountService->getRepository()->findByEmail($this->email);
         $this->assertInstanceOf($this->entityAccountClass, $account);
         $this->accountService->getRepository()->remove($account);
     } catch (EntityNotFoundException $e) {
         $this->assertTrue(true);
     }
 }