/** * Execute the controller. * * @return mixed Return executed result. * * @throws \LogicException * @throws \RuntimeException */ public function execute() { if (UserHelper::isLogin()) { Ioc::getApplication()->redirect(Router::build('admin:dashboard')); } $model = new LoginModel(); $session = Ioc::getSession(); $user = $this->input->getVar('user'); $result = $model->login($user['username'], $user['password']); $package = $this->getPackage(); $redirect = $session->get('login.redirect.url'); if ($result) { $url = $redirect ? base64_decode($redirect) : $package->get('redirect.login'); $msg = Language::translate('Login Success'); } else { $router = Ioc::getRouter(); $url = $router->build($this->package->getRoutingPrefix() . ':login'); $msg = Language::translate('Login Fail'); } $uri = new Uri($url); if (!$uri->getScheme()) { $url = $this->app->get('uri.base.full') . $url; } $session->remove('login.redirect.url'); $this->setRedirect($url, $msg); return true; }
/** * onBeforeRouting * * @param Event $event * * @return void * * @throws \Exception */ public function onBeforeRouting(Event $event) { $app = Ioc::getApplication(); $uri = $app->initUri(); $uri = new Uri(strtolower($uri->full)); $host = $uri->getHost(); $host = explode('.', $host); array_pop($host); array_pop($host); $alias = implode('.', $host); $alias = trim(str_replace('.', '', $alias)); // If is main domain but logged in, go to admin if (!$alias && UserHelper::isLogin()) { $app->set('client', 'admin'); return; } // Has subdomain, means it is users' blog if ($alias) { $blogMapper = new DataMapper('blogs'); $blog = $blogMapper->findOne(['alias' => $alias]); if ($blog->isNull()) { throw new \Exception('Blog not found', 404); } Ioc::getContainer('front')->set('current.blog', $blog); $app->set('client', 'front'); return; } // Main domain, got to site $app->set('client', 'site'); }
/** * doExecute * * @return mixed */ protected function doExecute() { $model['list.search'] = $this->getUserStateFromInput($this->getContext('list.search'), 'search', array(), InputFilter::ARRAY_TYPE); $model['list.filter'] = $this->getUserStateFromInput($this->getContext('list.filter'), 'filter', array(), InputFilter::ARRAY_TYPE); $model['list.ordering'] = $this->getUserStateFromInput($this->getContext('list.ordering'), 'list_ordering'); $model['list.direction'] = $this->getUserStateFromInput($this->getContext('list.direction'), 'list_direction'); $uri = new Uri($this->app->uri->full); $uri->delVar('filter'); $this->setRedirect($uri->toString()); return true; }
/** * Method to test match(). * * @param string $url * @param string $pattern * @param string $method * @param boolean $expected * @param integer $line * * @return void * * @covers Windwalker\Router\Route::match * * @dataProvider matchCases */ public function testMatch($url, $pattern, $method, $expected, $line) { $uri = new Uri($url); $host = $uri->getHost(); $scheme = $uri->getScheme(); $port = $uri->getPort() ?: 80; $config = array('name' => 'flower', 'pattern' => $pattern, 'variables' => array('_controller' => 'FlowerController', 'id' => 1), 'method' => array('GET', 'PUT'), 'host' => 'windwalker.com', 'scheme' => 'http', 'port' => 80, 'sslPort' => 443, 'requirements' => array('id' => '\\d+')); $route = new \Windwalker\Router\Route($config['name'], $config['pattern'], $config['variables'], $config['method'], $config); $result = $this->instance->setRoutes(array($route))->match($uri->getPath(), $method, array('host' => $host, 'scheme' => $scheme, 'port' => $port)); $this->assertEquals($expected, !empty($result), 'Match fail, case on line: ' . $line); }
/** * url * * @param int $size * @param int $id * @param string $u * * @return string */ public static function url($size = 300, $id = null, $u = null) { $uri = new Uri(static::$host); $size = $size ?: 300; $uri->setPath('/' . $size); if ($id) { $uri->setVar('id', (int) $id); } if ($u) { $uri->setVar('u', $u); } return $uri->toString(); }
/** * Execute the controller. * * @return mixed Return executed result. * * @throws \LogicException * @throws \RuntimeException */ public function execute() { $model = new LoginModel(); $user = $this->input->getVar('user'); $result = $model->login($user['username'], $user['password']); $package = $this->getPackage(); if ($result) { $url = $package->get('redirect.login'); $msg = Language::translate('pkg.user.login.success'); } else { $router = Ioc::getRouter(); $url = $router->build($this->package->getRoutingPrefix() . ':login'); $msg = Language::translate('pkg.user.login.fail'); } $uri = new Uri($url); if (!$uri->getScheme()) { $url = $this->app->get('uri.base.full') . $url; } $this->setRedirect($url, $msg); return true; }
/** * Execute the controller. * * @return mixed Return executed result. * * @throws \LogicException * @throws \RuntimeException */ public function doExecute() { $model = new LoginModel(); $user = $this->input->getVar('user'); $user = new Data($user); $result = $model->login($user['username'], $user['password'], $user['remember']); $package = $this->getPackage(); if ($result) { $url = $package->get('redirect.login'); $msg = Translator::translate('windwalker.user.login.success'); } else { $router = $this->package->getRouter(); $url = $router->http('login', array(), RestfulRouter::TYPE_FULL); $msg = Translator::translate('windwalker.user.login.fail'); } $uri = new Uri($url); if (!$uri->getScheme()) { $url = $this->app->get('uri.base.full') . $url; } $this->setRedirect($url, $msg); return true; }
/** * Get system Uri object. * * @param string $requestUri The request uri string. * @param bool $refresh Refresh the uri. * * @return Uri The system Uri object. * * @since 2.0 */ protected function getSystemUri($requestUri = null, $refresh = false) { if ($this->uri && !$refresh) { return $this->uri; } $requestUri = $requestUri ?: $this->detectRequestUri(); // Start with the requested URI. $uri = new Uri($requestUri); // If we are working from a CGI SAPI with the 'cgi.fix_pathinfo' directive disabled we use PHP_SELF. if (strpos(php_sapi_name(), 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI'])) { // We aren't expecting PATH_INFO within PHP_SELF so this should work. $uri->setPath(rtrim(dirname($_SERVER['PHP_SELF']), '/\\')); } else { $uri->setPath(rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\')); } // Clear the unused parts of the requested URI. $uri->setQuery(null); $uri->setFragment(null); return $this->uri = $uri; }
/** * Prepare Request object to send request. * * @param RequestInterface $request The Psr Request object. * @param string $method The method type. * @param string|object $url The URL to request, may be string or Uri object. * @param mixed $data The request body data, can be an array of POST data. * @param array $headers The headers array. * * @return RequestInterface */ protected function prepareRequest(RequestInterface $request, $method, $url, $data, $headers) { $url = (string) $url; // If is GET, we merge data into URL. if (strtoupper($method) == 'GET' && is_array($data)) { $url = new Uri($url); foreach ($data as $k => $v) { $url->setVar($k, $v); } $url = (string) $url; $data = null; } // If not GET, convert data to query string. if (is_array($data)) { $data = UriHelper::buildQuery($data); } /** @var RequestInterface $request */ $request->getBody()->write((string) $data); $request = $request->withRequestTarget((string) new PsrUri($url))->withMethod($method); // Set global headers foreach ((array) $this->getOption('headers') as $key => $value) { $request = $request->withHeader($key, $value); } // Override with this method foreach ($headers as $key => $value) { $request = $request->withHeader($key, $value); } return $request; }
/** * getSuccessRedirect * * @param DataInterface|Entity $data * * @return string */ protected function getSuccessRedirect(DataInterface $data = null) { $uri = new Uri($this->app->uri->full); foreach ($this->getRedirectQuery() as $field => $value) { $uri->setVar($field, $value); } return $uri->toString(); }
/** * Test the isSSL method. * * @return void * * @since 1.0 * @covers Windwalker\Uri\Uri::isSSL */ public function testIsSSL() { $object = new Uri('https://*****:*****@www.example.com:80/path/file.html?var=value#fragment'); $this->assertThat($object->isSSL(), $this->equalTo(true)); $object = new Uri('http://*****:*****@www.example.com:80/path/file.html?var=value#fragment'); $this->assertThat($object->isSSL(), $this->equalTo(false)); }