コード例 #1
0
 /**
  * @dataProvider provideInvalidPayloads
  */
 public function testReadMethodInvalidSessionData($invalidPayload)
 {
     $handler = new CookieSessionHandler('test_session');
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $mockCookieJar = new Symfony\Component\HttpFoundation\ParameterBag();
     $mockCookieJar->set('test_session', $invalidPayload);
     $request->cookies = $mockCookieJar;
     $handler->setRequest($request);
     $this->assertEquals('', $handler->read(''));
 }
コード例 #2
0
 /**
  * Update existing library.
  * 
  * @return LibraryModel
  */
 public function update($id)
 {
     if (!$this->input->get('name') || !$this->input->get('path')) {
         return new Response($this->app['translator']->trans('fillInAllFields'), 400);
     }
     $model = $this->model->find($id);
     if (!$model || $model->user_id != Sentry::getUser()->id) {
         return new Response($this->app['translator']->trans('cantEditLibrary'), 403);
     }
     $model->fill(array('name' => $this->input->get('name'), 'path' => $this->input->get('path')))->save();
     return $model;
 }
コード例 #3
0
 /**
  * Apply query parameters to the supplied query builder.
  *
  * @param $builder
  * @param Symfony\Component\HttpFoundation\ParameterBag|League\Fractal\ParamBag $parameters
  * @return mixed
  */
 protected function applyParameters($builder, $parameters = null)
 {
     if (!$parameters) {
         return $builder;
     }
     if ($parameters->get('sort')) {
         $builder = $this->sortBuilder($builder, $parameters);
     }
     if ($parameters->get('limit')) {
         $builder = $this->limitBuilder($builder, $parameters);
     }
     return $builder;
 }
コード例 #4
0
 /**
  * @dataProvider siteAccessMatchProvider
  */
 public function testOnSiteAccessMatch($pathinfo, $semanticPathinfo, SiteAccess $siteaccess, $expectedAccess)
 {
     $container = $this->getContainerMock();
     $container->expects($this->exactly(1))->method('get')->with('ezpublish.siteaccess')->will($this->returnValue($siteaccess));
     $request = $this->getRequestMock();
     $request->expects($this->any())->method('getPathInfo')->will($this->returnValue($pathinfo));
     $request->attributes->set('semanticPathinfo', $semanticPathinfo);
     $mapper = new LegacyMapper();
     $mapper->setContainer($container);
     $bag = new \Symfony\Component\HttpFoundation\ParameterBag();
     $mapper->onBuildKernelWebHandler(new PreBuildKernelWebHandlerEvent($bag, $request));
     self::assertSame($expectedAccess, $bag->get('siteaccess'));
 }
コード例 #5
0
 public function matchReportAction(Logger $log, Request $request)
 {
     $log->addNotice("Match data received from " . $request->getClientIp());
     $teamOneBZIDs = $this->params->get('teamOnePlayers');
     $teamTwoBZIDs = $this->params->get('teamTwoPlayers');
     $teamOnePlayers = $this->bzidsToIdArray($teamOneBZIDs);
     $teamTwoPlayers = $this->bzidsToIdArray($teamTwoBZIDs);
     $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->getId() == $teamTwo->getId()) {
         $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.");
     }
     $match = Match::enterMatch($teamOne->getId(), $teamTwo->getId(), $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('port'), $this->params->get('replayFile'), $this->params->get('mapPlayed'));
     $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()));
     // Output the match stats that will be sent back to BZFS
     return $match->getName();
 }
コード例 #6
0
 /**
  * Save a new template to database.
  * 
  * @return Builder\Themes\ThemesModel
  */
 public function store()
 {
     if (!$this->app['sentry']->getUser()->hasAccess('templates.create')) {
         return new Response($this->app['translator']->trans('noPermTemplateCreate'), 403);
     }
     if (!$this->input->get('name')) {
         return new Response($this->app['translator']->trans('enterNameForTemplate'), 400);
     }
     $exists = $this->model->where('user_id', Sentry::getUser()->id)->where('name', $this->input->get('name'))->first();
     if ($exists) {
         return new Response($this->app['translator']->trans('templateWithNameExists'), 400);
     }
     $rand = str_random(10);
     $this->model->user_id = Sentry::getUser()->id;
     $this->model->name = $this->input->get('name');
     $this->model->color = $this->input->get('color');
     $this->model->category = $this->input->get('category');
     $this->model->thumbnail = 'assets/images/thumbnails/templates/template-' . $rand . '.png';
     if ($this->model->save()) {
         foreach ($this->input->get('pages') as $k => $page) {
             $pModel = new \Builder\Projects\PageModel();
             foreach ($page as $name => $value) {
                 $pModel->{$name} = is_array($value) ? json_encode($value) : $value;
             }
             $this->model->pages()->save($pModel);
         }
         $model = $this->model->with('pages')->find($this->model->id);
         $model->thumbId = $rand;
         return $model;
     }
 }
コード例 #7
0
ファイル: UsersController.php プロジェクト: shomimn/builder
 public function assignPermissionsToAll()
 {
     if (!$this->sentry->getUser()->hasAccess('superuser') || !$this->input->has('permissions')) {
         return new Response($this->app['translator']->trans('noPermissionsGeneric'), 403);
     }
     UserModel::whereNull('permissions')->update(array('permissions' => $this->input->get('permissions')));
     return new Response($this->app['translator']->trans('permissionsUpdated'), 200);
 }
コード例 #8
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);
 }
コード例 #9
0
ファイル: ImagesController.php プロジェクト: shomimn/builder
 /**
  * Delete all images by passed in ids.
  * 
  * @return Response
  */
 public function deleteMultiple()
 {
     if ($this->input->has('ids')) {
         foreach ($this->input->get('ids') as $id) {
             if ($img = $this->model->find($id)) {
                 $this->fs->remove($this->app['base_dir'] . '/assets/images/uploads/' . $img->file_name);
                 $this->model->destroy($id);
             }
         }
     }
     return new Response(json_encode($this->input->get('ids')), 200);
 }
コード例 #10
0
ファイル: ThemesController.php プロジェクト: shomimn/builder
 /**
  * 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);
 }
コード例 #11
0
ファイル: ExportsController.php プロジェクト: shomimn/builder
 /**
  * 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);
 }
コード例 #12
0
ファイル: FoldersController.php プロジェクト: shomimn/builder
 /**
  * Create a new folder.
  * 
  * @return Response
  */
 public function store()
 {
     $folder = $this->model->create(array('user_id' => Sentry::getUser()->id, 'name' => $this->input->get('name')));
     return new Response($folder, 201);
 }