Пример #1
0
 /**
  *
  * @param Request $request            
  * @param Response $response            
  * @param array $args            
  */
 public function callback(Request $request, Response $response, $args)
 {
     // cleanup the session
     $this->session->clear();
     if ($this->facebook->getAccessToken()) {
         return $response->withRedirect($this->router->pathFor('home'));
     }
     return $response->withRedirect($this->router->pathFor('login'));
 }
Пример #2
0
 public function postSignin(Request $request, Response $response, $args)
 {
     $req = $request->getParsedBody();
     $hashed_password = hash('sha1', $req['password']);
     $query = "SELECT * FROM users WHERE email =:email AND password=:password";
     $stmt = $this->db->prepare($query);
     $stmt->execute(['email' => $req['email'], 'password' => $hashed_password]);
     $isExist = $stmt->rowCount();
     $userData = $stmt->fetch(\PDO::FETCH_OBJ);
     if ($isExist == 1) {
         $this->session->set('auth', $userData);
         $this->flash->addMessage('success', 'Login Successful');
         return $response->withRedirect($this->router->pathFor('admin'));
     } else {
         $this->flash->addMessage('error', 'Data Not Found');
         return $response->withRedirect($this->router->pathFor('admin/signup'));
     }
 }
Пример #3
0
 public function login(Request $req, Response $res, $args)
 {
     $this->logger->info('Login page request');
     if (isset($_POST) && isset($_POST['username']) && isset($_POST['password'])) {
         $user = $this->userManager->getByUsername($_POST['username']);
         $password = hash('sha512', $_POST['password']);
         if ($user && $password == $user->getPassword()) {
             $this->logger->notice('Login succeed [' . $user->getUsername() . ']');
             $_SESSION['login'] = $user->getUsername();
             return $res->withRedirect($this->router->pathFor('login'));
         } else {
             $this->logger->error('Login failed');
             $this->flash->addMessage('error', 'Authentification failed.');
             return $res->withRedirect($this->router->pathFor('login'));
         }
     }
     $this->view->render($res, 'Default/home.html.twig');
     return $res;
 }
Пример #4
0
 /**
  * Example middleware invokable class
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
  * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
  * @param  callable                                 $next     Next middleware
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke($request, $response, $next)
 {
     // check if user is authenticated, otherwise return 401/ redirect/ etc
     if (!$this->auth->isAuthenticated()) {
         // return $response->withStatus(401);
         return $response->withRedirect('/session/login', 401);
     }
     // pass onto the next callable
     $response = $next($request, $response);
     return $response;
 }
Пример #5
0
 /**
  *
  */
 public function get(ServerRequestInterface $request, ResponseInterface $response)
 {
     if (!$this->auth->check()) {
         return $this->auth->redirectToLogin();
     } elseif (!$this->auth->hasAccess(['admin'])) {
         return $response->withRedirect($this->url['root']);
     }
     parent::preparePage();
     $this->importView('Main:sb2/dashboard as content');
     return parent::withBody($response);
 }
Пример #6
0
 /**
  *
  */
 public function put(ServerRequestInterface $request, ResponseInterface $response)
 {
     if (!$this->auth->check()) {
         return $this->auth->redirectToLogin();
     } elseif (!$this->auth->hasAccess(['admin'])) {
         return $response->withRedirect($this->url['root']);
     }
     $data = $request->getParsedBody();
     // Process the input data and generate proper response, specific to each application.
     $responseData = json_encode(['method' => 'PUT', 'data' => $data]);
     return parent::withBody($response, $responseData);
 }
 /**
  * Remove trailing slash from any request.
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request
  * @param  \Psr\Http\Message\ResponseInterface      $response
  * @param  callable                                 $next
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     $uri = $request->getUri();
     $path = $uri->getPath();
     if ($path != '/' && substr($path, -1) == '/') {
         // permanently redirect paths with a trailing slash
         // to their non-trailing counterpart
         $uri = $uri->withPath(substr($path, 0, -1));
         return $response->withRedirect((string) $uri, 301);
     }
     return $next($request, $response);
 }
Пример #8
0
 /**
  *
  */
 public function get(ServerRequestInterface $request, ResponseInterface $response)
 {
     if (!$this->auth->check()) {
         return $this->auth->redirectToLogin();
     } elseif (!$this->auth->hasAccess(['admin'])) {
         return $response->withRedirect($this->url['root']);
     }
     parent::preparePage();
     $args = func_get_arg(2);
     $this->importView("Sb2:{$args['view']} as content");
     return parent::withBody($response);
 }
