Ejemplo n.º 1
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->get('/tokens', array($this, 'indexAction'))->bind('user_tokens');
     $controllers->get('/tokens/new', array($this, 'newAction'))->bind('user_tokens_new');
     $controllers->post('/tokens/new', array($this, 'newAction'))->bind('user_tokens_new_process');
     $controllers->post('/tokens/{token}/delete', array($this, 'deleteAction'))->bind('user_tokens_delete');
 }
Ejemplo n.º 2
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->get('/programmers/new', array($this, 'newAction'))->bind('programmer_new');
     $controllers->post('/programmers/new', array($this, 'handleNewAction'))->bind('programmer_new_handle');
     $controllers->get('/programmers/choose', array($this, 'chooseAction'))->bind('programmer_choose');
     $controllers->get('/programmers/{nickname}', array($this, 'showAction'))->bind('programmer_show');
     $controllers->post('/programmers/{nickname}/power/up', array($this, 'powerUpAction'))->bind('programmer_powerup');
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function mount(ControllerCollection $controllers)
 {
     $controllers->get('/', [$this, 'indexAction'])->bind('config_index');
     $controllers->get('/edit', [$this, 'editAction'])->bind('config_edit');
     $controllers->post('/edit', [$this, 'updateAction'])->bind('config_update');
     $controllers->get('/repository/{type}/form-fragment/{index}', [$this, 'retrieveRepositoryFormFragmentAction'])->bind('retrieve_repository_form_fragment');
     $controllers->post('/config/build', [$this, 'buildAction'])->bind('config_build');
 }
Ejemplo n.º 4
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->get('/register', array($this, 'registerAction'))->bind('user_register');
     $controllers->post('/register', array($this, 'registerHandleAction'))->bind('user_register_handle');
     $controllers->get('/login', array($this, 'loginAction'))->bind('user_login');
     $controllers->post('/login_check', array($this, 'longCheckAction'))->bind('user_login_check');
     $controllers->get('/logout', array($this, 'logoutAction'))->bind('user_logout');
 }
Ejemplo n.º 5
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->get('/password/generate', [$this, 'generatePassword']);
     $controllers->post('/password/generate', [$this, 'generatePassword']);
     $controllers->get('/password/complication', [$this, 'complicationPassword']);
     $controllers->get('/secret', [$this, 'secret']);
 }
Ejemplo n.º 6
0
 public function connect(Application $app)
 {
     $this->app = $app;
     // api v1
     $api = new ControllerCollection(new Route());
     $api->get('/{model}', __CLASS__ . '::listAction')->assert('model', '^([a-z]+)$');
     $api->get('/{model}/{id}', __CLASS__ . '::itemAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
     $api->delete('/{model}/{id}', __CLASS__ . '::deleteAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
     $api->put('/{model}/{id}', __CLASS__ . '::updateAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
     $api->post('/{model}', __CLASS__ . '::createAction')->assert('model', '^([a-z]+)$');
     //        $model = $this->checkModel('message');
     //
     //        foreach (range(900, 1000) as $id)
     //        {
     //            $message = new $model;
     //
     //            $message->text = $id;
     //            $message->date = time();
     //
     //            $this->dm->persist($message);
     //        }
     //
     //        $this->dm->flush();
     return $api;
 }
Ejemplo n.º 7
0
 protected function addRoutes(ControllerCollection $c)
 {
     $c->get('/login', 'getLogin')->bind('login');
     $c->post('/login', 'postLogin')->bind('postLogin');
     $c->match('/logout', 'logout')->bind('logout');
     $c->get('/resetpassword', 'resetPassword')->bind('resetpassword');
 }
Ejemplo n.º 8
0
 public function connect(Application $app)
 {
     $controllers = new ControllerCollection();
     $controllers->get('auth', function () use($app) {
         if ($app['session']->has($app['config']['prefix'] . 'authed-user')) {
             return $app->redirect('/');
         }
         return $app['twig']->render('PT/pages/authenticate.html', array('auth_path' => $app['uri']->generate('authenticate')));
     })->bind('authenticate');
     $controllers->post('auth', function () use($app) {
         if ($app['request']->get('username') === $app['config']['authenticate']['username'] && $app['request']->get('password') === $app['config']['authenticate']['password']) {
             $userHash = $userHash = sha1($app['config']['authenticate']['username'] . $app['config']['authenticate']['password']);
             $currentUser = $app['session']->set($app['config']['prefix'] . 'authed-user', $userHash);
             return $app->redirect('/');
         } else {
             $app['session']->setFlash('error', 'error');
             $app['session']->remove($app['config']['prefix'] . 'authed-user');
             return $app->redirect($app['uri']->generate('authenticate'));
         }
     })->bind('do_authenticate');
     $controllers->get('deauth', function ($result) use($app) {
         $app['session']->remove($app['config']['prefix'] . 'authed-user');
         return $app->redirect($app['uri']->generate('authenticate'));
     })->value('result', null)->bind('de_authenticate');
     return $controllers;
 }
Ejemplo n.º 9
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->get('/users/new', array($this, 'newAction'))->bind('user_new');
     $controllers->post('/users/new', array($this, 'handleNewAction'))->bind('user_new_handle');
     $controllers->get('/users/choose', array($this, 'chooseAction'))->bind('user_choose');
     $controllers->get('/users/{name}', array($this, 'showAction'))->bind('user_show');
 }
Ejemplo n.º 10
0
 public function connect(Application $app)
 {
     $controllers = new ControllerCollection();
     // *******
     // ** Signup member
     // *******
     $controllers->get('signup.html', function () use($app) {
         $form = $app['form.factory']->create(new \Aperophp\Form\Signup());
         return $app['twig']->render('member/signup.html.twig', array('form' => $form->createView()));
     })->bind('_signupmember');
     // *******
     // *******
     // ** Create member
     // *******
     $controllers->post('create.html', function (Request $request) use($app) {
         $form = $app['form.factory']->create(new \Aperophp\Form\Signup());
         $form->bindRequest($request);
         if ($form->isValid()) {
             $data = $form->getData();
             // TODO save member in database.
             var_dump($data);
             die;
         }
         return $app['twig']->render('member/signup.html.twig', array('form' => $form->createView()));
     })->bind('_createmember');
     // *******
     return $controllers;
 }
Ejemplo n.º 11
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->post('/key', [$this, 'create']);
     $controllers->get('/key/{id}', [$this, 'show']);
     $controllers->put('/key/{id}', [$this, 'update']);
     $controllers->delete('/key/{id}', [$this, 'delete']);
 }
 /**
  * @param ControllerCollection $controllers
  * @return ControllerCollection
  */
 private function setControllerPaths(ControllerCollection $controllers)
 {
     $controllers->get('/{id}', self::READ_REST_CONTROLLER . ':get');
     $controllers->patch('/{id}', self::EDIT_REST_CONTROLLER . ':patch');
     $controllers->get('/', self::READ_REST_CONTROLLER . ':search');
     $controllers->post('/', self::EDIT_REST_CONTROLLER . ':create');
     return $controllers;
 }
Ejemplo n.º 13
0
 protected function addRoutes(ControllerCollection $c)
 {
     $c->method('GET|POST');
     $c->get('/content/deletecontent/{contenttypeslug}/{id}', 'delete')->bind('deletecontent');
     $c->match('/editcontent/{contenttypeslug}/{id}', 'edit')->bind('editcontent')->assert('id', '\\d*')->value('id', '');
     $c->post('/content/{action}/{contenttypeslug}/{id}', 'modify')->bind('contentaction');
     $c->get('/overview/{contenttypeslug}', 'overview')->bind('overview');
     $c->get('/relatedto/{contenttypeslug}/{id}', 'related')->bind('relatedto')->assert('id', '\\d*');
 }
Ejemplo n.º 14
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->post('/api/users', array($this, 'newAction'));
     $controllers->get('/api/users/{name}', array($this, 'showAction'))->bind('api_users_show');
     $controllers->get('/api/users', array($this, 'listAction'));
     $controllers->put('/api/users/{name}', array($this, 'updateAction'));
     $controllers->delete('/api/users/{name}', array($this, 'deleteAction'));
     $controllers->match('api/users/{name}', array($this, 'updateAction'))->method('PATCH');
 }
