public function addUser() { try { $this->checkPostRequest(); $header = $this->datosPeticion[Rest::HEADER]; $body = $this->datosPeticion[Rest::BODY]; $countryCode = $header[Rest::COUNTRY]; $player = new Player(); if ($player->jsonUnserialize($body)) { //Encripta el password del usuario $player->setPassword(Helper::cryptUserPassword($player->getPassword())); //Se genera la semilla para los procesos posteriores $player->setSeed(Helper::generateSeed()); //el constructor del padre ya se encarga de sanear los datos de entrada $inserted = $this->playerDAO->addUser($player); if ($inserted == TRUE) { $this->processSuccessResponse($countryCode, $inserted); } else { $this->processErrorResponse($countryCode, Rest::STATUS_ERROR, IPlayerService::PLAYER_NOT_UPDATED); } } else { throw new DAOException(IPlayerService::REQUIRED, Rest::STATUS_BAD_REQUEST); } } catch (DAOException $e) { $this->processErrorResponse('', Rest::STATUS_ERROR, $e->getMessage()); } catch (Exception $e) { $this->processErrorResponse('', Rest::STATUS_ERROR, Rest::SERVER_ERROR); } }
/** * Modifica los datos del usuario * * @param Player $player */ public function addUser(Player $player) { $query = $this->getConnection()->prepare("INSERT INTO tch_player (username, pass, email, free, seed) \r\n\t\t\t\t\t\t\t\t\t\t\t\t VALUES(:username, :pass, :email, :free, :seed)"); $query->bindValue(":username", $player->getUserName()); //Llamada al método que encripta el password $query->bindValue(":pass", $player->getPassword()); $query->bindValue(":email", $player->getEmail()); $query->bindValue(":free", true); $query->bindValue(":seed", $player->getSeed()); $query->execute(); $updatedRows = $query->rowCount(); return $updatedRows == 1; }