diff --git a/application/controllers/auth.php b/application/controllers/auth.php index d1459eb..59ba86a 100755 --- a/application/controllers/auth.php +++ b/application/controllers/auth.php @@ -30,7 +30,7 @@ class Auth extends CI_Controller { } /** - * Logs the user in. + * Logs the user in - or not ;-) */ public function login() { if ($this->access->loggedIn()) { @@ -41,53 +41,28 @@ class Auth extends CI_Controller { $this->form_validation->set_rules('username', "Benutzername", 'required'); $this->form_validation->set_rules('password', "Passwort", 'required'); - if ($this->form_validation->run() == true) { //check to see if the user is logging in + if ($this->form_validation->run() == true) { // check for "remember me" $remember = (boolean) $this->input->post('remember'); - if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) { //if the login is successful - //redirect them back to the home page - $this->session->set_flashdata('message', $this->access->messages()); - redirect('', 'refresh'); - } else { //if the login was un-successful - //redirect them back to the login page - $this->session->set_flashdata('message', $this->access->errors()); - //redirect('auth/login', 'refresh'); //use redirects instead of loading views for compatibility with MY_Controller libraries - echo "{success: false}"; + if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) { + $this->data['success'] = true; + } else { // if the login was un-successful + $this->data['success'] = false; + $this->data['message'] = $this->access->errors(); } - } else { //the user is not logging in so display the login page - //set the flash data error message if there is one - $this->data['message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message'); + + // output json data + $this->output->set_content_type('application/json') + ->set_output(json_encode($this->data)); + } else { + $this->data['message'] = validation_errors() ? validation_errors() : null; $this->data['username'] = $this->form_validation->set_value('username'); $this->load->view('auth/login', $this->data); } } - /** - * Logs the user in - or not ;-) - */ - public function do_login() { - $this->form_validation->set_rules('username', "Benutzername", 'required'); - $this->form_validation->set_rules('password', "Passwort", 'required'); - - if ($this->form_validation->run() == true) { - $remember = (boolean) $this->input->post('remember'); - - if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) { - $this->session->set_flashdata('message', $this->access->messages()); - $return['success'] = true; - } else { // if the login was un-successful - $this->session->set_flashdata('message', $this->access->errors()); - $return['success'] = false; - $return['message'] = "Benutzername oder PW falsch"; - } - } - - $this->output->set_content_type('application/json') - ->set_output(json_encode($return)); - } - /** * Logs the user out. */ @@ -229,31 +204,6 @@ class Auth extends CI_Controller { } } - private function _get_csrf_nonce() { - $this->load->helper('string'); - $key = random_string('alnum', 8); - $value = random_string('alnum', 20); - $this->session->set_flashdata('csrfkey', $key); - $this->session->set_flashdata('csrfvalue', $value); - - return array($key => $value); - } - - private function _valid_csrf_nonce() { - if ($this->input->post($this->session->flashdata('csrfkey')) !== false && - $this->input->post($this->session->flashdata('csrfkey')) == $this->session->flashdata('csrfvalue')) { - return true; - } else { - return false; - } - } - - /** - * Logs the user out. - */ - public function do_logout() { - echo "{success: true}"; - } } /* End of file auth.php */ diff --git a/application/language/english/auth_lang.php b/application/language/english/auth_lang.php index 5566e5a..a9a6c90 100644 --- a/application/language/english/auth_lang.php +++ b/application/language/english/auth_lang.php @@ -9,7 +9,7 @@ $lang['password_change_unsuccessful'] = "Unable to change password"; $lang['forgot_password_successful'] = "Password reset email sent"; $lang['forgot_password_unsuccessful'] = "Unable to reset password"; $lang['login_successful'] = "Logged in successfully"; -$lang['login_unsuccessful'] = "In-correct login"; +$lang['login_unsuccessful'] = "Incorrect username or password"; $lang['logout_successful'] = "Logged out successfully"; $lang['update_successful'] = "Account information successfully updated"; $lang['update_unsuccessful'] = "Unable to update account information"; diff --git a/application/language/german/auth_lang.php b/application/language/german/auth_lang.php index 5566e5a..092a886 100644 --- a/application/language/german/auth_lang.php +++ b/application/language/german/auth_lang.php @@ -8,9 +8,9 @@ $lang['password_change_successful'] = "Password successfully changed"; $lang['password_change_unsuccessful'] = "Unable to change password"; $lang['forgot_password_successful'] = "Password reset email sent"; $lang['forgot_password_unsuccessful'] = "Unable to reset password"; -$lang['login_successful'] = "Logged in successfully"; -$lang['login_unsuccessful'] = "In-correct login"; -$lang['logout_successful'] = "Logged out successfully"; +$lang['login_successful'] = "Erfolgreich eingeloggt"; +$lang['login_unsuccessful'] = "Benutzername oder Passwort falsch"; +$lang['logout_successful'] = "Erfolgreich ausgeloggt"; $lang['update_successful'] = "Account information successfully updated"; $lang['update_unsuccessful'] = "Unable to update account information"; $lang['delete_successful'] = "User deleted"; diff --git a/application/libraries/Access.php b/application/libraries/Access.php index 49bd9e5..2d8a6ef 100644 --- a/application/libraries/Access.php +++ b/application/libraries/Access.php @@ -8,29 +8,22 @@ class Access { /** - * CodeIgniter global - * - * @var string - **/ + * Contains the CI instance. + */ protected $ci; - protected $message_start_delimiter = '
'; - protected $message_end_delimiter = '
'; - protected $error_start_delimiter = ''; - protected $error_end_delimiter = '
'; - /** - * message (uses lang file) + * Contains occured messages (using the language file). * * @var string - **/ + */ protected $messages = array(); /** - * error message (uses lang file) + * Contains occured errors (using the language file). * * @var string - **/ + */ protected $errors = array(); /** @@ -45,9 +38,6 @@ class Access { $this->ci->load->model('group'); $this->ci->load->helper('cookie'); - $this->messages = array(); - $this->errors = array(); - // auto-login the user if they are remembered if (!$this->loggedIn() && get_cookie('username') && get_cookie('remember_code')) { $this->ci->access = $this; @@ -179,10 +169,10 @@ class Access { if ($this->ci->user->login($username, $password, $remember)) { $this->setMessage('login_successful'); return true; + } else { + $this->setError('login_unsuccessful'); + return false; } - - $this->setError('login_unsuccessful'); - return false; } /** @@ -297,12 +287,12 @@ class Access { * @return void */ public function messages() { - $_output = ''; + $output = ''; foreach ($this->messages as $message) { - $_output .= $this->message_start_delimiter . $this->ci->lang->line($message) . $this->message_end_delimiter; + $output .= lang($message) . '