/** * Logout user, destroying session and invalidating remember me cookie. Forwards to login form. */ public function logoutAction() { $response = new Response(); $response->setCookies($this->cookies->set('username', '', strtotime('-1 year'))); $response->setCookies($this->cookies->set('password', '', strtotime('-1 year'))); $this->session->destroy(); return $response->redirect('session/index'); }
/** * Returns an Redirect to the given url. * * @param string $url * @return \Phalcon\Http\Response */ protected function redirect($url, $extraParams = array()) { $response = new Response(); $response->redirect($url); $formReflectionManager = new FormReflectionManager($this->flash); $formReflectionManager->add($extraParams + $this->request->get()); return $response; }
/** * Render to dashboard page. */ public function indexAction() { $uid = $this->session->get('uid'); $currentUser = $this->getCurrentUserObject($this->session); $redirectUrl = '/dashboard/issues'; if ($currentUser->getUserGroup()->getUserGroupSlug() == 'administrator') { $redirectUrl = '/administration'; } $response = new Response(); $response->redirect($redirectUrl); return $response; }
/** * Overrule this method when you want to display a nice page when * the authorization is finished. This function does not know if the authorization was * succesfull, you need to check the token in the database. * * @param boolean authorized if the current token (oauth_token param) is authorized or not * @param int user_id user for which the token was authorized (or denied) * @return string verifier For 1.0a Compatibility */ public function authorizeFinish($authorized, IIdentity $account, $token, $callback) { //$token = $this->request->getParam('oauth_token', true); $verifier = null; if ($this->session->get('verify_oauth_token') == $token) { // Flag the token as authorized, or remove the token when not authorized $store = $this->store; // Fetch the referrer host from the oauth callback parameter $referrer_host = ''; $oauth_callback = false; $verify_oauth_callback = $callback; if (!empty($verify_oauth_callback) && $verify_oauth_callback != 'oob') { $oauth_callback = $callback; $ps = parse_url($oauth_callback); if (isset($ps['host'])) { $referrer_host = $ps['host']; } } if ($authorized) { //$this->logger->addNote('Authorized token "'.$token.'" for user '.$account->email.' with referrer "'.$referrer_host.'"'); // 1.0a Compatibility : create a verifier code $verifier = $store->authorizeConsumerRequestToken($token, $account, $referrer_host); } else { //$this->logger->addNote('Authorization rejected for token "'.$token.'" for user '.$account->email."\nToken has been deleted"); $store->deleteConsumerRequestToken($token); } //$logger->alert("service: callback ze sešny: ".$oauth_callback); if (!empty($oauth_callback)) { //$params = array('oauth_token' => rawurlencode($token)); // 1.0a Compatibility : if verifier code has been generated, add it to the URL //if ($verifier) { // $params['oauth_verifier'] = $verifier; //} $uri = preg_replace('/\\s/', '%20', $oauth_callback); if (!empty($this->allowed_uri_schemes)) { if (!in_array(substr($uri, 0, strpos($uri, '://')), $this->allowed_uri_schemes)) { throw new OauthException('Illegal protocol in redirect uri ' . $uri); } } else { if (!empty($this->disallowed_uri_schemes)) { if (in_array(substr($uri, 0, strpos($uri, '://')), $this->disallowed_uri_schemes)) { throw new OauthException('Illegal protocol in redirect uri ' . $uri); } } } $oauth_callback = $oauth_callback . "?oauth_token=" . rawurlencode($token); return $this->response->redirect($oauth_callback, true); } } }
public function registerAction() { if ($this->request->isPost()) { $newUser = new Users(); $newUser->user_name = $this->request->getPost('user_name'); $newUser->first_name = $this->request->getPost('first_name'); $newUser->last_name = $this->request->getPost('last_name'); $newUser->email = $this->request->getPost('email'); $passwordText = $this->request->getPost('password'); $password = md5($passwordText, false); $newUser->password = $password; if (!$newUser->save()) { foreach ($newUser->getMessages() as $message) { $this->flash->error($message); } return $this->dispatcher->forward(array('module' => 'anonymous', "controller" => "user", "action" => "register")); } $this->flash->success("user was created successfully"); //redirect to other module cannot use forward $response = new Response(); return $response->redirect('student/index/'); } }
*/ require ROOT_DIR . 'core/config/services.php'; /** * Handle the request */ $application = new Application(); /** * Assign the DI */ $application->setDI($di); /** * Include modules */ $application->registerModules(require ROOT_DIR . 'core/config/modules.php'); /** * Sets the event manager */ $application->setEventsManager($eventsManager); echo $application->handle()->getContent(); } catch (Exception $e) { echo $e->getMessage(); echo $e->getTraceAsString(); /** * Show an static error page */ if (!$di->get('config')->application->debug) { $response = new Response(); $response->redirect('errors/503'); $response->send(); } }
* Include composer autoloader */ require APP_PATH . "/vendor/autoload.php"; try { /** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault(); /** * Include the application services */ require APP_PATH . "/app/config/services.php"; /** * Handle the request */ $application = new Application($di); echo $application->handle()->getContent(); } catch (Exception $e) { /** * Log the exception */ $logger = new Logger(APP_PATH . '/app/logs/error.log'); $logger->error($e->getMessage()); $logger->error($e->getTraceAsString()); /** * Show an static error page */ $response = new Response(); $response->redirect('505.html'); $response->send(); }
public function passThrouthMiddleWares(Request $request, Response $response, Dispatcher $dispatcher) { $route = $this->getMatchedRoute(); if (null == $route) { $r = $this->getDI()->get('router'); $r->handle($request->getURI()); $route = $r->getMatchedRoute(); //为什么搜索“装备”会出现找不到路由的问题?估计与字符处理有关系 if (null == $route) { die('url地址无效,找不到对应的路由设置!'); } } $pattern = $route->getPattern(); //对每个路由都进行验证的中间件! @todo 如果是get方式的话,目标对象如何获取呢?当前用户是否拥有该资源? foreach ($this->middlewaresForEveryRoute as $validator) { $data = null; if (preg_match('|.*:.*|', $validator)) { //此处设置了可以带中间件参数 list($validator, $data) = explode(':', $validator); $data = $dispatcher->getParam($data); } /** @var myValidation $validator */ $validator = new $validator(); if (!in_array($route->getName(), $validator->excludedRoutes) and !$validator->isValid($data)) { $url = $validator->getRedirectedUrl(); // dd($url); $response->redirect($url, true); return false; } } //@todo 如果是get方式的如何过滤呢?应该如何设置才是正常的呢?例如get方式的search的过滤,单独处理?也许吧? if ($this->hasMatchedMiddleWares($pattern) and $request->isPost()) { $middleWares = $this->getMiddleWares($pattern); foreach ($middleWares as $validator) { $data = $request->getPost(); // dd($validator); if (preg_match('|[^:]+:[^:]+|', $validator)) { list($validator, $data) = explode(':', $validator); $data = $dispatcher->getParam($data); } if (preg_match('|.*Rules$|', $validator)) { $rules = new $validator(); $validator = (new myValidation())->take($rules); } else { $validator = new $validator(); } if (!$validator->isValid($data)) { $url = $validator->getRedirectedUrl(); // dd($url); $response->redirect($url, true); return false; } } } return true; }
public function redirect($url = null, $externalRedirect = false, $statusCode = 302) { $response = new Response(); return $response->redirect($this->createUrl($url), $externalRedirect, $statusCode); }
public function redirect($location = null, $externalRedirect = false, $statusCode = 302) { return parent::redirect($location, $externalRedirect, $statusCode); }
/** * Render to new issue page to create an issue. * @param long $productId - the unique ID of the product */ public function newIssueAction($productId) { if (!$this->isLoggedIn($this->session)) { $response = new Response(); $response->redirect("/accounts/signin?forward=/product/{$productId}/new-issue"); return $response; } $productService = ServiceFactory::getService('ProductService'); $issueService = ServiceFactory::getService('IssueService'); $product = $productService->getProductUsingId($productId); if ($product == NULL) { $this->forward('errors/resourceNotFound'); return; } $product = $this->getProductInBestLanguage($product); $issueCategories = $this->getIssueCategoriesInBestLanguage($issueService->getIssueCategories()); $this->tag->prependTitle($this->localization['products.new-issue.title'] . ' · ' . $product['productName']); $this->view->setVar('product', $product); $this->view->setVar('issueCategories', $issueCategories); }
public function passThrouthMiddleWares(Request $request, Response $response, Dispatcher $dispatcher) { $route = $this->getMatchedRoute(); if (null == $route) { die('url is invalid, their is no matched route for this url!'); } $pattern = $route->getPattern(); //对每个路由都进行验证的中间件! @todo 如果是get方式的话,目标对象如何获取呢?当前用户是否拥有该资源? foreach ($this->middlewaresForEveryRoute as $validator) { $data = null; if (preg_match('|.*:.*|', $validator)) { //此处设置了可以带中间件参数 list($validator, $data) = explode(':', $validator); $data = $dispatcher->getParam($data); } $validator = new $validator(); if (!in_array($route->getName(), $validator->excludedRoutes) and !$validator->isValid($data)) { $url = $validator->getRedirectedUrl(); // dd($url); $response->redirect($url, true); return false; } } //@todo 如果是get方式的如何过滤呢?应该如何设置才是正常的呢?例如get方式的search的过滤,单独处理?也许吧? if ($this->hasMatchedMiddleWares($pattern) and $request->isPost()) { $middleWares = $this->getMiddleWares($pattern); foreach ($middleWares as $validator) { $data = $request->getPost(); // dd($validator); if (preg_match('|.*:.*|', $validator)) { list($validator, $data) = explode(':', $validator); $data = $dispatcher->getParam($data); } $validator = new $validator(); if (!$validator->isValid($data)) { $url = $validator->getRedirectedUrl(); // dd($url); $response->redirect($url, true); return false; } } } return true; }
/** * 用户注销页 */ public function getSignOutAction() { $this->session->has('auth') and $this->session->remove('auth'); $response = new Response(); $response->redirect(isset($_GET['callback']) ? $_GET['callback'] : $this->url->get('signin'), true); $response->send(); }
/** * Render to reset password page. */ public function resetPasswordAction() { $email = $this->request->get('email'); $token = $this->request->get('token'); $isTokenSet = !empty($token); $isTokenValid = false; if ($this->isLoggedIn($this->session)) { $response = new Response(); $response->redirect('/'); return $response; } if ($isTokenSet) { $userService = ServiceFactory::getService('UserService'); $isTokenValid = $userService->isEmailTokenValid($email, $token); } $this->tag->prependTitle($this->localization['accounts.reset-password.title']); $this->view->setVar('email', $email); $this->view->setVar('token', $token); $this->view->setVar('isTokenSet', $isTokenSet); $this->view->setVar('isTokenValid', $isTokenValid); }