diff options
author | Florian Pritz <bluewind@xinu.at> | 2013-07-15 13:12:19 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2013-07-15 13:12:19 +0200 |
commit | c5d5cb3c864ca381e133a24a2a786604db7880ab (patch) | |
tree | df5ef249ff270dd628316aa7afb44085839169fc /application/models | |
parent | 346caed594c7de29017a96b7d76f35be2539f4e3 (diff) |
Rework auto login for cli clients
Only login when necessary.
This also makes test_login() work properly (before the automatic login
would have intercepted the failure and in case of a good login
test_login() would test the credentials a second time.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/models')
-rw-r--r-- | application/models/muser.php | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/application/models/muser.php b/application/models/muser.php index 720b4ee7e..639b5ee3a 100644 --- a/application/models/muser.php +++ b/application/models/muser.php @@ -21,28 +21,6 @@ class Muser extends CI_Model { $this->load->helper("filebin"); $this->load->driver("duser"); - - if (is_cli_client()) { - $username = $this->input->post("username"); - $password = $this->input->post("password"); - - // prefer post parameters if either (username or password) is set - if ($username === false && $password === false) { - if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { - $username = $_SERVER['PHP_AUTH_USER']; - $password = $_SERVER['PHP_AUTH_PW']; - } - } - - if ($username !== false && $password !== false) { - if (!$this->login($username, $password)) { - // TODO: better message - $this->output->set_status_header(401); - echo "login failed.\n"; - exit; - } - } - } } function has_session() @@ -85,6 +63,31 @@ class Muser extends CI_Model { return $this->duser->login($username, $password); } + private function login_cli_client() + { + $username = $this->input->post("username"); + $password = $this->input->post("password"); + + // prefer post parameters if either (username or password) is set + if ($username === false && $password === false) { + if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { + $username = $_SERVER['PHP_AUTH_USER']; + $password = $_SERVER['PHP_AUTH_PW']; + } + } + + if ($username !== false && $password !== false) { + if ($this->login($username, $password)) { + return true; + } else { + // TODO: better message + $this->output->set_status_header(401); + echo "login failed.\n"; + exit; + } + } + } + function logout() { $this->require_session(); @@ -125,18 +128,24 @@ class Muser extends CI_Model { { if ($this->logged_in()) { return true; - } else { - if (is_cli_client()) { - echo "FileBin requires you to have an account, please go to the homepage for more information.\n"; - exit(); - } else { - $this->require_session(); - if (!$this->session->userdata("flash:new:uri")) { - $this->session->set_flashdata("uri", $this->uri->uri_string()); - } - redirect('user/login'); + } + + // handle cli clients + if (is_cli_client()) { + if ($this->login_cli_client()) { + return true; } + + echo "FileBin requires you to have an account, please go to the homepage for more information.\n"; + exit(); + } + + // desktop clients get redirected to the login form + $this->require_session(); + if (!$this->session->userdata("flash:new:uri")) { + $this->session->set_flashdata("uri", $this->uri->uri_string()); } + redirect('user/login'); exit(); } |