Пример #9
0
 /**
  * @param  Container         $container A DI (Pimple) container.
  * @param  RequestInterface  $request   A PSR-7 compatible Request instance.
  * @param  ResponseInterface $response  A PSR-7 compatible Response instance.
  * @return ResponseInterface
  */
 public function __invoke(Container $container, RequestInterface $request, ResponseInterface $response)
 {
     $config = $this->config();
     // Handle explicit redirects
     if (!empty($config['redirect'])) {
         $uri = $this->parseRedirect($config['redirect'], $request);
         if ($uri) {
             return $response->withRedirect($uri, $config['redirect_mode']);
         }
     }
     $templateContent = $this->templateContent($container, $request);
     $response->write($templateContent);
     return $response;
 }
Пример #10
0
 /**
  * 
  */
 public function listAll(ServerRequestInterface $request, ResponseInterface $response)
 {
     if (!$this->auth->check()) {
         return $this->auth->redirectToLogin();
     } elseif (!$this->auth->hasAccess($this->requiredPermissions)) {
         return $response->withRedirect($this->app['urlRoot']);
     }
     parent::preparePage();
     $rolesModel = new Models\Roles();
     $rst = $rolesModel->selectAll();
     $this->importView("Auth:roles/list-all as content");
     $url_Roles = Auth::getUrlRoot() . "/auth/roles";
     $this->template->setData(['rst' => $rst, 'txt_pageTitle' => $this->locale->say('roles page title'), 'txt_th_Name' => $this->locale->say('roles table title name'), 'txt_th_Slug' => $this->locale->say('roles table title slug'), 'txt_th_Permissions' => $this->locale->say('roles table title permissions'), 'txt_btn_NewRole' => $this->locale->say('roles table btn new role'), 'url_Roles' => $url_Roles, 'url_NewRole' => "{$url_Roles}/0"]);
     return parent::withBody($response);
 }
Пример #11
0
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $path = $request->getUri()->getPath();
     if ($path == '/install') {
         if (file_exists(DATABASE . DS . 'config.yml')) {
             return $response->withRedirect('/');
         }
         return $next($request, $response);
     } elseif ($path == '/api/v1/install') {
         return $next($request, $response);
     } elseif ($path != '/install') {
         if (!file_exists(DATABASE . DS . 'config.yml')) {
             return $response->withRedirect('install');
         }
         return $next($request, $response);
     }
     return $next($request, $response);
 }
Пример #12
0
 private function logoutAndRediret(Response $res, $message)
 {
     $this->authService->clearIdentity();
     $this->flash->addMessage('danger', $message);
     return $res->withRedirect($this->unitNotFoundRedirectUrl);
 }
Пример #13
0
 /**
  *
  * @param Request $request            
  * @param Response $response            
  * @param unknown $args            
  */
 public function resultsdelete(Request $request, Response $response, $args)
 {
     $id = $args['id'];
     $record = R::load(USER, $id);
     if ($record) {
         R::trash($record);
     }
     return $response->withRedirect($this->router->pathFor('results'));
 }
 /**
  * Deallocate a user's current resource
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
  * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
  * @param  array                                    $args     Args passed in from URL
  * @return \Psr\Http\Message\ResponseInterface                Final PSR7 response
  */
 public function deallocate_action($request, $response, $args)
 {
     $resource_id = $request->getParsedBody()['resource_id'];
     $this->resource_action->destroy_resource($resource_id);
     return $response->withRedirect($this->router->pathFor('list-resources'));
 }
Пример #15
0
 public function delete(Request $request, Response $response, $args)
 {
     $kpi_entity = $this->em->getRepository('App\\Entity\\Kpi')->findOneById($args['id']);
     $this->em->remove($kpi_entity);
     $this->em->flush();
     return $response->withRedirect($this->router->pathFor('kpi'));
 }
Пример #16
0
 /**
  * Logs out the currently logged user. 
  */
 public function logout(ServerRequestInterface $request, ResponseInterface $response)
 {
     Proxy::logout();
     return $response->withRedirect(Proxy::getUrlRoot() . '/auth/login');
 }
