Beispiel #1
2
 public function goBack()
 {
     if ($this->request->hasHeader('HTTP_REFERER')) {
         $referer = $this->request->getHeader('HTTP_REFERER')[0];
         return $this->response->withRedirect($referer, 301);
     }
     return $this->goHome();
 }
Beispiel #2
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $teacherId = $req->getParam('teacher_id');
     $teacher = $this->staffService->getTeacherById($teacherId);
     if ($teacher['school_id'] !== $school->id) {
         return $res->withStatus(403, 'No school');
     }
     if ($req->isPost()) {
         $inputFilter = $this->inputFilter;
         $result = $inputFilter($req->getParams());
         if (!$result['is_valid']) {
             $res = $res->withStatus(422);
             $res = $res->withJson($result);
             return $res;
         }
         $this->service->saveAnswers($teacherId, $result['values']);
     }
     $data = $this->service->getAnswers($teacherId);
     $res = $res->withJson($data);
     return $res;
 }
 public function __invoke(Request $request, Response $response, callable $next)
 {
     $request->registerMediaTypeParser('application/json', function ($input) {
         return json_decode($input);
     });
     return $next($request, $response);
 }
Beispiel #4
0
 /**
  * Intermediario entre el Front-End y el servicio.
  *
  * @param Request $request
  *
  * @return []
  */
 public function login($request)
 {
     $result = [];
     $formData = $request->getParsedBody();
     $email = null;
     $password = null;
     // Verificamos que efectivamente exista una entrada de email
     if (array_key_exists("email", $formData)) {
         $email = $formData["email"];
     }
     // Verificamos que efectivamente exista una entrada de password
     if (array_key_exists("password", $formData)) {
         $password = $formData["password"];
     }
     if (isset($email, $password)) {
         $loginResult = $this->userService->login($email, $password);
         if (array_key_exists("error", $loginResult)) {
             $result["error"] = true;
         } else {
             setcookie($this->nombreCookie, true, time() + 3600);
         }
         $result["message"] = $loginResult["message"];
     } else {
         $result["error"] = true;
         $result["message"] = "Email and password can not be empty.";
     }
     return $result;
 }
Beispiel #5
0
 public function listMedia(Request $request, Response $response, $arguments)
 {
     $media = $this->container->MediaService->getAllMedia();
     $media = collect($media)->values();
     $baseUrl = $request->getUri()->getBaseUrl();
     $media = $media->map(function ($item) use($baseUrl) {
         $item['is_image'] = false;
         if ($this->isImage($item)) {
             $imagick = $this->manager->make($item['full_name_with_path']);
             $item['height'] = $imagick->height();
             $item['width'] = $imagick->width();
             $item['is_image'] = true;
         }
         $item['url'] = $baseUrl . '/uploads/' . $item['full_name'];
         if ($this->isPdf($item)) {
             $item['thumbnail'] = $baseUrl . '/api/media/thumbnail/' . $item['full_name'];
         } elseif ($this->isImage($item)) {
             $item['thumbnail'] = $item['url'];
         } else {
             $item['thumbnail'] = null;
         }
         $item['downloadUrl'] = $baseUrl . '/api/media/download/' . $item['full_name'];
         return $item;
     });
     return $response->withJson($media);
 }
Beispiel #6
0
 public function test(Request $request, Response $response, array $args)
 {
     $uid = $args['uid'];
     $myaccount = R::load('accounts', $uid);
     $accountId = $myaccount->accountid;
     $account = R::findOne('accounts', ' accountid = ?', [$accountId]);
     if (!empty($account)) {
         $apiKey = $account['apikey'];
         $type = $account['servertype'];
         $oandaInfo = new Broker_Oanda($type, $apiKey, $accountId);
     } else {
         $this->flash->addMessage('flash', "Oanda AccountId not found");
         return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('homepage'));
     }
     $side = 'buy';
     $pair = 'EUR_USD';
     $price = '1.1400';
     $expiry = time() + 60;
     $stopLoss = '1.1300';
     $takeProfit = NULL;
     $risk = 1;
     //        $side='buy';
     //        $pair='GBP_CHF';
     //        $price='2.1443';
     //        $expiry = $oandaInfo->getExpiry(time()+60);
     //        $stopLoss='2.1452';
     //        $takeProfit=NULL;
     //        $risk=1;
     //$oandaInfo->placeLimitOrder($side,$pair,$price,$expiry,$stopLoss,$takeProfit,$risk);
     $oandaInfo->processTransactions();
 }
 public function rememberme(Request $request)
 {
     if (false === SecurityController::AppAuthorization()) {
         $tockenAccess = false;
         $cookies = $request->getCookieParams();
         foreach ($cookies as $cookie => $value) {
             if ('Rememberme' === $cookie) {
                 $tockenAccess = $value;
                 break;
             }
         }
         /*
         $cookies = explode(';', $request->getHeaders()['HTTP_COOKIE'][0]);
         foreach($cookies As $cookie)
         {
             if(trim(stristr($cookie, '=', true)) === 'Rememberme') {
                 $tockenAccess = trim(substr(stristr($cookie, '=', false), 1));
                 break;
             }
         }
         */
         if (false !== $tockenAccess) {
             $security = new SecurityController();
             return $security->tockenAuthenticate($tockenAccess);
         }
     }
     return false;
 }
