/**
  * 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;
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
Example #5
0
 /**
  * Test the setScheme method.
  *
  * @return  void
  *
  * @since   1.0
  * @covers  Windwalker\Uri\Uri::setScheme
  */
 public function testSetScheme()
 {
     $this->object->setScheme('ftp');
     $this->assertThat($this->object->getScheme(), $this->equalTo('ftp'));
 }