/**
  * Creates a new user
  * @param Request $request
  * @return JsonResponse
  * @throws BadRequestHttpException
  */
 public function postAction(Request $request)
 {
     $data = $this->getParsedRequestContent($request);
     if (!isset($data['name']) || !isset($data['password'])) {
         throw new BadRequestHttpException('The parameter name or password is missing.');
     }
     if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $data['name'])) {
         throw new BadRequestHttpException('The parameter name does not match the pattern.');
     }
     if (!preg_match('/^.{6,32}$/', $data['password'])) {
         throw new BadRequestHttpException('The parameter password does not match the pattern.');
     }
     if ($this->em->getRepository('CoreBundle:User')->findOneBy(['name' => $data['name']])) {
         $message = 'A user with this name allready exists.';
         return new JsonResponse($message, 200);
     }
     $passwordGenerator = new Password();
     $password = $passwordGenerator->generatePassword($data['password']);
     /* @var $user User */
     $user = new User();
     $user->setName($data['name']);
     $user->setPassword($password['password']);
     $user->setSalt($password['salt']);
     $this->em->persist($user);
     $this->em->flush();
     $request->getSession()->set('userId', $user->getId());
     return new JsonResponse(null, 204);
 }
Example #2
0
 /**
  * Insert un message de team en base
  *
  * @param User      $user
  * @param integer   $teamId
  * @param string    $message
  *
  * @author Benjamin Levoir <*****@*****.**>
  */
 public function insertMessage(User $user, $teamId, $message)
 {
     $m = new \CoreBundle\Entity\TeamMessage();
     $m->setContent($message);
     $m->setSender($this->em->getReference('CoreBundle:User', $user->getId()));
     $m->setTeam($this->em->getReference('CoreBundle:Team', $teamId));
     $this->em->persist($m);
     $this->em->flush();
     return $this;
 }
Example #3
0
 /**
  * @inheritDoc
  */
 protected function createEntity($data)
 {
     $user = new User();
     $user->setLogin($data['login'])->setEmail($data['email'])->setPassword(md5($data['password']))->setHash(md5($data['hash']))->setConfirm($data['confirm'])->setInRest($data['in_rest'])->setLeftRest($data['left_rest'])->setGoneInRest($this->container->get("core.service.date")->getDateTime($data['gone_in_rest']))->setLastPing($this->container->get("core.service.date")->getDateTime($data['last_ping']))->setClass($data['class'])->setRating($data['rating'])->setWin($data['win'])->setDraw($data['draw'])->setLose($data['lose'])->setLoseTime($data['lose_time'])->setImmortalId($data['immortal_id'])->setAnotherLogin($data['another_login'])->setLastMove($this->container->get("core.service.date")->getDateTime($data['last_move']))->setBalance($data['balance'])->setLag((double) @$data["lag"])->setOnline((bool) @$data['online']);
     if (isset($data["settings"])) {
         foreach ($data["settings"] as $settingArray) {
             /** @var UserSetting $userSetting */
             $userSetting = $this->getReference($settingArray["settingReference"]);
             $userSetting->setValue($settingArray["value"]);
             $user->setSetting($userSetting);
         }
     }
     return $user;
 }
Example #4
0
 /**
  * Créer un noueau champion
  *
  * @param User $user
  * @param array $data
  * @return integer id
  * @author Benjamin Levoir <*****@*****.**>
  */
 public function addChampion(User $user, $data)
 {
     if (isset($data['slug'])) {
         $champ = $this->em->getRepository('CoreBundle:RefChampion')->findOneBy(array('slug' => $data['slug']));
         if (!empty($champ) && isset($data['level']) && UserChampion::levelExist($data['level']) && isset($data['role']) && UserChampion::roleExist($data['role']) && !$this->em->getRepository('CoreBundle:UserChampion')->findOneBy(array('user' => $user->getId(), 'role' => $data['role'], 'level' => $data['level'], 'champion' => $champ->getId()))) {
             $uchamp = new UserChampion();
             $uchamp->setUser($user);
             $uchamp->setChampion($champ);
             $uchamp->setRole($data['role']);
             $uchamp->setLevel($data['level']);
             $this->em->persist($uchamp);
             $this->em->flush();
             return $uchamp->getId();
         }
     }
     return null;
 }