Beispiel #8
0
 public function login(Request $request, Response $response, array $args)
 {
     $this->logger->info("Login page action dispatched");
     $username = null;
     $error = null;
     $urlRedirect = $this->router->pathFor('homepage');
     //        if ($request->getAttribute('r') && $request->getAttribute('r') != '/logout' && $request->getAttribute('r') != '/login') {
     //            $_SESSION['urlRedirect'] = $request->getAttribute('r');
     //        }
     if (isset($_SESSION['urlRedirect'])) {
         $urlRedirect = $_SESSION['urlRedirect'];
         unset($_SESSION['urlRedirect']);
     }
     if ($request->isPost()) {
         $username = $request->getParam('username');
         $password = $request->getParam('password');
         $result = $this->authenticator->authenticate($username, $password);
         if ($result->isValid()) {
             //$error = $this->authenticator->getIdentity();
             return $response->withRedirect($urlRedirect);
         } else {
             $messages = $result->getMessages();
             $error = (string) $messages[0];
             //$this->flash->addMessage('flash', $error);
         }
     }
     $this->view->render($response, 'login.twig', ['username' => $username, 'error' => $error]);
     return $response;
 }
Beispiel #9
0
 public function __invoke(Request $req, Response $res, array $args = [])
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $params = $req->getParams();
     $id = $params['id'];
     $params['school_id'] = $school->id;
     if (isset($params['lessons']) && !is_array($params['lessons'])) {
         $params['lessons'] = explode(',', $params['lessons']);
     }
     unset($params['id']);
     try {
         if ($id) {
             $lab = $this->labservice->updateLab($params, $id);
             $res = $res->withStatus(200);
         } else {
             $lab = $this->labservice->createLab($params);
             $res = $res->withStatus(201);
         }
         $res = $res->withJson($lab);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }
Beispiel #10
0
 public function learningcenterRemove(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $db->delete("learningcenter", ["id" => $attr["id"]]);
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/learningcenter");
 }
Beispiel #11
0
 /**
  * This function outputs the given $data as valid HAL+JSON to the client
  * and sets the HTTP Response Code to the given $statusCode.
  *
  * @param array|SlimBootstrap\DataObject $data       The data to output to
  *                                                   the client
  * @param int                            $statusCode The status code to set
  *                                                   in the reponse
  */
 public function write($data, $statusCode = 200)
 {
     $path = $this->_request->getPath();
     $hal = new hal\Hal($path);
     if (true === is_array($data)) {
         $pathData = explode('/', $path);
         unset($pathData[0]);
         $endpointName = end($pathData);
         $endpointUri = '/' . implode('/', $pathData) . '/';
         foreach ($data as $entry) {
             /** @var SlimBootstrap\DataObject $entry */
             $identifiers = $entry->getIdentifiers();
             $resourceName = $endpointUri . implode('/', array_values($identifiers));
             $resource = new hal\Hal($resourceName, $entry->getData() + $entry->getIdentifiers());
             $this->_addAdditionalLinks($resource, $entry->getLinks());
             $hal->addLink($endpointName, $resourceName);
             $hal->addResource($endpointName, $resource);
         }
     } else {
         $hal->setData($data->getData() + $data->getIdentifiers());
         $this->_addAdditionalLinks($hal, $data->getLinks());
     }
     $body = $this->_jsonEncode($hal);
     if (false === $body) {
         $this->_response->setStatus(500);
         $this->_response->setBody("Error encoding requested data.");
         return;
     }
     $this->_headers->set('Content-Type', 'application/hal+json; charset=UTF-8');
     $this->_response->setStatus($statusCode);
     $this->_response->setBody($hal->asJson());
 }
 public function getBody()
 {
     $body = $this->request->getBody();
     if ($body == '') {
         return array();
     }
     return json_decode($body, true);
 }
