From 96511fe25a2ea2d11d9c34d4a5345eda06d09d3a Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 11 Dec 2014 16:17:35 +0100 Subject: [PATCH] Now the user can enable and configure the 2 step auth --- pandora_console/operation/users/user_edit.php | 233 ++++++++++++++++++ 1 file changed, 233 insertions(+) diff --git a/pandora_console/operation/users/user_edit.php b/pandora_console/operation/users/user_edit.php index ca2858d378..3068cd3f9f 100644 --- a/pandora_console/operation/users/user_edit.php +++ b/pandora_console/operation/users/user_edit.php @@ -337,6 +337,23 @@ if (!$meta) { $table->data[] = $data; } +// Double auth +$double_auth_enabled = (bool) db_get_value('id', 'tuser_double_auth', 'id_user', $config['id_user']); +$data = array(); +$data[0] = __('Double authentication'); +$data[0] .= '
'; +$data[0] .= html_print_checkbox('double_auth', 1, $double_auth_enabled, true); +if ($double_auth_enabled) { + $data[0] .= '  '; + $data[0] .= html_print_button(__('Show information'), 'show_info', false, 'javascript:show_double_auth_info();', '', true); +} +// Dialog +$data[0] .= "
"; +$table->colspan[count($table->data)][0] = 3; +$table->rowclass[] = ''; +$table->rowstyle[] = 'font-weight: bold;'; +$table->data[] = $data; + $data = array(); $data[0] = __('Comments'); $table->colspan[count($table->data)][0] = 3; @@ -431,6 +448,17 @@ $(document).ready (function () { $("#text-block_size").removeAttr('disabled'); } } + + $("input#checkbox-double_auth").change(function (e) { + e.preventDefault(); + + if (this.checked) { + show_double_auth_activation(); + } + else { + show_double_auth_deactivation(); + } + }); show_data_section(); }); @@ -481,4 +509,209 @@ function show_data_section () { break; } } + +function show_double_auth_info () { + var userID = ""; + + var $loadingSpinner = $("/images/spinner.gif\" />"); + var $dialogContainer = $("div#dialog-double_auth-container"); + + $dialogContainer.html($loadingSpinner); + + // Load the info page + var request = $.ajax({ + url: 'ajax.php', + type: 'POST', + dataType: 'html', + data: { + page: 'include/ajax/double_auth.ajax', + id_user: userID, + get_double_auth_data_page: 1, + containerID: $dialogContainer.prop('id') + }, + complete: function(xhr, textStatus) { + + }, + success: function(data, textStatus, xhr) { + // isNaN = is not a number + if (isNaN(data)) { + $dialogContainer.html(data); + } + // data is a number, convert it to integer to do the compare + else if (Number(data) === -1) { + $dialogContainer.html(""); + } + else { + $dialogContainer.html(""); + } + }, + error: function(xhr, textStatus, errorThrown) { + $dialogContainer.html(""); + } + }); + + $("div#dialog-double_auth") + .append($dialogContainer) + .dialog({ + resizable: true, + draggable: true, + modal: true, + title: "", + overlay: { + opacity: 0.5, + background: "black" + }, + width: 400, + height: 375, + close: function(event, ui) { + // Abort the ajax request + if (typeof request != 'undefined') + request.abort(); + // Remove the contained html + $dialogContainer.empty(); + } + }) + .show(); + +} + +function show_double_auth_activation () { + var userID = ""; + + var $loadingSpinner = $("/images/spinner.gif\" />"); + var $dialogContainer = $("div#dialog-double_auth-container"); + + $dialogContainer.html($loadingSpinner); + + // Load the info page + var request = $.ajax({ + url: 'ajax.php', + type: 'POST', + dataType: 'html', + data: { + page: 'include/ajax/double_auth.ajax', + id_user: userID, + get_double_auth_info_page: 1, + containerID: $dialogContainer.prop('id') + }, + complete: function(xhr, textStatus) { + + }, + success: function(data, textStatus, xhr) { + // isNaN = is not a number + if (isNaN(data)) { + $dialogContainer.html(data); + } + // data is a number, convert it to integer to do the compare + else if (Number(data) === -1) { + $dialogContainer.html(""); + } + else { + $dialogContainer.html(""); + } + }, + error: function(xhr, textStatus, errorThrown) { + $dialogContainer.html(""); + } + }); + + $("div#dialog-double_auth").dialog({ + resizable: true, + draggable: true, + modal: true, + title: "", + overlay: { + opacity: 0.5, + background: "black" + }, + width: 500, + height: 400, + close: function(event, ui) { + // Abort the ajax request + if (typeof request != 'undefined') + request.abort(); + // Remove the contained html + $dialogContainer.empty(); + + document.location.reload(); + } + }) + .show(); +} + +function show_double_auth_deactivation () { + var userID = ""; + + var $loadingSpinner = $("/images/spinner.gif\" />"); + var $dialogContainer = $("div#dialog-double_auth-container"); + + var message = "

' . __('The double authentication will be deactivated'); ?>

"; + var $button = $("\" />"); + + $dialogContainer + .empty() + .append(message) + .append($button); + + var request; + + $button.click(function(e) { + e.preventDefault(); + + $dialogContainer.html($loadingSpinner); + + // Deactivate the double auth + request = $.ajax({ + url: 'ajax.php', + type: 'POST', + dataType: 'json', + data: { + page: 'include/ajax/double_auth.ajax', + id_user: userID, + deactivate_double_auth: 1 + }, + complete: function(xhr, textStatus) { + + }, + success: function(data, textStatus, xhr) { + if (data === -1) { + $dialogContainer.html("
' . __('Authentication error') . '
'; ?>"); + } + else if (data) { + $dialogContainer.html("
' . __('The double autentication was deactivated successfully') . '
'; ?>"); + } + else { + $dialogContainer.html("
' . __('There was an error deactivating the double autentication') . '
'; ?>"); + } + }, + error: function(xhr, textStatus, errorThrown) { + $dialogContainer.html("
' . __('There was an error deactivating the double autentication') . '
'; ?>"); + } + }); + }); + + + $("div#dialog-double_auth").dialog({ + resizable: true, + draggable: true, + modal: true, + title: "", + overlay: { + opacity: 0.5, + background: "black" + }, + width: 300, + height: 150, + close: function(event, ui) { + // Abort the ajax request + if (typeof request != 'undefined') + request.abort(); + // Remove the contained html + $dialogContainer.empty(); + + document.location.reload(); + } + }) + .show(); +}