function edit($user_id = 0) { if ($user_id !== 0) { $data = array(); $this->load->helper('form'); if ($this->input->post()) { $this->load->library('form_validation'); $this->form_validation->set_rules('groups_id', 'User Group', 'trim|required'); $this->form_validation->set_rules('user_login', 'Username', 'trim|required|min_length[5]|max_length[20]|edit_unique[users.user_login.user_id.' . $user_id . ']'); $this->form_validation->set_rules('user_email', 'Email', 'trim|required|valid_email|edit_unique[users.user_email.user_id.' . $user_id . ']'); $this->form_validation->set_rules('user_first_name', 'First Name', 'trim|required'); $this->form_validation->set_rules('user_last_name', 'Last Name', 'trim'); $this->form_validation->set_rules('user_status', 'User Status', 'trim|required'); $this->form_validation->set_rules('notify_user', 'Email Notification', 'trim'); $this->form_validation->set_rules('captcha_image', 'Image Text', 'trim|required|callback_validate_captcha'); $this->form_validation->set_error_delimiters('<span class="help-block">', '</span>'); if ($this->form_validation->run()) { $time_now = date('Y-m-d H:i:s'); $user_details_array = array('groups_id' => $this->input->post('groups_id'), 'user_first_name' => $this->input->post('user_first_name'), 'user_last_name' => $this->input->post('user_last_name'), 'user_email' => $this->input->post('user_email'), 'user_login' => $this->input->post('user_login'), 'user_security_hash' => md5($time_now . $this->input->post('user_login')), 'user_status' => $this->input->post('user_status'), 'user_modified' => $time_now); if ($this->User_model->edit($user_id, $user_details_array)) { if ($this->input->post('notify_user') && $this->input->post('notify_user') === '1') { $this->load->helper('string'); $email_hash = random_string('unique'); $email_body = parent::add_email_tracking($email_hash, $this->render_view(array('email_hash' => $email_hash, 'user_first_name' => $this->input->post('user_first_name'), 'user_last_name' => $this->input->post('user_last_name'), 'user_login' => $this->input->post('user_login'), 'user_email' => $this->input->post('user_email'), 'login_link' => base_url() . 'auth/login'), 'emails', 'emails/users_edit', TRUE)); if (parent::send_email($email_hash, 'Account Details Modified', $this->config->item('email_from'), $user_details_array['user_email'], $email_body)) { $data['success'] = 'We have sent account detailed instructions on ' . parent::mask_characters($user_details_array['user_email']); } else { $data['error'] = 'Error Sending Email !!!'; } } else { $data['success'] = 'Account Edited Successfully !!!'; } } else { $data['error'] = 'Error Editing User Account !!!'; } } else { $data['error'] = 'Error Editing User Account !!!'; } } $this->load->model('Group_model'); $data['groups_array'] = $this->generate_dropdown_array($this->Group_model->get_all_active_groups(), 'group_id', 'group_name', 'Select User Group'); $data['user_array'] = $this->User_model->get_user_by_id($user_id); $data['captcha_image'] = parent::create_captcha(); $this->render_view($data); } else { redirect('users'); } }
function forgot_password() { $data = array(); $this->load->helper('form'); if ($this->input->post()) { $this->load->library('form_validation'); $this->form_validation->set_rules('user_detail', 'Username OR Email Address', 'trim|required|min_length[5]'); $this->form_validation->set_rules('captcha_image', 'Image Text', 'trim|required|callback_validate_captcha'); $this->form_validation->set_error_delimiters('<span class="help-block">', '</span>'); if ($this->form_validation->run()) { $this->load->model('Auth_model'); $user_details_array = $this->Auth_model->get_user_by_username_or_email($this->input->post('user_detail')); if (count($user_details_array) > 0) { if ($user_details_array['user_status'] !== '-1') { $this->load->helper('string'); $email_hash = random_string('unique'); $email_body = parent::add_email_tracking($email_hash, $this->render_view(array('email_hash' => $email_hash, 'user_first_name' => $user_details_array['user_first_name'], 'user_last_name' => $user_details_array['user_last_name'], 'password_reset_link' => base_url() . 'auth/reset-password/' . $user_details_array['user_security_hash']), 'emails', 'emails/forgot_password', TRUE)); if (parent::send_email($email_hash, 'Forgot Password Notification', $this->config->item('email_from'), $user_details_array['user_email'], $email_body)) { $data['success'] = 'We have sent password reset instructions on ' . parent::mask_characters($user_details_array['user_email']); } else { $data['error'] = 'Error Sending Email !!!'; } } else { $data['error'] = 'Account Suspended !!!'; } } else { $data['error'] = 'Invalid User Details !!!'; } } else { $data['error'] = 'Error Sending Email !!!'; } } $data['captcha_image'] = parent::create_captcha(); $this->render_view($data, 'auth'); }