Beispiel #13
0
 function getMunicipioDepartamento(Request $request, Response $response)
 {
     $response = $response->withHeader('Content-type', 'application/json');
     $id = $request->getAttribute("id");
     $data = Municipio::select("municipio.*", "departamento.nombre as departamento")->join('departamento', 'departamento.id', '=', 'municipio.idDepartamento')->where("municipio.id", "=", $id)->first();
     $response->getBody()->write($data);
     return $response;
 }
Beispiel #14
0
 public function disavantaged_typeRemove(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $db->delete("disavantaged_type", ["id" => $attr["id"]]);
     $db->delete("person_disavantaged", ["disavantaged_id" => $attr["id"]]);
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/disavantaged_type");
 }
 public function productRemove(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $db->delete("product", ["id" => $attr["id"]]);
     $db->delete("person_cripple", ["cripple_id" => $attr["id"]]);
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/product");
 }
 public function promedio(Request $request, Response $response)
 {
     $response = $response->withHeader('Content-type', 'application/json');
     $idCliente = $request->getAttribute("idCliente");
     $query = "SELECT COALESCE(AVG(calificacion),0) as promedio FROM calificacioncliente WHERE idCliente = " . $idCliente;
     $data = DB::select(DB::raw($query));
     $response->getBody()->write(json_encode($data));
     return $response;
 }
Beispiel #17
0
 /**
  * @param Request $request
  * @param UserRepository $userRepository
  * @param Redirector $redirector
  */
 public function __construct(Request $request, UserRepository $userRepository, Redirector $redirector)
 {
     $this->dispname = $request->post('dispname');
     $this->username = $request->post('username');
     $this->password = $request->post('password');
     $this->phone = $request->post('phone');
     $this->userRepository = $userRepository;
     $this->redirector = $redirector;
 }
 /**
  * @param Request $request
  * @param Response $response
  * @return Response
  */
 public function saveAction(Request $request, Response $response) : Response
 {
     $service = new FieldService();
     $entity = (new SampleEntity())->setOne((new Field())->setId(1)->setValue(8))->setTwo($service->getFieldGroup(2))->setThree($service->getFieldGroup(3))->setFour((new Field())->setId(4)->setValue(123));
     $form = $this->formFactory->create(SampleType::class, $entity);
     $form->submit($request->getParams())->isValid();
     $bla = 0;
     return $this->view->render($response, 'field/index.html.twig', ['form' => $form->createView()]);
 }
 function eliminarservicios(Request $request, Response $response)
 {
     $response = $response->withHeader('Content-type', 'application/json');
     $data = json_decode($request->getBody(), true);
     $id = $request->getAttribute("idempleado");
     $tipo = ServiciosEmpleado::select("*")->where("idEmpleado", "=", $id)->delete();
     $response->getBody()->write($tipo);
     return $response;
 }
 function borrartipoturnosucursal(Request $request, Response $response)
 {
     $response = $response->withHeader('Content-type', 'application/json');
     $data = json_decode($request->getBody(), true);
     $id = $request->getAttribute("id");
     $tipo = Tipoturnosucursal::select("*")->where("idsucursal", "=", $id)->delete();
     $response->getBody()->write($tipo);
     return $response;
 }
Beispiel #21
0
 /**
  * display a static page
  *
  * @param Request $request
  * @param Response $response
  * @return Response
  */
 public function display(Request $request, Response $response)
 {
     try {
         $res = $this->render($response, sprintf('pages/%s.html', $request->getAttribute('page', 'home')));
     } catch (\Exception $e) {
         $res = $this->render($response, 'errors/404.html');
     }
     return $res;
 }
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $this->service->setTotalTeachers($school->id, (int) $req->getParam('total_teachers', 0));
     return $res->withStatus(204);
 }
Beispiel #23
0
 /**
  * @param View $view
  * @param Request $request
  * @param UserRepository $userRepository
  * @param Session $session
  * @param Redirector $redir
  */
 public function __construct(View $view, Request $request, UserRepository $userRepository, Session $session, Redirector $redir)
 {
     $this->view = $view;
     $this->username = $request->post('username');
     $this->password = $request->post('password');
     $this->userRepository = $userRepository;
     $this->session = $session;
     $this->redir = $redir;
 }
Beispiel #24
0
 /**
  * Execute the middleware.
  *
  * @param Request  $request
  * @param Response $response
  * @param callable $next
  *
  * @return Response
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     $response = $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', ['Content-Type'])->withHeader('Access-Control-Allow-Methods', ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']);
     if ($request->isOptions()) {
         return $response;
     }
     // Call next middleware
     return $next($request, $response);
 }
Beispiel #25
0
 /**
  * Execute the middleware.
  *
  * @param Request  $request
  * @param Response $response
  * @param callable $next
  *
  * @return Response
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     $server = $request->getServerParams();
     $requestTime = $server['REQUEST_TIME_FLOAT'] ?? microtime(true);
     // Call next middleware
     $response = $next($request, $response);
     $executionTime = microtime(true) - $requestTime;
     return $response->withHeader(self::HEADER, sprintf('%.3f', $executionTime));
 }
Beispiel #26
0
 public function anyLogout(Request $req, Response $res)
 {
     $container = $this->slim->getContainer();
     /** @var Aura\Session\Session */
     $session = $container->session;
     $loginSegment = $session->getSegment("login");
     $loginSegment->clear();
     $session->commit();
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/login");
 }
