diff --git a/application/controllers/auth.php b/application/controllers/auth.php index 59ba86a..4f201d5 100755 --- a/application/controllers/auth.php +++ b/application/controllers/auth.php @@ -14,6 +14,7 @@ class Auth extends CI_Controller { parent::__construct(); $this->load->library('access'); $this->load->library('form_validation'); + $this->load->model('user'); } //redirect if needed, otherwise display the user list @@ -116,53 +117,28 @@ class Auth extends CI_Controller { $this->load->view('auth/register_success', $this->data); } - //change password - public function change_password() { - $this->form_validation->set_rules('old', 'Old password', 'required'); - $this->form_validation->set_rules('new', 'New Password', 'required|min_length[' . $this->config->item('min_password_length', 'access') . ']|max_length[' . $this->config->item('max_password_length', 'access') . ']|matches[new_confirm]'); - $this->form_validation->set_rules('new_confirm', 'Confirm New Password', 'required'); - + public function settings() { if (!$this->access->loggedIn()) { redirect('auth/login', 'refresh'); } - $user = $this->access->get_user($this->session->userdata('user_id')); - if ($this->form_validation->run() == false) { //display the form - //set the flash data error message if there is one - $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); + // validate form + $this->form_validation->set_rules('new_password', 'New Password', 'min_length[' . $this->config->item('min_password_length', 'auth') . ']|max_length[' . $this->config->item('max_password_length', 'auth') . ']|matches[new_password_confirm]'); - $this->data['old_password'] = array('name' => 'old', - 'id' => 'old', - 'type' => 'password' - ); - $this->data['new_password'] = array('name' => 'new', - 'id' => 'new', - 'type' => 'password' - ); - $this->data['new_password_confirm'] = array('name' => 'new_confirm', - 'id' => 'new_confirm', - 'type' => 'password' - ); - $this->data['user_id'] = array('name' => 'user_id', - 'id' => 'user_id', - 'type' => 'hidden', - 'value' => $user->id - ); + if ($this->form_validation->run() == true) { + // change password if needed + if ($this->input->post('new_password') != '') { + $username = $this->session->userdata('username'); + $change = $this->access->changePassword($username, $this->input->post('old_password'), $this->input->post('new_password')); - //render - $this->load->view('auth/change_password', $this->data); - } else { - $username = $this->session->userdata('username'); - - $change = $this->access->change_password($username, $this->input->post('old'), $this->input->post('new')); - - if ($change) { //if the password was successfully changed - $this->session->set_flashdata('message', $this->access->messages()); - $this->logout(); - } else { - $this->session->set_flashdata('message', $this->access->errors()); - redirect('auth/change_password', 'refresh'); + if ($change) { + $this->logout(); + } } + echo "{success: true}"; + } else { + echo validation_errors(); + $user = $this->access->getCurrentUser(); } } @@ -204,6 +180,9 @@ class Auth extends CI_Controller { } } + public function test() { + echo "{xtype: 'form', title: 'Bla'}"; + } } /* End of file auth.php */ diff --git a/application/libraries/Access.php b/application/libraries/Access.php index fa2fb78..bdb3b62 100644 --- a/application/libraries/Access.php +++ b/application/libraries/Access.php @@ -232,6 +232,15 @@ class Access { return $userGroup == $checkGroup; } + /** + * Gets the current logged in user. + * + * @return object + */ + public function getCurrentUser() { + return $this->ci->user->getUserByID($this->ci->session->userdata('user_id'))->row(); + } + /** * Gets the profile of the current user. * diff --git a/application/views/auth/login.php b/application/views/auth/login.php index a0c2dfa..21357fa 100755 --- a/application/views/auth/login.php +++ b/application/views/auth/login.php @@ -14,6 +14,7 @@ var BASE_URL = '=site_url('/');?>'; var BASE_PATH = '=base_url();?>'; + =script_tag('assets/js/language/' . $this->config->item('language') . '.js');?> =script_tag('assets/js/common.js');?> diff --git a/application/views/header.php b/application/views/header.php index 8490d55..d056293 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -14,6 +14,7 @@ var BASE_URL = '=site_url('/');?>'; var BASE_PATH = '=base_url();?>'; + =script_tag('assets/js/language/' . $this->config->item('language') . '.js');?> =script_tag('assets/js/common.js');?> @@ -22,7 +23,7 @@