/** * / * @param [type] $app [description] * @return [type] [description] */ public function route($app) { $app->view->setLayout('frontend'); $app->get('/login', function () use($app) { $app->render('login'); })->name('user_login_form'); $app->post('/login', function () use($app) { $credentials = $app->handler->handlePostRequest(); $app->doorman->login($credentials); if ($app->doorman->isUserAuthenticated()) { $app->redirect('admin_panel'); } else { $app->redirect('user_login_form'); } })->name('user_login'); $app->get('/signup', function () use($app) { $app->render('signup'); })->name('user_signup_form'); $app->post('/signup', function () use($app) { $record = new Record($app->request->post()); $token = User::query($app->db, 'signUp', $record); $sent = $app->handler->sendSignUpConfirmation($record, $token); $app->redirect('user_login_form'); })->name('user_signup'); $app->get('/signup/confirm/:token', function ($user_id, $token) use($app) { $result = User::query($app->db, 'validate', $token, 'activation'); if ((int) $result->isSuccessful()) { $app->redirect('user_login'); } $app->errorForbidden(); })->name('confirm_signup')->conditions(array('token' => '\\w+')); $app->get('/password/forgot', function () use($app) { $app->render('password.forgot'); })->name('forgot_password_form'); $app->post('/password/forgot', function () use($app) { $record = new Record($app->request->post()); $token = User::query($app->db, 'forgot', $record->get('user_id')); $sent = $app->handler->sendPasswordReset($record, $token); $app->redirect('user_login_form'); })->name('forgot_password'); $app->get('/password/new/:token', function ($token) use($app) { $result = User::query($app->db, 'validate', $token, 'forgot'); if ($result->isSuccessful()) { $app->render('password.new'); $app->stop(); } else { $app->handler->errorForbidden(); } })->name('new_password_form')->conditions(array('token' => '\\w+')); $app->post('/password/new', function () use($app) { $record = new Record($app->request->post()); $result = User::query($app->db, 'resetPassword', $record->get('new_password')); $app->redirect($app->urlFor('user_login_form')); })->name('new_password'); return $app; }
/** * / * @param [type] $app [description] * @return [type] [description] */ public function route($app) { $app->post('/api/calendar', function () use($app) { }); $app->get('/api/event/:id', function () use($app) { }); $app->post('/api/event/save', function () use($app) { }); return $app; }
/** * / * @param [type] $app [description] * @return [type] [description] */ public function route($app) { $app->get('', function () use($app) { }); $app->post('', function () use($app) { }); }
/** * / * @param [type] $app [description] * @return [type] [description] */ public function route($app) { /* * UPLOAD */ $app->get('/upload', function () use($app) { $app->render('upload'); }); $app->post('/upload', function () use($app) { $validator = new \FileUpload\Validator\Simple(1024 * 1024 * 2, $app->allowedFileTypes); $pathresolver = new \FileUpload\PathResolver\Simple('/var/www/html/files/'); $filesystem = new \FileUpload\FileSystem\Simple(); $fileupload = new \FileUpload\FileUpload($_FILES['files'], $_SERVER); $fileupload->setPathResolver($pathresolver); $fileupload->setFileSystem($filesystem); $fileupload->addValidator($validator); list($files, $headers) = $fileupload->processAll(); foreach ($headers as $header => $value) { $app->response->headers->set($header . ': ' . $value); } $body = json_encode(array('files' => $files)); $app->response->setBody($body); $app->stop(); }); return $app; }
/** * [sendRequest description]. * * @return [type] [description] */ public function sendRequest() { if ($this->error->hasError() || !$this->http) { return; } if (class_exists($this->dispatcher)) { $dispatcherClass = $this->dispatcher; $dispatcher = new $dispatcherClass($this->instance->getQuery()); if ($dispatcher instanceof AbstractDispatcher) { $payload = array('data' => json_encode(array('config' => $this->config->getRawConfig(), 'sql' => $this->instance->getQuery()->toString(), 'limit' => $this->instance->getQuery()->getLimit(), 'offset' => $this->instance->getQuery()->getOffset(), 'single' => $this->instance->getQuery()->isSingle())), 'key' => $this->key, 'method' => $this->method); $jsonResult = '[]'; try { // Guzzle Old if (get_class($this->http) == 'Guzzle\\Http\\Client') { $request = $this->http->post($this->url, array(), $payload); $response = $request->send(); $jsonResult = $response->getBody(true); } elseif (get_class($this->http) == 'GuzzleHttp\\Client') { $response = $this->http->request('POST', $this->url, array('form_params' => $payload)); $jsonResult = $response->getBody(); } elseif ($this->http instanceof BuiltinRestClient) { $jsonResult = self::post($this->url, $payload); } if ($this->method == 'getAvailableDrivers') { $this->availableDrivers = json_decode((string) $jsonResult, true); } elseif ($this->method == 'getServerVersion') { $res = json_decode((string) $jsonResult, true); $this->serverVersion = isset($res['version']) ? $res['version'] : null; } else { $dispatcher->dispatch((string) $jsonResult); } } catch (\Exception $e) { $this->error->setMessage(strip_tags($e->getMessage())); } } else { $this->error->setMessage(sprintf('Dispatcher class must be instance of %s, %s given', AbstractDispatcher::class, (string) $this->dispatcher)); } } else { $this->error->setMessage(sprintf('Class %s not found', (string) $this->dispatcher)); } }
/** * / * @param [type] $app [description] * @return [type] [description] */ public function route($app) { $app->view->setLayout($layout); $app->get('/tag/:tag', function ($tag) use($app) { })->name('tag')->conditions(array('' => '')); $app->get('/', function () use($app) { $result = Content::query($app->db, 'findPublished'); $app->view->setData($result); $app->view->render(''); })->name('home'); $app->get('/perfil', function () use($app) { $result = User::query($app->db, 'show', $app->sessionDataStore->getUserId()); $app->view->setData($result); $app->view->render(''); })->name('perfil'); $app->get('/perfil/editar', function () use($app) { $app->view->setData($result); $app->view->render(''); })->name('salvar_perfil'); $app->post('/perfil/salvar', function () use($app) { $record = $app->handler->handlePostRequest(); $app->redirect($app->urlFor('')); })->name('salvar_perfil'); $app->post('/comentar', function () use($app) { $record = $app->handler->handlePostRequest(); $app->redirect($app->urlFor('')); })->name('comentar'); $app->get('/programacao(/:pagina)', function ($pagina = 1) use($app) { $result = Event::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('programacao')->conditions(array('' => '')); $app->get('/evento/:slug/:id', function ($slug, $id) use($app) { $result = Event::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('evento')->conditions(array('' => '')); $app->get('/espacos(/:pagina)', function ($pagina = 1) use($app) { $result = Content::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('espacos')->conditions(array('' => '')); $app->get('/espaco/:slug/:id', function ($slug, $id) use($app) { $result = Content::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('espaco')->conditions(array('' => '')); $app->get('/galerias(/:pagina)', function ($pagina = 1) use($app) { $result = Content::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('galerias')->conditions(array('' => '')); $app->get('/galeria/:slug/:id', function ($slug, $id) use($app) { $result = Content::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('galeria')->conditions(array('' => '')); $app->get('/revista(/:pagina)', function ($pagina = 1) use($app) { $result = Content::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('revista')->conditions(array('' => '')); $app->get('/materia/:slug/:id', function ($slug, $id) use($app) { $result = Content::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('materia')->conditions(array('' => '')); $app->get('/notas(/:pagina)', function ($pagina = 1) use($app) { $result = Content::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('notas')->conditions(array('' => '')); $app->get('/secao/:slug/:id', function ($id) use($app) { $result = Content::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('nota')->conditions(array('' => '')); $app->get('/equipe', function () use($app) { $result = Equipe::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('equipe'); $app->get('/consultas(/:pagina)', function ($pagina = 1) use($app) { $result = ConsultaPublica::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('consultas')->conditions(array('' => '')); $app->get('/consulta/:id', function ($id) use($app) { $result = ConsultaPublica::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('consulta')->conditions(array('' => '')); $app->get('/editais(/:pagina)', function ($pagina = 1) use($app) { $result = Edital::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('editais')->conditions(array('' => '')); $app->get('/edital/:id', function ($id) use($app) { $result = Edital::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('edital')->conditions(array('' => '')); $app->get('/projetos(/:pagina)', function ($pagina = 1) use($app) { $result = Content::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('projetos')->conditions(array('' => '')); $app->get('/projeto/:id', function ($id) use($app) { $result = Content::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('projeto')->conditions(array('' => '')); $app->get('/leis(/:pagina)', function ($pagina = 1) use($app) { $result = LeiIncentivo::query($app->db, 'findPublished', $pagina); $app->view->setData($result); $app->view->render(''); })->name('leis')->conditions(array('' => '')); $app->get('/lei/:id', function ($id) use($app) { $result = LeiIncentivo::query($app->db, 'showPublished', $id); $app->view->setData($result); $app->view->render(''); })->name('lei')->conditions(array('id' => '\\d+')); return $app; }
/** * @param [type] $request [description] * * @return [type] [description] */ public function accessTokenPost($request) { $params = new Set($request->post()); $requiredParams = ['grant_type', 'client_id', 'client_secret', 'redirect_uri', 'code']; //TODO: Use json-schema validator foreach ($requiredParams as $requiredParam) { if (!$params->has($requiredParam)) { throw new \Exception('Parameter ' . $requiredParam . ' is missing!', Resource::STATUS_BAD_REQUEST); } } if ($params->get('grant_type') !== 'authorization_code') { throw new \Exception('Invalid grant_type specified.', Resource::STATUS_BAD_REQUEST); } $collection = $this->getDocumentManager()->getCollection('oAuthTokens'); $cursor = $collection->find(); $cursor->where('code', $params->get('code')); $tokenDocument = $cursor->current(); if (null === $tokenDocument) { throw new \Exception('Invalid code specified!', Resource::STATUS_BAD_REQUEST); } $clientDocument = $tokenDocument->client; if ($clientDocument->getClientId() !== $params->get('client_id') || $clientDocument->getSecret() !== $params->get('client_secret')) { throw new \Exception('Invalid client_id/client_secret combination!', Resource::STATUS_BAD_REQUEST); } if ($params->get('redirect_uri') !== $clientDocument->getRedirectUri()) { throw new \Exception('Redirect_uri mismatch!', Resource::STATUS_BAD_REQUEST); } //Remove one-time code $tokenDocument->setCode(false); $tokenDocument->save(); $this->accessTokens = [$tokenDocument]; $this->single = true; return $tokenDocument; }
/** * / * @param [type] $app [description] * @return [type] [description] */ public function route($app) { /* * USERS */ $app->get('/api/user(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'modified', $order = 'desc') use($app) { $result = User::query($app->db, 'find', $pg, $app->config('per_page'), $key, $order); $app->handler->handleApiResponse($result); })->name('api_user_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => 'asc|desc')); $app->get('/api/user/:id/show', function ($id) use($app) { $result = User::query($app->db, 'show', $id); $app->handler->handleApiResponse($result); })->name('api_user_show')->conditions(array()); $app->get('/api/user/profile', function ($id) use($app) { $result = User::query($app->db, 'show', $app->sessionDataStore->getUserId()); $app->handler->handleApiResponse($result); })->name('api_user_profile'); $app->post('/api/user/delete', function () use($app) { $record = $app->handler->handlePostRequest(); $id = $record->get('id'); $result = User::query($app->db, 'delete', $id); Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'user', $id, 'delete', '', '', $app->nonce->get()); $app->handler->handleApiResponse($result); })->via('POST', 'DELETE')->name('api_user_delete'); $app->map('/api/user/save', function () use($app) { $record = $app->handler->handlePostRequest(); $result = User::query($app->db, 'save', $record); $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId(); Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), $model, $id, 'save', '', '', $app->nonce->get()); $app->handler->handleApiResponse($result); })->via('POST', 'PUT')->name('api_user_save'); /* * TYPES */ $app->get('/api/type(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'name', $order = 'asc') use($app) { $result = Type::query($app->db, 'display'); $app->handler->handleApiResponse($result); })->name('api_type_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => 'asc|desc')); $app->post('/api/type/delete', function () use($app) { $record = $app->handler->handlePostRequest(); $id = $record->get('id'); $result = Type::query($app->db, 'delete', $id); Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'type', $id, 'delete', '', '', $app->nonce->get()); $app->handler->handleApiResponse($result); })->name('api_type_delete'); $app->post('/api/type/save', function () use($app) { $record = $app->handler->handlePostRequest(); $result = Type::query($app->db, 'save', $record); $id = $record->has('id') ? $record->get('id') : $result->get('last.insert.id'); Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), $model, $id, 'save', '', '', $app->nonce->get()); $app->handler->handleApiResponse($result); })->name('api_type_save'); /* * SYSTEM */ $app->get('/api/config', function () use($app) { $result = Config::query($app->db, 'display'); $app->handler->handleApiResponse($result); })->name('api_config_list')->conditions(array()); $app->map('/api/config', function () use($app) { $record = $app->handler->handlePostRequest(); $result = Config::query($app->db, 'save', $record); $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId(); Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'config', $id, 'save', '', '', $app->nonce->get()); $app->handler->handleApiResponse($result); })->via('POST', 'PUT')->name('api_config_save'); $app->get('/api/log(/:pg)', function ($pg = 1) use($app) { $result = Log::query($app->db, 'find', $pg, $app->config('per_page')); $app->handler->handleApiResponse($result); })->name('api_log_list')->conditions(array('pg' => '\\d+')); /* * LANG */ $app->get('/api/lang/:lang', function ($lang) use($app) { $app->session->set('language', $lang); })->name('api_set_lang')->conditions(array('lang' => '\\w+')); /* * NONCE */ $app->get('/api/nonce', function () use($app) { $app->nonce->generate(); $result = new Result(array('success' => true, 'message' => 'Nonce has been generated.', 'nonce' => $app->nonce->get())); $app->handler->handleApiResponse($result); }); return $app; }