diff --git a/application/controllers/User.php b/application/controllers/User.php index a26812a34..9f04b8be2 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -805,13 +805,16 @@ class User extends CI_Controller { } } - // Send an E-Mail to the user. Function is similar to forgot_password() - public function admin_send_passwort_reset() { + // Send an E-Mail to the user. Function is similar to forgot_password() but will be called by an AJAX + public function admin_send_password_reset() { + + header('Content-Type: application/json'); + if ($this->input->is_ajax_request()) { // just additional, to make sure request is from ajax if ($this->input->post('submit_allowed')) { $this->load->model('user_model'); - + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $query = $this->user_model->get_by_id($this->input->post('user_id')); @@ -872,18 +875,12 @@ class User extends CI_Controller { if (! $this->email->send()) { - // Redirect to user page with message - $this->session->set_flashdata('danger', lang('admin_email_settings_incorrect')); - redirect('user'); + echo json_encode(false); } else { - // Redirect to user page with message - $this->session->set_flashdata('success', lang('admin_password_reset_processed') . " " . $data->user_name . " (" . $data->user_email . ")"); - redirect('user'); + echo json_encode(true); } } else { - // No account found just return to user page - $this->session->set_flashdata('danger', 'Nothing done. No user found.'); - redirect('user'); + echo json_encode(false); } } } diff --git a/application/views/user/main.php b/application/views/user/main.php index 843e55c08..e15dcd6d9 100644 --- a/application/views/user/main.php +++ b/application/views/user/main.php @@ -2,6 +2,9 @@ var lang_admin_confirm_pwd_reset = ""; var lang_admin_user = ""; var lang_gen_hamradio_callsign = ""; + + var lang_admin_email_settings_incorrect = ""; + var lang_admin_password_reset_processed = "";
@@ -16,22 +19,9 @@
- - session->flashdata('success')) { ?> - - - - - - session->flashdata('danger')) { ?> - - - - + + +
@@ -81,7 +71,7 @@ user_id) { - echo ''; + echo ''; } ?> diff --git a/assets/js/sections/user.js b/assets/js/sections/user.js index 8a0d198b8..57ff32287 100644 --- a/assets/js/sections/user.js +++ b/assets/js/sections/user.js @@ -39,16 +39,27 @@ $(document).ready(function(){ var pwd_reset_user_name = $(this).data('username'); var pwd_reset_user_callsign = $(this).data('callsign'); var pwd_reset_user_id = $(this).data('userid'); + var pwd_reset_user_email = $(this).data('usermail'); BootstrapDialog.confirm({ title: lang_general_word_warning, - message: lang_admin_confirm_pwd_reset + "\n\n" + lang_admin_user + ": " + pwd_reset_user_name + "\n" + lang_gen_hamradio_callsign + ": " + pwd_reset_user_callsign, + message: + lang_admin_confirm_pwd_reset + "\n\n" + + lang_admin_user + ": " + pwd_reset_user_name + "\n" + + lang_gen_hamradio_callsign + ": " + pwd_reset_user_callsign, type: BootstrapDialog.TYPE_DANGER, btnCancelLabel: lang_general_word_cancel, btnOKLabel: lang_general_word_ok, btnOKClass: "btn-warning", + closable: false, // Setzt closable auf false, um das Schließen während des Ajax-Aufrufs zu verhindern callback: function (result) { if (result) { + var wait_dialog = BootstrapDialog.show({ + title: 'Bitte warten', + message: '
', + closable: false, + buttons: [] + }); $.ajax({ url: base_url + 'index.php/user/admin_send_password_reset', type: 'POST', @@ -56,9 +67,30 @@ $(document).ready(function(){ user_id: pwd_reset_user_id, submit_allowed: true }, + success: function(result) { + wait_dialog.close(); + + if (result) { + $('#pwd_reset_message').addClass('alert-success'); + $('#pwd_reset_message').text(lang_admin_password_reset_processed + " " + pwd_reset_user_name + " (" + pwd_reset_user_email + ")"); + $('#pwd_reset_message').show(); + } else { + $('#pwd_reset_message').addClass('alert-danger'); + $('#pwd_reset_message').text(lang_admin_email_settings_incorrect); + $('#pwd_reset_message').show(); + } + }, + error: function() { + wait_dialog.close(); + + $('#pwd_reset_message').addClass('alert-danger'); + $('#pwd_reset_message').text('Error! Description: admin_send_password_reset failed'); + $('#pwd_reset_message').show(); + } }); } }, - }); + }).getModalHeader().find('.modal-title').after(''); + }); });