Example #5
0
 /**
  * @param User $user
  * @param Game $game
  */
 public function defineUserMoveAndOpponentForGame(User $user, Game $game)
 {
     $game->setUserMove($game->getUserToMove() == $user);
     switch (true) {
         case $game->getUserWhite() == $user:
             $game->setOpponent($game->getUserBlack());
             break;
         case $game->getUserBlack() == $user:
             $game->setOpponent($game->getUserWhite());
             break;
         default:
             throw new GameHandlerException("Unknown user {$user->getLogin()} for game {$game->getId()}");
     }
 }
Example #6
0
 /**
  * Retourne la liste des équipes dans lesquels l'utilisateur est capitaine
  *
  * @param User $user
  * @return array
  *
  * @author Benjamin Levoir <*****@*****.**>
  */
 public function getUserTeamCaptain($user)
 {
     return $this->em->getRepository('CoreBundle:Team')->findBy(array('captain' => $user->getId()));
 }
Example #7
0
 /**
  * @param User $user
  * @param Game $game
  */
 private function updateWinDrawLoseForOneGame(User $user, Game $game)
 {
     $win = $user->getWin();
     $draw = $user->getDraw();
     $lose = $user->getLose();
     $this->updateWinDrawLose($game, $user, $win, $draw, $lose);
     $user->setWin($win)->setDraw($draw)->setLose($lose);
 }
Example #8
0
 /**
  * @param User $user
  * @return $this
  */
 public function addOpponent(User $user)
 {
     if (!$this->opponents) {
         $this->opponents = [];
     }
     $this->opponents[] = $user->getId();
     return $this;
 }
Example #9
0
 /**
  * Retourne les messages Envoyés
  *
  * @param User $user
  * @param integer $page
  * @param array $data
  * @return array
  * 
  * @author Benjamin Levoir <*****@*****.**>
  */
 public function getMessagesSent(User $user, $page, $data = array())
 {
     return $this->em->getRepository('CoreBundle:UserMessage')->getUserSentMessages($user->getId(), $page, \CoreBundle\Entity\UserMessage::PAGINATOR, $data);
 }
Example #10
0
 /**
  * @param User $playzoneUser
  * @param int $count
  * @return int
  */
 private function updatePlayzoneUsersMap(User $playzoneUser, int $count)
 {
     if (!isset($this->playzoneUsersMap[$playzoneUser->getId()])) {
         return $this->playzoneUsersMap[$playzoneUser->getId()] = 1;
     }
     return $this->playzoneUsersMap[$playzoneUser->getId()] += $count;
 }
Example #11
0
 /**
  * Récupère le compte de jeu d'un utilisateur
  * @param \CoreBundle\Service\User $user
  * @return \CoreBundle\Entity\GameAccount
  *
  * @author Benjamin Levoir <*****@*****.**>
  */
 public function getUserAccount(\CoreBundle\Entity\User $user)
 {
     $account = $this->em->getRepository('CoreBundle:GameAccount')->findOneBy(array('user' => $user->getId(), 'active' => true));
     return $account;
 }
Example #12
0
 /**
  * @param User $user
  * @param bool $save
  * @return bool
  */
 public function banUserIfIpIsBanned(User $user, $save = false) : bool
 {
     foreach ($user->getIps() as $userIp) {
         if ($this->isIpBanned($userIp)) {
             $user->setBanned(true);
             if ($save) {
                 $this->saveUser($user);
             }
             return true;
         }
     }
     return false;
 }
Example #13
0
 /**
  * Supprime un calendrier d'un utilisateur
  *
  * @param User $user
  * @param array $data
  * @return type
  */
 public function delCalendar(User $user, $data)
 {
     if (isset($data['id'])) {
         $cal = $this->em->getRepository('CoreBundle:UserCalendar')->findOneBy(array('id' => $data['id'], 'user' => $user->getId()));
         if (!empty($cal)) {
             $this->em->remove($cal);
             $this->em->flush();
         }
     }
     return null;
 }