diff --git a/application/controllers/Options.php b/application/controllers/Options.php index be8b83ef..cb7899cf 100644 --- a/application/controllers/Options.php +++ b/application/controllers/Options.php @@ -149,4 +149,107 @@ class Options extends CI_Controller { } } + // function used to display the /appearance url + function email() { + + $data['page_title'] = "Cloudlog Options"; + $data['sub_heading'] = "Email"; + + $this->load->view('interface_assets/header', $data); + $this->load->view('options/email'); + $this->load->view('interface_assets/footer'); + } + + // Handles saving the radio options to the options system. + function email_save() { + + // Get Language Options + + $data['page_title'] = "Cloudlog Options"; + $data['sub_heading'] = "Email"; + + $this->load->helper(array('form', 'url')); + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('emailProtocol', 'Email Protocol', 'required'); + + if ($this->form_validation->run() == FALSE) + { + $this->load->view('interface_assets/header', $data); + $this->load->view('options/email'); + $this->load->view('interface_assets/footer'); + } + else + { + + // Update emailProtocol choice within the options system + $emailProtocolupdate = $this->optionslib->update('emailProtocol', $this->input->post('emailProtocol'), 'yes'); + + // If emailProtocolupdate update is complete set a flashsession with a success note + if($emailProtocolupdate == TRUE) { + $this->session->set_flashdata('success', 'Outgoing Email Protocol changed to '.$this->input->post('emailProtocol')); + } + + // Update smtpEncryption choice within the options system + $smtpEncryptionupdate = $this->optionslib->update('smtpEncryption', $this->input->post('smtpEncryption'), 'yes'); + + // If smtpEncryption update is complete set a flashsession with a success note + if($smtpEncryptionupdate == TRUE) { + $this->session->set_flashdata('success', 'SMTP Encryption changed to '.$this->input->post('smtpEncryption')); + } + + // Update smtpHost choice within the options system + $smtpHostupdate = $this->optionslib->update('smtpHost', $this->input->post('smtpHost'), 'yes'); + + // If smtpHost update is complete set a flashsession with a success note + if($smtpHostupdate == TRUE) { + $this->session->set_flashdata('success', 'SMTP Host changed to '.$this->input->post('smtpHost')); + } + + // Update smtpPort choice within the options system + $smtpPortupdate = $this->optionslib->update('smtpPort', $this->input->post('smtpPort'), 'yes'); + + // If smtpPort update is complete set a flashsession with a success note + if($smtpPortupdate == TRUE) { + $this->session->set_flashdata('success', 'SMTP Port changed to '.$this->input->post('smtpPort')); + } + + // Update smtpUsername choice within the options system + $smtpUsernameupdate = $this->optionslib->update('smtpUsername', $this->input->post('smtpUsername'), 'yes'); + + // If smtpUsername update is complete set a flashsession with a success note + if($smtpUsernameupdate == TRUE) { + $this->session->set_flashdata('success', 'SMTP Username changed to '.$this->input->post('smtpUsername')); + } + + // Update smtpPassword choice within the options system + $smtpPasswordupdate = $this->optionslib->update('smtpPassword', $this->input->post('smtpPassword'), 'yes'); + + // If smtpPassword update is complete set a flashsession with a success note + if($smtpPasswordupdate == TRUE) { + $this->session->set_flashdata('success', 'SMTP Password changed to '.$this->input->post('smtpPassword')); + } + + // Update emailcrlf choice within the options system + $emailcrlfupdate = $this->optionslib->update('emailcrlf', $this->input->post('emailcrlf'), 'yes'); + + // If emailcrlf update is complete set a flashsession with a success note + if($emailcrlfupdate == TRUE) { + $this->session->set_flashdata('success', 'Email CRLF changed to '.$this->input->post('emailcrlf')); + } + + // Update emailnewline choice within the options system + $emailnewlineupdate = $this->optionslib->update('emailnewline', $this->input->post('emailnewline'), 'yes'); + + // If emailnewline update is complete set a flashsession with a success note + if($emailnewlineupdate == TRUE) { + $this->session->set_flashdata('success', 'Email Newline changed to '.$this->input->post('emailnewline')); + } + + // Redirect back to /appearance + redirect('/options/email'); + } + } + } diff --git a/application/controllers/User.php b/application/controllers/User.php index c5649548..dbb48912 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -516,8 +516,6 @@ class User extends CI_Controller { $check_email = $this->user_model->check_email_address($this->input->post('email', true)); - print_r($check_email); - if($check_email == TRUE) { // Generate password reset code 50 characters long $this->load->helper('string'); @@ -530,6 +528,20 @@ class User extends CI_Controller { $this->data['reset_code'] = $reset_code; $this->load->library('email'); + if($this->optionslib->get_option('emailProtocol') == "smtp") { + $config = Array( + 'protocol' => $this->optionslib->get_option('emailProtocol'), + 'smtp_host' => $this->optionslib->get_option('smtpHost'), + 'smtp_port' => $this->optionslib->get_option('smtpPort'), + 'smtp_user' => $this->optionslib->get_option('smtpUsername'), + 'smtp_pass' => $this->optionslib->get_option('smtpPassword'), + 'crlf' => "\r\n", + 'newline' => "\r\n" + ); + + $this->email->initialize($config); + } + $message = $this->load->view('email/forgot_password', $this->data, TRUE); $this->email->from('noreply@cloudlog.co.uk', 'Cloudlog'); @@ -538,10 +550,16 @@ class User extends CI_Controller { $this->email->subject('Cloudlog Account Password Reset'); $this->email->message($message); - $this->email->send(); - // Redirect to login page with message - $this->session->set_flashdata('notice', 'Password Reset Processed.'); - redirect('user/login'); + if (! $this->email->send()) + { + // Redirect to login page with message + $this->session->set_flashdata('warning', 'Email settings are incorrect.'); + redirect('user/login'); + } else { + // Redirect to login page with message + $this->session->set_flashdata('notice', 'Password Reset Processed.'); + redirect('user/login'); + } } else { // No account found just return to login page $this->session->set_flashdata('notice', 'Password Reset Processed.'); diff --git a/application/libraries/OptionsLib.php b/application/libraries/OptionsLib.php index 1808f311..baf9f45e 100644 --- a/application/libraries/OptionsLib.php +++ b/application/libraries/OptionsLib.php @@ -72,7 +72,7 @@ class OptionsLib { } // Function to update options within the options table - function update($option_name, $option_value) { + function update($option_name, $option_value, $auto_load = NULL) { // Make Codeigniter functions available to library $CI =& get_instance(); @@ -80,7 +80,7 @@ class OptionsLib { $CI->load->model('options_model'); // call library function to save update - $result = $CI->options_model->update($option_name, $option_value); + $result = $CI->options_model->update($option_name, $option_value, $auto_load); // return True or False on whether its completed. return $result; diff --git a/application/models/Options_model.php b/application/models/Options_model.php index 1fe5a488..d323e10f 100644 --- a/application/models/Options_model.php +++ b/application/models/Options_model.php @@ -65,13 +65,14 @@ class Options_model extends CI_Model { * - option_name: name of the option with no spaces * - option_value: the value of the option name */ - function update($option_name, $option_value) { + function update($option_name, $option_value, $auto_load = NULL) { $this->db->where('option_name', $option_name); $query = $this->db->get('options'); $data = array( 'option_name' => $option_name, 'option_value' => $option_value, + 'autoload' => $auto_load, ); if($query->num_rows() > 0) { diff --git a/application/views/options/email.php b/application/views/options/email.php new file mode 100644 index 00000000..248bfa0b --- /dev/null +++ b/application/views/options/email.php @@ -0,0 +1,105 @@ +