Beispiel #27
0
 /**
  *
  */
 public static function getTokenId(\Slim\Http\Request $req)
 {
     $auth = $req->getHeaderLine('Authorization');
     $hasBearer = preg_match('|Bearer (.+)|', $auth, $m);
     if (!$hasBearer) {
         return false;
     }
     $tokenId = $m[1];
     return $tokenId;
 }
 public function edit(Request $request, Response $response, array $args)
 {
     $input = $request->getParsedBody();
     /** @var MemberPortfolios $portfolio */
     $portfolio = $this->data(MemberPortfolios::class);
     $validator = $this->validator->rule('required', ['company_name', 'industry_id', 'start_date_y', 'work_status', 'job_title', 'job_desc']);
     if ($input['work_status'] == 'R') {
         $validator->rule('required', 'end_date_y');
     }
     if ($validator->validate()) {
         if ($input['work_status'] == 'A') {
             unset($input['end_date_y'], $input['end_date_m'], $input['end_date_d']);
         }
         try {
             $update = $portfolio->update($input, (int) $args['id']);
             $message = 'Item portfolio berhasil diperbaharui. Selamat!';
         } catch (\PDOException $e) {
             $update = false;
             $message = 'System error!<br>' . $e->getMessage();
         }
         $this->addFormAlert($update !== false ? 'success' : 'error', $message);
     } else {
         $this->addFormAlert('warning', 'Some of mandatory fields is empty!', $validator->errors());
         return $response->withRedirect($this->router->pathFor('membership-portfolios-edit', $args));
     }
     return $response->withRedirect($this->router->pathFor('membership-account'));
 }
 public function getSlimView(\Slim\Http\Request $request)
 {
     if ($request->isAjax() || $request->isXhr() || $request->get('format', '') == 'json' || $request->post('format', '') == 'json') {
         return $this->slimViewFactory->getJsonSlimView();
     }
     return $this->slimViewFactory->getHtmlSlimView();
 }
Beispiel #30
-1
 public function editRota(Request $request, Response $response, array $args)
 {
     $id = $this->authenticator->getIdentity();
     if (strtolower($id['name']) != 'admin') {
         $this->flash->addMessage('flash', 'Access Denied');
         return $response->withRedirect($this->router->pathFor('homepage'));
     }
     $name = $args['name'];
     if (empty($name)) {
         $this->flash->addMessage('flash', 'No rota specified');
         return $response->withRedirect($this->router->pathFor('rotas'));
     }
     if ($name != 'new') {
         $rota = R::findOrCreate('rotas', ['name' => $name]);
     } else {
         $rota = R::dispense('rotas');
     }
     if ($request->isPost()) {
         $data = $request->getParams();
         //$username = $request->getParam('username');
         $rota->import($data, 'name,fullname,title,comment');
         $rota->sharedUsersList = [];
         foreach ($data['users'] as $checkUserID) {
             $rotaUser = R::load('users', $checkUserID);
             $rota->sharedUsersList[] = $rotaUser;
         }
         $id = R::store($rota);
         try {
             $fieldtest = R::inspect($rota->name);
         } catch (\Exception $e) {
             //thaw for creation
             R::freeze(['users']);
             $rotaUser = R::load('users', 1);
             $rotaDay = R::findOrCreate($rota->name, ['day' => 29, 'month' => 2, 'year' => 2015]);
             $rotaUser = R::load('users', 1);
             $rotaDay->name = $rotaUser;
             $rotaDay->who = $rotaUser;
             $rotaDay->stamp = date("Y-m-d H:i:s");
             R::store($rotaDay);
             R::freeze(true);
         }
         $this->flash->addMessage('flash', "{$rota->name} updated");
         return $response->withRedirect($this->router->pathFor('rotas'));
     }
     $userList = R::findAll('users');
     $data = $rota->export();
     $data['userList'] = $userList;
     $users = [];
     $userRota = $rota->sharedUsersList;
     foreach ($userRota as $userCheck) {
         $users[$userCheck->id] = 'checked';
     }
     $data['userCheck'] = $users;
     $this->view->render($response, 'rota.twig', $data);
     return $response;
 }