Beispiel #1
0
 /**
  * Update an existing project.
  * 
  * @param  sting/int $id
  * @return Response
  */
 public function update($id)
 {
     if (!$this->app['sentry']->getUser()->hasAccess('projects.update')) {
         return new Response($this->app['translator']->trans('noPermProjectUpdate'), 403);
     }
     $p = $this->creator->update($this->input->all());
     if (!$p) {
         return new Response($this->app['translator']->trans('problemUpdatingProject'), 500);
     }
     return new Response(json_encode($p), 200);
 }
 public function matchReportAction(Logger $log, Request $request)
 {
     $log->addNotice("Match data received from " . $request->getClientIp());
     $log->addDebug("Debug match data query: " . http_build_query($this->params->all()));
     $matchType = $this->params->get('matchType', Match::OFFICIAL);
     $teamOneBZIDs = $this->params->get('teamOnePlayers');
     $teamTwoBZIDs = $this->params->get('teamTwoPlayers');
     $teamOnePlayers = $this->bzidsToIdArray($teamOneBZIDs);
     $teamTwoPlayers = $this->bzidsToIdArray($teamTwoBZIDs);
     if (Match::OFFICIAL === $matchType) {
         $teamOne = $this->getTeam($teamOnePlayers);
         $teamTwo = $this->getTeam($teamTwoPlayers);
         // If we fail to get the the team ID for either the teams or both reported teams are the same team, we cannot
         // report the match due to it being illegal.
         // An invalid team could be found in either or both teams, so we need to check both teams and log the match
         // failure respectively.
         $error = true;
         if (!$teamOne->isValid()) {
             $log->addNotice("The BZIDs ({$teamOneBZIDs}) were not found on the same team. Match invalidated.");
         } elseif (!$teamTwo->isValid()) {
             $log->addNotice("The BZIDs ({$teamTwoBZIDs}) were not found on the same team. Match invalidated.");
         } else {
             $error = false;
         }
         if ($error) {
             throw new ForbiddenException("An invalid player was found during the match. Please message a referee to manually report the match.");
         }
         if ($teamOne->isSameAs($teamTwo)) {
             $log->addNotice("The '" . $teamOne->getName() . "' team played against each other in an official match. Match invalidated.");
             throw new ForbiddenException("Holy sanity check, Batman! The same team can't play against each other in an official match.");
         }
     } elseif (Match::FUN === $matchType) {
         if (count($teamOnePlayers) < 2 || count($teamTwoPlayers) < 2) {
             throw new ForbiddenException("You are not allowed to report a match with less than 2 players per team.");
         }
     }
     $map = Map::fetchFromAlias($this->params->get('mapPlayed'));
     $match = Match::enterMatch(isset($teamOne) ? $teamOne->getId() : null, isset($teamTwo) ? $teamTwo->getId() : null, $this->params->get('teamOneWins'), $this->params->get('teamTwoWins'), $this->params->get('duration'), null, $this->params->get('matchTime'), $teamOnePlayers, $teamTwoPlayers, $this->params->get('server'), $this->params->get('replayFile'), $map->getId(), $this->params->get('matchType'), $this->params->get('teamOneColor'), $this->params->get('teamTwoColor'));
     $log->addNotice("Match reported automatically", array('winner' => array('name' => $match->getWinner()->getName(), 'score' => $match->getScore($match->getWinner())), 'loser' => array('name' => $match->getLoser()->getName(), 'score' => $match->getScore($match->getLoser())), 'eloDiff' => $match->getEloDiff(), 'type' => $matchType, 'map' => $map->getName()));
     // Output the match stats that will be sent back to BZFS
     return $match->getName();
 }
Beispiel #3
0
 /**
  * Register a new user.
  * 
  * @return Response
  */
 public function store()
 {
     //if registration is disabled and we don't have logged in admin, bail
     if (!$this->app['settings']['enable_registration'] && !$this->sentry->getUser()->hasAccess('users.create')) {
         return new Response($this->app['translator']->trans('registrationDisabled'), 403);
     }
     //if basic validation fails return errors
     if ($this->validator->fails($this->input->all(), 'register')) {
         return new Response(json_encode($this->validator->errors), 400);
     }
     //create a new user
     try {
         $user = $this->creator->create($this->input->all());
     } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
         return new Response(json_encode(array('email' => $this->app['translator']->trans('emailTaken'))), 400);
     }
     $response = new Response($user, 200);
     //set cookie on response with new user data
     $response->headers->setCookie(new Cookie('blUser', $user, 0, '/', null, false, false));
     return $response;
 }
Beispiel #4
0
 /**
  * Save a new theme.
  * 
  * @return void
  */
 public function store()
 {
     if (!$this->app['sentry']->getUser()->hasAccess('themes.create')) {
         return new Response($this->app['translator']->trans('noPermThemeCreate'), 403);
     }
     $name = $this->input->get('name');
     $data = $this->input->get('theme');
     $vars = $this->input->get('vars', array());
     //make sure we got a name passed in
     if (!$name) {
         return new Response($this->app['translator']->trans('enterNameForTheme'), 400);
     }
     $byName = $this->model->where('name', $name)->first();
     //if we have an id it means we're gonna need to edit an existing theme
     if (isset($data['id'])) {
         $byId = $this->model->find($data['id']);
         if ($byName && $byName->name != $byId->name) {
             return new Response($this->app['translator']->trans('themeWithNameExists'), 400);
         }
         if ($byId && Sentry::getUser()->id == $byId->user_id) {
             return new Response($this->theme->update($byId, $this->input->all()));
         }
     } else {
         //update if theme is created by currently logged in user or return an error
         if ($byName && Sentry::getUser()->id == $byName->user_id) {
             return new Response($this->theme->update($byName, $this->input->all()));
         } elseif ($byName) {
             return new Response($this->app['translator']->trans('themeWithNameExists'), 400);
         }
     }
     //if we didn't return by this point we'll just create a new theme with given data
     try {
         $this->theme->create($this->input->all());
     } catch (\Less_Exception_Compiler $e) {
         return new Response($this->app['translator']->trans('errorInTheme'), 400);
     }
     return new Response($this->model, 201);
 }
Beispiel #5
0
 /**
  * Export project to remote ftp.
  * 
  * @param  string|int $id
  * @return Response
  */
 public function exportProjectToFtp($id)
 {
     if (!$this->app['sentry']->getUser()->hasAccess('publish')) {
         return new Response($this->app['translator']->trans('noPermissionsGeneric'), 403);
     }
     if (!$this->input->get('host')) {
         return new Response($this->app['translator']->trans('ftpNoHost'), 400);
     }
     if (!$this->input->get('user')) {
         return new Response($this->app['translator']->trans('ftpNoUsername'), 400);
     }
     if (!$this->input->get('password')) {
         return new Response($this->app['translator']->trans('ftpNoPassword'), 400);
     }
     if (!$this->input->get('root')) {
         return new Response($this->app['translator']->trans('ftpNoFolder'), 400);
     }
     try {
         @$this->export->projectToFtp($id, $this->input->all());
     } catch (\Exception $e) {
         return new Response($e->getMessage(), 400);
     }
     return new Response($this->app['translator']->trans('projectExportSuccess'), 200);
 }