Пример #17
0
 /**
  * Удаление категории 
  * @param  \Psr\Http\Message\ServerRequestInterface $request
  * @param  \Psr\Http\Message\ResponseInterface  $response
  */
 public function delete($request, $response)
 {
     $id = $request->getAttribute('id');
     if (!isset($id)) {
         return $response->withRedirect('/categories');
     }
     $id = (int) $id;
     $category = Model::factory('Models\\Category')->find_one($id);
     if (!isset($category->id)) {
         return $response->withRedirect('/categories');
     }
     $category->delete();
     return $response->withRedirect('/categories');
 }
Пример #18
0
 /**
  * Удаление продукта
  * @param  \Psr\Http\Message\ServerRequestInterface $request
  * @param  \Psr\Http\Message\ResponseInterface  $response
  */
 public function delete($request, $response)
 {
     $id = $request->getAttribute('id');
     if (!isset($id)) {
         return $response->withRedirect('/products');
     }
     $id = (int) $id;
     $product = Model::factory('Models\\Product')->find_one($id);
     if (!isset($product->id)) {
         return $response->withRedirect('/products');
     }
     $product->delete();
     return $response->withRedirect('/products');
 }
Пример #19
0
 public function delete(Request $request, Response $response, $args)
 {
     $this->getIndicadorService()->remove($args['id']);
     return $response->withRedirect($this->router->pathFor('indicador'));
 }
Пример #20
0
 public function results(Request $request, Response $response, $args)
 {
     return $response->withRedirect($this->router->pathFor('results'));
 }
Пример #21
0
 public function logout(Request $request, Response $response) : Response
 {
     unset($_SESSION['user_id']);
     return $response->withRedirect($this->container->router->pathFor('search-tabs'));
 }
Пример #22
0
 public function __invoke(Request $request, Response $response, $args)
 {
     return $response->withRedirect($this->getRoute()->pathFor('indicador'));
 }
Пример #23
0
 public function logout(Request $request, Response $response, $args)
 {
     $session = new \App\Helper\Session();
     $session::destroy();
     return $response->withRedirect('login');
 }
Пример #24
0
 public function rateTab(Request $request, Response $response, array $args)
 {
     if (!$this->container->user) {
         return $response->withStatus(400)->getBody()->write('Not logged in!');
     }
     try {
         $tab = $this->container->tabRepository->get($args['id']);
     } catch (\Tablak\ModelNotFoundException $e) {
         return $response->withStatus(400)->getBody()->write('Tab not found!');
     }
     $input = $request->getParsedBody();
     if (!isset($input['rating'])) {
         return $response->withStatus(400)->getBody()->write('No rating!');
     }
     $rating = filter_var($input['rating'], FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 5]]);
     if ($rating === false) {
         return $response->withStatus(400)->getBody()->write('Rating not integer between 1 and 5!');
     }
     $this->container->ratingRepository->setUserTabRating($this->container->user, $tab, $rating);
     $this->container->flash->addMessage('info', 'Thank you for rating!');
     return $response->withRedirect($this->container->router->pathFor('show-tab', ['id' => $tab->id]));
 }
Пример #25
0
 public function flash(Request $request, Response $response, $args)
 {
     $this->flash->addMessage('success', 'Tes Flashing Message');
     return $response->withRedirect($this->router->pathFor('admin'));
 }
 /**
  * Log user out of the system
  * 
  * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
  * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
  * @param  array                                    $args     Args passed in from URL
  * @return \Psr\Http\Message\ResponseInterface                Final PSR7 response
  */
 public function logout($request, $response, $args)
 {
     $this->sentinel->logout();
     return $response->withRedirect('/');
 }
Пример #27
0
 /**
  * Update usernamde and password
  *
  * @param  Request  $request
  * @param  Response $response
  * @return Response
  */
 public function updateSettings(Request $request, Response $response)
 {
     $input = $request->getParsedBody();
     $form = new Form();
     if ($form->updateUsernameAndPassword($input) === true) {
         $this->flash->addMessage('message', $form->flash['message']);
         $this->flash->addMessage('alert_type', 'success');
         return $response->withRedirect('/admin/');
     } else {
         $form = $form->getForm();
         $form['alert_type'] = 'danger';
         return $this->view->render($response, 'admin/settings.twig', ['form' => $form, 'csrf_name' => $request->getAttribute('csrf_name'), 'csrf_value' => $request->getAttribute('csrf_value'), 'active_page' => 'settings']);
     }
 }