Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function edit_user($id)
- {
- $this->data['title'] = $this->lang->line('edit_user_heading');
- if (!$this->ion_auth->logged_in() || (!$this->ion_auth->is_admin() && !($this->ion_auth->user()->row()->id == $id))) {
- redirect('auth', 'refresh');
- }
- $user = $this->ion_auth->user($id)->row();
- $groups = $this->ion_auth->groups()->result_array();
- $currentGroups = $this->ion_auth->get_users_groups($id)->result();
- // validate form input
- $this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'trim|required');
- $this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'trim|required');
- $this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'trim|required');
- $this->form_validation->set_rules('company', $this->lang->line('edit_user_validation_company_label'), 'trim|required');
- if (isset($_POST) && !empty($_POST)) {
- // do we have a valid request?
- /*
- if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
- {
- show_error($this->lang->line('error_csrf'));
- }
- */
- // update the password if it was posted
- if ($this->input->post('password')) {
- $this->form_validation->set_rules('password', $this->lang->line('edit_user_validation_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
- $this->form_validation->set_rules('password_confirm', $this->lang->line('edit_user_validation_password_confirm_label'), 'required');
- }
- // RULE apa yang ngak jalan??? ini jd pertanyaan... tapi di message kayaknya ada form yang ga ke isi deh
- if ($this->form_validation->run() === TRUE) {
- $data = array(
- 'first_name' => $this->input->post('first_name'),
- 'last_name' => $this->input->post('last_name'),
- 'company' => $this->input->post('company'),
- 'phone' => $this->input->post('phone')
- );
- // update the password if it was posted
- if ($this->input->post('password')) {
- $data['password'] = $this->input->post('password');
- }
- // Only allow updating groups if user is admin
- if ($this->ion_auth->is_admin()) {
- // Update the groups user belongs to
- $groupData = $this->input->post('groups');
- if (isset($groupData) && !empty($groupData)) {
- $this->ion_auth->remove_from_group('', $id);
- foreach ($groupData as $grp) {
- $this->ion_auth->add_to_group($grp, $id);
- }
- }
- }
- // check to see if we are updating the user
- if ($this->ion_auth->update($user->id, $data)) {
- // redirect them back to the admin page if admin, or to the base url if non admin
- $this->session->set_flashdata('message', $this->ion_auth->messages());
- $data = array(
- 'status' => TRUE,
- 'pesan' => 'ERROR:' . validation_errors()
- );
- die(json_encode($data));
- $this->redirectUser();
- } else {
- // redirect them back to the admin page if admin, or to the base url if non admin
- $this->session->set_flashdata('message', $this->ion_auth->errors());
- die('ok2');
- $this->redirectUser();
- }
- } else {
- //show_error('masih ada yg error:'.validation_errors());
- $data = array(
- 'status' => FALSE,
- 'pesan' => 'ERROR:' . validation_errors()
- );
- die(json_encode($data));
- }
- }
- // set the flash data error message if there is one
- $this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
- // pass the user to the view
- $this->data['user'] = $user;
- $this->data['groups'] = $groups;
- $this->data['currentGroups'] = $currentGroups;
- echo json_encode($this->data);
- }
Advertisement
Add Comment
Please, Sign In to add comment