Ejemplo n.º 15
0
 protected function addRoutes(ControllerCollection $c)
 {
     $c->get('/users', 'admin')->bind('users');
     $c->match('/users/edit/{id}', 'edit')->assert('id', '\\d*')->bind('useredit');
     $c->match('/userfirst', 'first')->bind('userfirst');
     $c->post('/user/{action}/{id}', 'modify')->bind('useraction');
     $c->match('/profile', 'profile')->bind('profile');
     $c->get('/roles', 'viewRoles')->bind('roles');
 }
Ejemplo n.º 16
0
 /**
  *
  *
  * @param ControllerCollection $factory
  * @return null
  */
 public function createRoutes(ControllerCollection $factory)
 {
     $factory->get('/files', [$this, 'get']);
     $factory->get('/files/{hash}', [$this, 'getOne']);
     $factory->post('/files/{hash}', [$this, 'userAction']);
     $factory->delete('/files/{hash}', [$this, 'remove'])->onlyAdmin();
     $factory->put('/files/{hash}', [$this, 'update'])->onlyAdmin();
     $factory->get('/artists', [$this, 'getArtists']);
 }
Ejemplo n.º 17
0
 public function connect(Application $app)
 {
     $controller = new ControllerCollection($app['route_factory']);
     // Element Delete (POST)
     $controller->post('delete', function () use($app) {
         $id = $app['request']->get('elementId');
         $result = $app['repository.element']->delete(array('id' => $id));
         if ($result == 1) {
             return $app->json('OK');
         }
         return $app->json('KO');
     })->bind('route.element.delete');
     return $controller;
 }
Ejemplo n.º 18
0
 protected function addRoutes(ControllerCollection $ctr)
 {
     $ctr->get('/browse/{namespace}/{path}', 'browse')->assert('path', '.*')->value('namespace', 'files')->value('path', '')->bind('asyncbrowse');
     $ctr->get('/file/autocomplete', 'filesAutoComplete')->bind('file/autocomplete');
     $ctr->post('/file/create', 'createFile')->bind('file/create');
     $ctr->post('/file/delete', 'deleteFile')->bind('file/delete');
     $ctr->post('/file/duplicate', 'duplicateFile')->bind('file/duplicate');
     $ctr->post('/file/rename', 'renameFile')->bind('file/rename');
     $ctr->post('/folder/create', 'createFolder')->bind('createfolder');
     $ctr->post('/folder/rename', 'renameFolder')->bind('renamefolder');
     $ctr->post('/folder/remove', 'removeFolder')->bind('removefolder');
     $ctr->get('/recordbrowser', 'recordBrowser')->bind('recordbrowser');
 }
 public function connect(Application $app)
 {
     $controllers = new ControllerCollection();
     $supervisor = new API();
     $servers = (require_once __DIR__ . '/../../config.php');
     $controllers->get('/{server}', function ($server) use($supervisor, $app) {
         //$server_ip = $servers[$server]['ip'];
         $services = $supervisor->getAllProcessInfo('127.0.0.1');
         return $app->json($services);
     });
     $controllers->post('/{server}/{service}', function (Request $request, $server, $service) use($supervisor, $servers, $app) {
         $server_ip = $servers[$server]['ip'];
         if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
             $data = json_decode($request->getContent(), true);
         } else {
             return false;
         }
         $result = false;
         // Get the current state of the service
         $current_service = $supervisor->getProcessInfo('127.0.0.1', $service);
         if (isset($current_service['error'])) {
             $result = $current_service;
         } else {
             if (!(bool) $data['running'] && $current_service['state'] == $supervisor::STATE_RUNNING) {
                 $result = $supervisor->stopProcess('127.0.0.1', $service);
             } else {
                 if ((bool) $data['running'] && $current_service['state'] != $supervisor::STATE_RUNNING) {
                     $result = $supervisor->startProcess('127.0.0.1', $service);
                 }
             }
         }
         if (!$result) {
             $result = array('error' => array('code' => '', 'msg' => 'Error getting details for ' . $service . ' from ' . $server_ip));
         }
         return $app->json($result);
     });
     $controllers->get('/{server}/{service}', function ($server, $service) use($supervisor, $servers, $app) {
         $server_ip = $servers[$server]['ip'];
         return $app->json($supervisor->getProcessInfo('127.0.0.1', $service));
     });
     return $controllers;
 }
