From d7cbc89d8bd77878e47ffa8a46a6026db3ca967c Mon Sep 17 00:00:00 2001 From: Cris Date: Wed, 25 Sep 2019 12:15:19 +0200 Subject: [PATCH] =?UTF-8?q?Added=20password=20validation=20to=20accept=20L?= =?UTF-8?q?ehrauftr=C3=A4ge=20in=20view=20&=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit . added password input field in view . added password check in controller . adapted ajax data object and logic to handle password check --- .../lehrauftrag/LehrauftragAkzeptieren.php | 38 +++++++++++---- .../lehre/lehrauftrag/acceptLehrauftrag.php | 46 +++++++++++++++---- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/application/controllers/lehre/lehrauftrag/LehrauftragAkzeptieren.php b/application/controllers/lehre/lehrauftrag/LehrauftragAkzeptieren.php index f83ce1c45..8f0fdda8c 100644 --- a/application/controllers/lehre/lehrauftrag/LehrauftragAkzeptieren.php +++ b/application/controllers/lehre/lehrauftrag/LehrauftragAkzeptieren.php @@ -36,6 +36,7 @@ class LehrauftragAkzeptieren extends Auth_Controller // Load libraries $this->load->library('WidgetLib'); $this->load->library('PermissionLib'); + $this->load->library('AuthLib'); // Load helpers $this->load->helper('array'); @@ -110,17 +111,33 @@ class LehrauftragAkzeptieren extends Auth_Controller */ public function acceptLehrauftrag() { - $lehrauftrag_arr = $this->input->post(); - - foreach($lehrauftrag_arr as $lehrauftrag) + // Verify password + $password = $this->input->post('password'); + if (!isEmptyString($password)) { - if (!isEmptyArray($lehrauftrag)) + $result = $this->authlib->checkUserAuthByUsernamePassword($this->_uid, $password); + if (isError($result)) + { + return $this->outputJsonError('Passwort ist inkorrekt'); // exit if password is incorrect + } + } + else + { + show_error('Password is missing'); + } + + // Loop through lehraufträge + $lehrauftrag_arr = $this->input->post('selected_data'); + if(is_array($lehrauftrag_arr)) + { + foreach($lehrauftrag_arr as $lehrauftrag) { $mitarbeiter_uid = (!is_null($lehrauftrag['mitarbeiter_uid'])) ? $lehrauftrag['mitarbeiter_uid'] : null; $vertrag_id = (!is_null($lehrauftrag['vertrag_id'])) ? intval($lehrauftrag['vertrag_id']) : null; + // Set status to accepted $result = $this->VertragModel->setStatus($vertrag_id, $mitarbeiter_uid, 'akzeptiert'); - + if ($result->retval) { $json []= array( @@ -129,11 +146,12 @@ class LehrauftragAkzeptieren extends Auth_Controller ); } } - } - // output json to ajax - if (isset($json) && !isEmptyArray($json)) - { - $this->outputJsonSuccess($json); + + // Output json to ajax + if (isset($json) && !isEmptyArray($json)) + { + $this->outputJsonSuccess($json); + } } } diff --git a/application/views/lehre/lehrauftrag/acceptLehrauftrag.php b/application/views/lehre/lehrauftrag/acceptLehrauftrag.php index a86ca537b..cea417c65 100644 --- a/application/views/lehre/lehrauftrag/acceptLehrauftrag.php +++ b/application/views/lehre/lehrauftrag/acceptLehrauftrag.php @@ -65,14 +65,22 @@ $this->load->view(
-
- +
-
+
+
+
+ + + + +
+
+ @@ -152,27 +160,46 @@ $(function() { // Approve Lehrauftraege $("#accept-lehrauftraege").click(function(){ - selected_data = $('#filterTabulator').tabulator('getSelectedData'); - + // Get selected rows data + var selected_data = $('#filterTabulator').tabulator('getSelectedData'); if (selected_data.length == 0) { FHC_DialogLib.alertInfo('Bitte wählen Sie erst zumindest einen Lehrauftrag'); return; } + // Get password for verification + var password = $("#password").val(); + if (password == '') + { + FHC_DialogLib.alertInfo('Bitte verifizieren Sie sich mit Ihrem Login Passwort.'); + $("#password").focus(); + return; + } + + // Prepare data object for ajax call + var data = { + 'password': password, + 'selected_data': selected_data + }; + FHC_AjaxClient.ajaxCallPost( FHC_JS_DATA_STORAGE_OBJECT.called_path + "/acceptLehrauftrag", - selected_data, + data, { successCallback: function (data, textStatus, jqXHR) { - if (data.retval != null) + if (data.error) + { + // Password not verified + FHC_DialogLib.alertWarning(data.retval); + } + if (!data.error && data.retval != null) { // Update status 'Erteilt' $('#filterTabulator').tabulator('updateData', data.retval); + FHC_DialogLib.alertSuccess(data.retval.length + " Lehraufträge wurden akzeptiert."); } - - FHC_DialogLib.alertSuccess(data.retval.length + " Lehraufträge wurden akzeptiert."); }, errorCallback: function (jqXHR, textStatus, errorThrown) { @@ -180,7 +207,6 @@ $(function() { } } ); - }); });