Ejemplo n.º 20
0
 protected function addRoutes(ControllerCollection $c)
 {
     $c->get('/dbcheck', 'check')->bind('dbcheck');
     $c->post('/dbupdate', 'update')->bind('dbupdate');
     $c->get('/dbupdate_result', 'updateResult')->bind('dbupdate_result');
 }
 /**
  * Setup the basic crud endpoints for this controller
  * @param ControllerCollection $controller
  * @return ControllerCollection
  */
 public function addCrudOperations(ControllerCollection $controller)
 {
     $controller->get("/search", array($this, "search"));
     $controller->get("/{id}", array($this, "get"));
     $controller->post("/", array($this, "create"));
     $controller->put("/{id}", array($this, "update"));
     $controller->delete("/{id}", array($this, "delete"));
     return $controller;
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function connect(Application $app)
 {
     $modelName = $this->modelName;
     $prefix = sprintf('rest_controller.%s.', $this->modelName);
     if (null !== $this->modelClass) {
         $app[$prefix . 'model_class'] = $this->modelClass;
     }
     if (null !== $this->lastModifiedGetter) {
         $app[$prefix . 'last_modified_getter'] = $this->lastModifiedGetter;
     }
     if (isset($app[$prefix . 'model_class'])) {
         $app[$prefix . 'query_class'] = $app[$prefix . 'model_class'] . 'Query';
     } else {
         throw new \InvalidArgumentException(sprintf('You have to configure the "%s.model_class" parameter.', $prefix));
     }
     $controllers = new ControllerCollection($app['route_factory']);
     /**
      * Returns all objects
      */
     $controllers->get('/', function () use($app, $prefix) {
         $query = new $app[$prefix . 'query_class']();
         return new Response($query->find()->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
     });
     /**
      * Returns a specific object identified by a given id
      */
     $controllers->get('/{id}', function ($id) use($app, $prefix, $modelName) {
         $query = new $app[$prefix . 'query_class']();
         $object = $query->findPk($id);
         if (!$object instanceof $app[$prefix . 'model_class']) {
             throw new NotFoundHttpException(sprintf('%s with id "%d" does not exist.', ucfirst($modelName), $id));
         }
         $response = new Response($object->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
         if (isset($app[$prefix . 'last_modified_getter'])) {
             $response->setLastModified($object->{$app}[$prefix . 'last_modified_getter']());
         }
         return $response;
     });
     /**
      * Create a new object
      */
     $controllers->post('/', function (Request $request) use($app, $prefix) {
         $object = new $app[$prefix . 'model_class']();
         $object->fromArray($request->request->all());
         $object->save();
         return new Response($object->exportTo($app['json_parser']), 201, array('Content-Type' => 'application/json'));
     });
     /**
      * Update a object identified by a given id
      */
     $controllers->put('/{id}', function ($id, Request $request) use($app, $prefix, $modelName) {
         $query = new $app[$prefix . 'query_class']();
         $object = $query->findPk($id);
         if (!$object instanceof $app[$prefix . 'model_class']) {
             throw new NotFoundHttpException(sprintf('%s with id "%d" does not exist.', ucfirst($modelName), $id));
         }
         $object->fromArray($request->request->all());
         $object->save();
         if (isset($app['monolog'])) {
             $app['monolog']->addInfo(sprintf('Update %s with id %d', ucfirst($modelName), $id));
         }
         return new Response($object->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
     });
     /**
      * Delete a object identified by a given id
      */
     $controllers->delete('/{id}', function ($id) use($app, $prefix) {
         $query = new $app[$prefix . 'query_class']();
         $query->filterByPrimaryKey($id)->delete();
         return new Response('', 204, array('Content-Type' => 'application/json'));
     });
     return $controllers;
 }
Ejemplo n.º 23
0
 public function connect(Application $app)
 {
     $controller = new ControllerCollection($app['route_factory']);
     // Part Add (GET)
     $controller->get('add/for/Report/{reportId}', function ($reportId) use($app) {
         $defaultData = array('report_id' => $reportId, 'height' => 10, 'is_visible' => 1, 'is_page_jump' => 0, 'is_indivisible' => 0, 'is_auto_extend' => 0, 'is_auto_reduc' => 0, 'sort_order' => 'asc');
         $form = $app['form.factory']->createBuilder(new \RevPDF\Form\PartType(), $defaultData)->getForm();
         return $app['twig']->render('Part/add.html.twig', array('form' => $form->createView(), 'reportId' => $reportId));
     })->bind('route.part.add');
     // Part Add (POST)
     $controller->post('add', function () use($app) {
         $form = $app['form.factory']->createBuilder(new \RevPDF\Form\PartType())->getForm();
         $form->bind($app['request']);
         $data = $form->getData();
         if ($form->isValid()) {
             try {
                 $result = $app['repository.part']->insert($data);
             } catch (\Exception $e) {
                 $result = false;
                 $app['session']->getFlashBag()->add('warning', $e->getMessage());
             }
             if ($result !== false) {
                 $app['session']->getFlashBag()->add('success', 'message.element_created');
             }
         } else {
             $app['session']->getFlashBag()->add('warning', 'form.invalid.supply');
             return $app->redirect($app['url_generator']->generate('route.part.add', array('locale' => $app['locale'], 'reportId' => $data['report_id'])));
         }
         return $app->redirect($app['url_generator']->generate('route.report.modify', array('locale' => $app['locale'], 'id' => $data['report_id'])));
     })->bind('route.part.create');
     // Part Edit (GET)
     $controller->get('edit/{id}', function ($id) use($app) {
         $part = $app['repository.part']->find($id);
         $builder = $app['form.factory']->createBuilder(new \RevPDF\Form\PartType(), $part);
         $form = $builder->getForm();
         return $app['twig']->render('Part/edit.html.twig', array('form' => $form->createView(), 'reportId' => $part['report_id']));
     })->bind('route.part.edit');
     // Part Update (POST)
     $controller->post('update', function () use($app) {
         $form = $app['form.factory']->createBuilder(new \RevPDF\Form\PartType())->getForm();
         $form->bind($app['request']);
         $data = $form->getData();
         if ($form->isValid()) {
             try {
                 $result = $app['repository.part']->update($data, array('id' => $data['id']));
             } catch (\Exception $e) {
                 $result = false;
                 $app['session']->getFlashBag()->add('warning', $e->getMessage());
             }
             if ($result !== false) {
                 $app['session']->getFlashBag()->add('success', 'message.element_updated');
                 return $app->redirect($app['url_generator']->generate('route.report.modify', array('locale' => $app['locale'], 'id' => $data['report_id'])));
             }
         } else {
             $app['session']->getFlashBag()->add('warning', 'form.invalid.supply');
         }
         return $app['twig']->render('Part/edit.html.twig', array('form' => $form->createView(), 'post' => $data));
     })->bind('route.part.update');
     // Part Delete (GET)
     $controller->get('delete/{id}', function ($id) use($app) {
         $part = $app['repository.part']->find($id);
         $result = $app['repository.part']->delete(array('id' => $id));
         $app['session']->getFlashBag()->add('success', 'message.element_deleted');
         return $app->redirect($app['url_generator']->generate('route.report.modify', array('locale' => $app['locale'], 'id' => $part['report_id'])));
     })->bind('route.part.delete');
     return $controller;
 }
Ejemplo n.º 24
0
 public function connect(Application $app)
 {
     $controller = new ControllerCollection($app['route_factory']);
     // Report Add (GET)
     $controller->get('add', function () use($app) {
         $form = $app['form.factory']->createBuilder(new \RevPDF\Form\ReportType())->getForm();
         return $app['twig']->render('Report/add.html.twig', array('form' => $form->createView()));
     })->bind('route.report.add');
     // Report Add (POST)
     $controller->post('add', function () use($app) {
         $form = $app['form.factory']->createBuilder(new \RevPDF\Form\ReportType())->getForm();
         $form->bind($app['request']);
         $data = $form->getData();
         if ($form->isValid()) {
             try {
                 $result = $app['repository.report']->insert($data);
                 if ($result !== false) {
                     $partInfo = $app['repository.part']->getParts();
                     $defaultProperties = array('is_visible' => 1, 'is_page_jump' => 0, 'is_indivisible' => 0, 'is_auto_extend' => 1, 'is_auto_reduc' => 1, 'sort_order' => 'asc', 'height' => 10, 'report_id' => $app['repository.report']->lastInsertId());
                     $defaultParts = array(array('weight' => 0, 'name' => $partInfo[0]), array('weight' => 5, 'name' => $partInfo[5]));
                     foreach ($defaultParts as $data) {
                         $data = array_merge($data, $defaultProperties);
                         $result = $app['repository.part']->insert($data);
                     }
                 }
             } catch (\Exception $e) {
                 $result = false;
                 $app['session']->getFlashBag()->add('warning', $e->getMessage());
             }
             if ($result !== false) {
                 $app['session']->getFlashBag()->add('success', 'message.element_created');
                 return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
             }
         } else {
             $app['session']->getFlashBag()->add('warning', 'form.invalid.supply');
         }
         return $app['twig']->render('Report/add.html.twig', array('form' => $form->createView(), 'post' => $data));
     })->bind('route.report.create');
     // Report Modify (GET)
     $controller->get('modify/{id}', function ($id) use($app) {
         $report = $app['repository.report']->find($id);
         $report['dimensions'] = $app['repository.application']->getDimensions($report['paper_format'], $report['page_orientation']);
         $sourceFieldsChoices = $app['repository.report']->getColumnsNames($report['source_value']);
         $parts = $app['repository.part']->findAllByReport($id, 'weight asc');
         foreach ($parts as &$part) {
             $part['Elements'] = $app['repository.element']->findAllByPart($part['id']);
         }
         $partForm = $app['form.factory']->createBuilder(new \RevPDF\Form\PartType())->getForm();
         $elementForm = $app['form.factory']->createBuilder(new \RevPDF\Form\ElementType(), null, array('data' => array('sourceFields' => $sourceFieldsChoices, 'deleteElementUrl' => $app['url_generator']->generate('route.element.delete', array('locale' => $app['locale'])))))->getForm();
         return $app['twig']->render('Report/modify.html.twig', array('id' => $id, 'parts' => $parts, 'report' => $report, 'partForm' => $partForm->createView(), 'elementForm' => $elementForm->createView()));
     })->bind('route.report.modify');
     // Report Save (POST)
     $controller->post('save/{reportId}', function ($reportId) use($app) {
         // Json data
         $app['monolog']->addDebug($app['request']->get('serialized'));
         $parts = json_decode($app['request']->get('serialized'));
         if (is_null($parts)) {
             return $app->json(array('status' => 'KO', 'message' => $app['translator']->trans('message.incorrect_json_data')), 500);
         }
         // Save part data
         foreach ($parts as $part) {
             $partLoaded = $app['repository.part']->find($part->partId);
             if (is_array($partLoaded)) {
                 // Save elements
                 $res = $app['repository.element']->saveElements($part->partElementList);
                 $app['monolog']->addDebug('Number of updated/inserted elements: ' . $res);
                 // Save part
                 $partLoaded['height'] = $part->height;
                 $app['repository.part']->update($partLoaded, array('id' => $partLoaded['id']));
             }
         }
         return $app->json(array('status' => 'OK', 'message' => $app['translator']->trans('message.element_updated')), 200);
     })->bind('route.report.save');
     // Report Edit (GET)
     $controller->get('edit/{id}', function ($id) use($app) {
         $report = $app['repository.report']->find($id);
         $builder = $app['form.factory']->createBuilder(new \RevPDF\Form\ReportType(), $report);
         $form = $builder->getForm();
         return $app['twig']->render('Report/edit.html.twig', array('form' => $form->createView()));
     })->bind('route.report.edit');
     // Report Update (POST)
     $controller->post('update', function () use($app) {
         $form = $app['form.factory']->createBuilder(new \RevPDF\Form\ReportType())->getForm();
         $form->bind($app['request']);
         $data = $form->getData();
         if ($form->isValid()) {
             try {
                 $result = $app['repository.report']->update($data, array('id' => $data['id']));
             } catch (\Exception $e) {
                 $result = false;
                 $app['session']->getFlashBag()->add('warning', $e->getMessage());
             }
             if ($result !== false) {
                 $app['session']->getFlashBag()->add('success', 'message.element_updated');
                 return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
             }
         } else {
             $app['session']->getFlashBag()->add('warning', 'form.invalid.supply');
         }
         return $app['twig']->render('Report/edit.html.twig', array('form' => $form->createView(), 'post' => $data));
     })->bind('route.report.update');
     // Report Generate (GET)
     $controller->get('generate/{id}', function ($id) use($app) {
         $report = $app['repository.report']->find($id);
         $parts = $app['repository.part']->findAllByReport($id);
         foreach ($parts as $i => $part) {
             $parts[$i]['Elements'] = $app['repository.element']->findAllByPart($part['id']);
         }
         $data = array();
         $data['report']['shortname'] = $report['short_name'];
         $data['report']['fullname'] = $report['full_name'];
         $data['report']['author'] = $report['author'];
         $data['report']['keywords'] = $report['keywords'];
         $data['report']['subject'] = $report['subject'];
         $data['report']['title'] = $report['title'];
         $data['report']['displayModeZoom'] = $report['display_mode_zoom'];
         $data['report']['displayModeLayout'] = $report['display_mode_layout'];
         $data['report']['comments'] = $report['comments'];
         $data['report']['topMargin'] = $report['top_margin'];
         $data['report']['bottomMargin'] = $report['bottom_margin'];
         $data['report']['rightMargin'] = $report['right_margin'];
         $data['report']['leftMargin'] = $report['left_margin'];
         $data['report']['paperFormat'] = $report['paper_format'];
         $data['report']['pageOrientation'] = $report['page_orientation'];
         if ($report['source_type'] == 'DB') {
             $data['source']['provider'] = 'PdoProvider';
             $data['source']['value'] = $report['source_value'];
         }
         if (count($parts) > 0) {
             foreach ($parts as $part) {
                 $partName = $part['name'];
                 $data[$partName]['height'] = $part['height'];
                 $data[$partName]['isVisible'] = $part['is_visible'];
                 $data[$partName]['backgroundColor'] = $part['color'];
                 $data[$partName]['isPageJump'] = $part['is_page_jump'];
                 $data[$partName]['isIndivisible'] = $part['is_indivisible'];
                 $data[$partName]['isAutoExtend'] = $part['is_auto_extend'];
                 $data[$partName]['isAutoReduc'] = $part['is_auto_reduc'];
                 $data[$partName]['sortOrder'] = $part['sort_order'];
                 if (count($part['Elements']) > 0) {
                     foreach ($part['Elements'] as $element) {
                         $data[$partName]['elements'][] = array('value' => $element['field'], 'type' => strtolower($element['type']), 'format' => $element['format'], 'backcolor' => $element['fill_color'], 'forecolor' => $element['text_color'], 'border' => $element['border'], 'borderWidth' => $element['border_width'], 'x' => $element['posx'], 'y' => $element['posy'], 'width' => $element['width'], 'height' => $element['height'], 'zindex' => $element['zindex'], 'textAlignement' => $element['alignment'], 'font' => array('fontName' => $element['font_family'], 'size' => $element['size'], 'isBold' => strpos($element['style'], 'B') !== false ? 1 : 0, 'isItalic' => strpos($element['style'], 'I') !== false ? 1 : 0, 'isUnderline' => strpos($element['style'], 'U') !== false ? 1 : 0));
                     }
                 }
             }
         }
         $lib = new $app['lib']['instance']();
         $lib->setDataSource($app['db']->getWrappedConnection());
         try {
             $response = new Response();
             $lib->export($data);
             $response->headers->set('Content-Type', 'application/pdf');
             return $response;
         } catch (\Exception $e) {
             $app['session']->getFlashBag()->add('warning', 'message.exception_occurred_with_info');
             $app['monolog']->addwarning('[report.generate] Exception: ' . $e->getMessage());
         }
         return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
     })->bind('report.generate');
     // Report Export (GET)
     $controller->get('export/{id}.{format}', function ($format, $id) use($app) {
         $report = $app['repository.report']->find($id);
         $parts = $app['repository.part']->findAllByReport($id);
         foreach ($parts as &$part) {
             $part['Elements'] = $app['repository.element']->findAllByPart($part['id']);
         }
         //var_dump($parts);exit;
         $reportAttributes = array('shortname' => 'short_name', 'fullname' => 'full_name', 'author' => 'author', 'keywords' => 'keywords', 'subject' => 'subject', 'title' => 'title', 'displayModeZoom' => 'display_mode_zoom', 'displayModeLayout' => 'display_mode_layout', 'comments' => 'comments', 'topMargin' => 'top_margin', 'bottomMargin' => 'bottom_margin', 'rightMargin' => 'right_margin', 'leftMargin' => 'left_margin', 'paperFormat' => 'paper_format', 'pageOrientation' => 'page_orientation');
         if ($report['source_type'] == 'DB') {
             $report['provider'] = 'PdoProvider';
         }
         $partAttributes = array('height' => 'height', 'isVisible' => 'is_visible', 'backgroundColor' => 'color', 'isPageJump' => 'is_page_jump', 'isIndivisible' => 'is_indivisible', 'isAutoExtend' => 'is_auto_extend', 'isAutoReduc' => 'is_auto_reduc', 'sortOrder' => 'sort_order');
         $elementAttributes = array('format' => 'format', 'backcolor' => 'fill_color', 'forecolor' => 'text_color', 'border' => 'border', 'borderWidth' => 'border_width', 'x' => 'posx', 'y' => 'posy', 'width' => 'width', 'height' => 'height', 'zindex' => 'zindex', 'textAlignment' => 'alignment');
         $response = new Response($app['twig']->render('Report/export.' . $format . '.twig', array('report' => $report, 'parts' => $parts, 'reportAttributes' => $reportAttributes, 'partAttributes' => $partAttributes, 'elementAttributes' => $elementAttributes)), 200);
         $response->headers->set('Content-Type', 'text/' . $format . '; charset=UTF-8');
         return $response;
     })->bind('report.export')->assert('format', 'xml|json');
     // Report Delete (GET)
     $controller->get('delete/{id}', function ($id) use($app) {
         $result = $app['repository.report']->delete(array('id' => $id));
         $app['session']->getFlashBag()->add('success', 'message.element_deleted');
         return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
     })->bind('route.report.delete');
     return $controller;
 }
Ejemplo n.º 25
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->post('/battles/new', array($this, 'newAction'))->bind('battle_new');
     $controllers->get('/battles/{id}', array($this, 'showAction'))->bind('battle_show');
     $controllers->get('/battles', array($this, 'listAction'))->bind('battle_list');
 }
Ejemplo n.º 26
0
 public function connect(Application $app)
 {
     $app->register(new SecurityServiceProvider());
     $controller = new ControllerCollection($app['route_factory']);
     $app['security.firewalls'] = array('login' => array('pattern' => '^/[a-z]{2}/login$', 'anonymous' => true), 'login_google_openid' => array('pattern' => '^/[a-z]{2}/login/with/google/openid$', 'anonymous' => true), 'login_google_openid' => array('pattern' => '^/[a-z]{2}/login/with/google$', 'anonymous' => true), 'signup' => array('pattern' => '^/[a-z]{2}/signup$', 'anonymous' => true), 'signup_confirmation' => array('pattern' => '^/[a-z]{2}/signup/confirm/[a-zA-Z0-9]+$', 'anonymous' => true), 'secured' => array('pattern' => '^.*$', 'form' => array('login_path' => '/fr/login', 'check_path' => '/login_check'), 'logout' => array('logout_path' => '/logout'), 'users' => $app->share(function () use($app) {
         return new UserProvider($app['db']);
     })));
     $app['security.role_hierarchy'] = array('ROLE_ADMIN' => array('ROLE_USER', 'ROLE_ALLOWED_TO_SWITCH'));
     $app['security.access_rules'] = array(array('^/admin', 'ROLE_ADMIN'));
     /**
      * Route : show login forms
      */
     $controller->match('/{locale}/login', function (Request $request) use($app) {
         $form = $app['form.factory']->createBuilder(new UserLoginType())->getForm();
         $formSSO = $app['form.factory']->createBuilder(new UserLoginOpenIDType())->getForm();
         return $app['twig']->render('Security/login.html.twig', array('form' => $form->createView(), 'formSSO' => $formSSO->createView(), 'error' => $app['security.last_error']($request), 'last_username' => $app['session']->get('_security.last_username')));
     })->bind('route.user.login');
     $controller->match('/logout', function (Request $request) use($app) {
         $app['session']->clear();
     })->bind('route.user.logout');
     /**
      * Route : show signup form
      */
     $controller->get('/{locale}/signup', function (Request $request) use($app) {
         $form = $app['form.factory']->createBuilder(new UserSignupType())->getForm();
         return $app['twig']->render('Security/signup.html.twig', array('form' => $form->createView()));
     })->bind('route.user.signup');
     /**
      * Route : confirmation link to activate an account using token
      */
     $controller->get('/{locale}/signup/confirm/{confirmationToken}', function (Request $request) use($app) {
         $confirmationToken = $app['request']->get('confirmationToken');
         if (!is_null($confirmationToken)) {
             $user = $app['repository.user']->findByConfirmationToken($confirmationToken);
             if ($user && $user->isEnabled() == 0) {
                 $data['enabled'] = 1;
                 $data['confirmation_token'] = null;
                 $app['repository.user']->update($data, array('id' => $user->getId()));
                 $app['monolog']->addDebug(sprintf('Account activated: %s (%d)', $user->getUsername(), $user->getId()));
                 $app['session']->getFlashBag()->add('warning', 'message.user.signup.success_enabling_account');
                 return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
             }
         }
         $app['monolog']->addDebug('Account has NOT been enabled or is already enabled');
         $app['session']->getFlashBag()->add('warning', 'message.user.signup.failed_enabling_account');
         return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
     })->bind('route.user.register.confirmation');
     $controller->post('/{locale}/signup', function (Request $request) use($app) {
         $form = $app['form.factory']->createBuilder(new UserSignupType())->getForm();
         $form->bind($app['request']);
         $data = $form->getData();
         if ($form->isValid()) {
             $app['monolog']->addDebug('Checking existing user with mail: ' . $data['mail']);
             $userProvider = new UserProvider($app['db']);
             $isUserExist = $this->checkUserExist($userProvider, $data['mail']);
             if ($isUserExist) {
                 $user = $userProvider->loadUserByUsername($data['mail']);
                 if (!$user->isEnabled()) {
                     $app['monolog']->addDebug('User exists but not enabled');
                     $app['session']->getFlashBag()->add('warning', 'message.user.signup.user_already_exist_but_not_validated');
                     return $app['twig']->render('Security/signup.html.twig', array('form' => $form->createView(), 'post' => $data));
                 } else {
                     $app['monolog']->addDebug('User already exists with this mail');
                     $app['session']->getFlashBag()->add('warning', 'message.user.signup.user_already_exist');
                     return $app['twig']->render('Security/signup.html.twig', array('form' => $form->createView(), 'post' => $data));
                 }
             } else {
                 $app['monolog']->addDebug('user doesnt exist');
                 $splittedFullname = explode(' ', $data['fullname'], 2);
                 unset($data['fullname']);
                 $data['firstname'] = isset($splittedFullname[0]) ? ucfirst($splittedFullname[0]) : '';
                 $data['lastname'] = isset($splittedFullname[1]) ? ucfirst($splittedFullname[1]) : '';
                 $data['roles'] = 'ROLE_USER';
                 $data['enabled'] = false;
                 $app['monolog']->addDebug('Adding new user with those values: ' . json_encode($data));
                 $resCreateUser = $this->createUser($app, $data['firstname'], $data['lastname'], $data['roles'], $data['enabled'], $data['mail'], $data['password']);
                 if ($resCreateUser <= 0) {
                     $app['monolog']->addDebug('User cannot be created');
                     $app['session']->getFlashBag()->add('warning', 'Your account has not been created. Please try again.');
                     return $app['twig']->render('Security/signup.html.twig', array('form' => $form->createView(), 'post' => $data));
                 }
             }
             // refresh User with all data from DB
             $user = $userProvider->loadUserByUsername($data['mail']);
             $app['monolog']->addDebug('User created');
             $template = $app['twig']->loadTemplate('Security/Mail/mail/signup.html.twig');
             $mailData = array('message_mail_activate_account' => $app['translator']->trans('message.mail.activate_account'), 'message_mail_intro' => $app['translator']->trans('message.mail.intro'), 'message_mail_ready_to_activate_account' => $app['translator']->trans('message.mail.ready_to_activate_account'), 'message_mail_click_here' => $app['translator']->trans('message.mail.click_here'), 'message_mail_href_validation' => $app['request']->getSchemeAndHttpHost() . $app['url_generator']->generate('route.user.register.confirmation', array('locale' => $app['locale'], 'confirmationToken' => $user->getConfirmationToken())));
             $bodyHtml = $template->renderBlock('body_html', $mailData);
             $bodyText = $template->renderBlock('body_text', $mailData);
             $message = \Swift_Message::newInstance()->setSubject($app['translator']->trans('lbl.mail.subject.account_confirmation'))->setFrom(array($app['mailer.config.from']))->setTo(array($data['mail']))->setBody($bodyText, 'text/plain')->addPart($bodyHtml, 'text/html');
             $app['mailer']->send($message);
             $app['session']->getFlashBag()->add('success', 'message.user.signup_successful');
             $app['session']->getFlashBag()->add('success', $app['translator']->trans('message.user.signup.please_validate_your_account', array('%mail%' => $data['mail'])));
             return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
         }
         $app['session']->getFlashBag()->add('warning', 'form.invalid.supply');
         return $app['twig']->render('Security/signup.html.twig', array('form' => $form->createView(), 'post' => $data));
     })->bind('route.user.register');
     $controller->match('/{locale}/login/with/google', function (Request $request) use($app) {
         $formSSO = $app['form.factory']->createBuilder(new UserLoginOpenIDType())->getForm();
         $formSSO->bind($app['request']);
         $data = $formSSO->getData();
         if (!$app['session']->has('username')) {
             $openid = new LightOpenID($_SERVER['SERVER_NAME']);
             if (!$openid->mode) {
                 $openid->identity = $data['openid_identifier'];
                 $openid->required = array('email' => 'contact/email', 'firstname' => 'namePerson/first', 'lastname' => 'namePerson/last');
                 return $app->redirect($openid->authUrl());
             } else {
                 // Provider returns valid data
                 if ($openid->validate()) {
                     $attributes = $openid->getAttributes();
                     $app['monolog']->addDebug('Successfully logged in using openid');
                     $userProvider = new UserProvider($app['db']);
                     $isUserExist = $this->checkUserExist($userProvider, $attributes['contact/email']);
                     if ($isUserExist) {
                         $user = $userProvider->loadUserByUsername($attributes['contact/email']);
                         if (!$user->isEnabled()) {
                             $app['monolog']->addDebug('User exists but not enabled');
                             $app['session']->getFlashBag()->add('warning', 'message.user.signup.user_already_exist_but_not_validated');
                             $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
                         } else {
                             $token = new UsernamePasswordToken($user, $user->getPassword(), 'secured', $user->getRoles());
                             $app['session']->set('_security_secured', serialize($token));
                             $app['session']->set('username', $user->getUsername());
                         }
                     } else {
                         $data = array();
                         $data['signupProvider'] = 'google';
                         $data['firstname'] = $attributes['namePerson/first'];
                         $data['lastname'] = $attributes['namePerson/last'];
                         $data['roles'] = 'ROLE_USER';
                         $data['mail'] = $attributes['contact/email'];
                         $data['enabled'] = true;
                         $data['password'] = '';
                         $app['monolog']->addDebug('Adding new user with those values: ' . json_encode($data));
                         $resCreateUser = $this->createUser($app, $data['firstname'], $data['lastname'], $data['roles'], $data['enabled'], $data['mail'], $data['password'], $data['signupProvider']);
                         if ($resCreateUser <= 0) {
                             $app['monolog']->addDebug('User cannot be created');
                             $app['session']->getFlashBag()->add('warning', 'message.user.signup.account_has_not_been_created');
                             return $app['twig']->render('Security/login.html.twig', array('form' => $formSSO->createView(), 'post' => $data));
                         }
                         $userProvider = new UserProvider($app['db']);
                         $isUserExist = $this->checkUserExist($userProvider, $attributes['contact/email']);
                         if ($isUserExist) {
                             $user = $userProvider->loadUserByUsername($attributes['contact/email']);
                             $token = new UsernamePasswordToken($user, $user->getPassword(), 'secured', $user->getRoles());
                             $app['session']->set('_security_secured', serialize($token));
                             $app['session']->set('username', $user->getUsername());
                         }
                     }
                 } else {
                     return $app->redirect($openid->authUrl());
                 }
             }
         }
         if (isset($app['auth']) && !$app['auth']($app['session']->get('username'))) {
             $app['monolog']->addDebug('Something got wrong with authentification');
             return new Response($app['twig']->render('500.html.twig'), 403);
         }
         $app['twig']->addGlobal('username', $app['session']->get('username'));
         $app['session']->getFlashBag()->add('success', $app['translator']->trans('message.user.loggedin.as', array('%username%' => $app['session']->get('username'))));
         return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale'])));
     })->bind('route.user.check_login_sso');
     return $controller;
 }
Ejemplo n.º 27
0
 /**
  * Mapeia uma rota de ExtDirect em um controlador.
  *
  * @param Direct $direct
  * @param \Silex\ControllerCollection $controller
  * @param String $controllerService
  * @param \ReflectionClass $reflectionClass
  * @param \ReflectionMethod $reflectionMethod
  * @param Array $beforeFilters
  * @param Array $afterFilters
  */
 private function mapDirectRoute($direct, $controller, $controllerService, $reflectionClass, $reflectionMethod, $beforeFilters, $afterFilters)
 {
     $app = $this->app;
     $method = $reflectionMethod->getName();
     $callback = function (Request $request) use($controllerService, $app, $method) {
         return $app[$controllerService]->{$method}($request);
     };
     $ctr = $controller->post($method, $callback)->direct($direct->form);
     if (!empty($beforeFilters)) {
         foreach ($beforeFilters->methods as $method) {
             $this->addFilter($method, 'before', $ctr, $controllerService, $reflectionClass);
         }
     }
     if (!empty($afterFilters)) {
         foreach ($afterFilters->methods as $method) {
             $this->addFilter($method, 'after', $ctr, $controllerService, $reflectionClass);
         }
     }
 }
Ejemplo n.º 28
0
 /**
  * @param Server $app
  *
  * @return ControllerCollection
  */
 public function connect(Server $app)
 {
     $_controllers = new ControllerCollection();
     //*************************************************************************
     //* GET
     //*************************************************************************
     $_controllers->get('/{id}', function (Application $app, $id) {
         if (!isset($id)) {
             throw new \InvalidArgumentException('You must specify an "id".');
         }
         //	Have to base64 encode id cuz it's funky
         $_id = base64_decode(urldecode($id));
         \Kisma\Utility\Log::trace('get /contact/' . $_id);
         $_controller = new ContactsController();
         if (null !== ($_result = $_controller->findById($_id))) {
             return $_controller->createResponse($_id, $_result);
         }
         return new Response('you suck Not found');
     });
     //*************************************************************************
     //* POST
     //*************************************************************************
     $_controllers->post('/', function (Application $app) {
         $_returnUrl = $app['request']->get('return_url');
         $_id = $app['request']->get('id');
         if (!isset($_id)) {
             throw new \InvalidArgumentException('You must specify an "id".');
         }
         $_id = base64_decode(urldecode($_id));
         \Kisma\Utility\Log::trace('post /contact/' . ($_id ?: '[NEW]') . print_r($_POST, true));
         $_controller = new ContactsController();
         if (null === ($_result = $_controller->findById($_id))) {
             //	Ajax request? Return a JSON response
             if ('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
                 return $_controller->createResponse($_id, 'Contact not found!', 404);
             }
             return 'Contact not found!';
         }
         //	Copy to id as well
         $_POST['id'] = $_id;
         try {
             $_result = $_controller->updateContact(new \Teledini\Components\Contacts\GenericContact($_POST));
             \Kisma\Utility\Log::trace('post result: ' . print_r($_result, true));
             $_SESSION['contact_post_result'] = $_result;
         } catch (\Exception $_ex) {
             //	Error
             \Kisma\Utility\Log::error('Exception saving contact: ' . $_ex->getMessage());
         }
         //	Ajax request? Return a JSON response
         if ('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
             return $_controller->createResponse($_id, 'Contact updated.');
         }
         if ($_returnUrl) {
             //	Redirect
             header('Location: ' . $_returnUrl);
             die;
         }
     });
     //*************************************************************************
     //* DELETE
     //*************************************************************************
     $_controllers->delete('/{id}', function (Application $app, $id) {
         $_returnUrl = $app['request']->get('return_url');
         $_id = $app['request']->get('id');
         if (!isset($_id)) {
             throw new \InvalidArgumentException('You must specify an "id".');
         }
         $_id = base64_decode(urldecode($_id));
         \Kisma\Utility\Log::trace('post /contact/' . ($_id ?: '[NEW]') . print_r($_POST, true));
         $_controller = new ContactsController();
         if (null === ($_result = $_controller->findById($_id))) {
             //	Ajax request? Return a JSON response
             if ('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
                 return $_controller->createResponse($_id, 'Contact not found!', 404);
             }
             return 'Contact not found!';
         }
         //	Copy to id as well
         $_POST['id'] = $_id;
         try {
             $_result = $_controller->updateContact(new \Teledini\Components\Contacts\GenericContact($_POST));
             \Kisma\Utility\Log::trace('post result: ' . print_r($_result, true));
             $_SESSION['contact_post_result'] = $_result;
         } catch (\Exception $_ex) {
             //	Error
             \Kisma\Utility\Log::error('Exception saving contact: ' . $_ex->getMessage());
         }
         //	Ajax request? Return a JSON response
         if ('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
             return $_controller->createResponse($_id, 'Contact updated.');
         }
         if ($_returnUrl) {
             //	Redirect
             header('Location: ' . $_returnUrl);
             die;
         }
     });
     return $_controllers;
 }
Ejemplo n.º 29
0
 protected function addRoutes(ControllerCollection $c)
 {
     $c->method('POST');
     $c->post('/content/{action}', 'action')->bind('contentaction');
 }
Ejemplo n.º 30
0
 protected function addRoutes(ControllerCollection $ctrl)
 {
     $ctrl->get('/login', [$this, 'login']);
     $ctrl->post('/render-richtext', [$this, 'renderRichText'])->mustBeAjax();
 }