• Resolved anemos2k

    (@anemos2k)


    Hi Tom,

    I am thinking of implementing your plugin on my site and I have a small question that I was hoping you could answer.

    Is there a possibility to detect a flag like active/inactive on the external database and deactivate/activate accordingly the users created on the local WordPress database? Or if I assign a specific user role in the external db, can this be used to disallow access locally in WordPress? If any of the above scenarios are not possible, any ideas how I could prevent a deactivated user on the external database to login in WordPress?

    Please let me clarify: On the external database, users never get deleted, they are only marked as deactivated and this leads me to question the fact that since a user account and a password DO EXIST in the external database how do I prevent that this user gets created and be allowed to log in locally in WordPress?

    By the way, the suggestion that you made on another user to allow adding/modifying part of the SQL query on the external database is very, very interesting!

    Thanks in advance for your input!
    Panos

Viewing 15 replies - 16 through 30 (of 50 total)
  • Hi Tom,
    Answers to your questions:

    1) Firefox 64.02 Mac OSX 10.13.6
    2) I did the hard refresh and the only error that I received at any point was: `JQMIGRATE: Migrate is installed, version 1.4.1 load-scripts.php:9:542
    Source map error: request failed with status 404
    Resource URL: /wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-position,jquery-ui-draggable,jquery-u&load%5B%5D=i-droppable,jquery-ui-resizable,jquery-effects-core,jquery-effects-drop,jquery-effects-fade,jquery-effects-bounce,jquery-ui-tabs&load%5B%5D=,jquery-form&ver=5.0.3
    Source Map URL: jquery.form.min.js.map`
    3) the only thing stored is the option value of “false”

    Thank you,
    Paul

    Plugin Author tbenyon

    (@tbenyon)

    Can you show me the PHP errors that happen at the time that you press the Test button.

    As you’re doing this testing on Mac I’m assuming you’re using Mamp to run this locally?

    If so, in menu bar I think there is an error logs option and PHP is an option within.

    Key here is there will be loads of stuff in there. I just want the stuff that appears when you click the button.

    I’m running this on a lamp server. There are no php errors reported.

    Plugin Author tbenyon

    (@tbenyon)

    I may be wrong but it sounds like your PHP errors aren’t coming through.

    The 500 error only appears if there is an error on the server.

    There’s a few more things to do so that we can the required error information.

    Test that your error logs are working
    In your functions.php file, at the very top add:
    error_log("-----------EXTERNAL LOGIN TESTING!!!!!------------");

    If when you refresh your page you are not seeing this in your error logs then we need to fix that first. Make sure you’re looking at the logs for the server where you are pressing the test button from.

    Test if we’re getting to the test query function in the plugin
    If we are seeing the above error log that’s great.

    Let’s see if we’re getting to the test function in the plugin.

    Let’s add this line of code:
    error_log("External Login - We're starting the test query!!!!!!!!!!!!");

    . . . to this file:
    wp-content/plugins/external-login/js/exlog_test.js

    . . .in this function:
    exlog_test_query()

    . . . so that it now looks like this:

    function exlog_test_query($limit = false) {
        error_log("External Login - We're starting the test query!!!!!!!!!!!!");
        $dbType = exlog_get_option('external_login_option_db_type');
        $db_data = exlog_get_external_db_instance_and_fields($dbType);
        if ($dbType == "postgresql") {
            $query_string =
                'SELECT *' .
                ' FROM "' . esc_sql($db_data["dbstructure_table"]) . '"';
            if ($limit && is_int($limit)) {
                $query_string .= ' LIMIT ' . $limit;
            }
            $rows = pg_query($query_string) or die('Query failed: ' . pg_last_error());
            $users = array();
            if (sizeof($rows) > 0) {
                while ($x = pg_fetch_array($rows, null, PGSQL_ASSOC)) {
                    array_push($users, $x); //Gets the first row
                };
                pg_close($db_data["db_instance"]);
                return $users;
            }
        } else {
            $query_string =
                'SELECT *' .
                ' FROM ' . esc_sql($db_data["dbstructure_table"]) . '';
            if ($limit && is_int($limit)) {
                $query_string .= ' LIMIT ' . $limit;
            }
            $rows = $db_data["db_instance"]->get_results($query_string, ARRAY_A);
            $users = array();
            if (sizeof($rows) > 0) {
                foreach ($rows as $user_data) {
                    array_push($users, exlog_build_wp_user_data($db_data, $user_data));
                };
                return $users;
            }
        }
        //If got this far, query failed
        error_log("External Login - No rows returned from test query.");
        return false;
    }

    Do we see that error in your logs?

    Get more information from the front end JS error
    We’re going to add a line of code to the front end JS so we can see more of what is going on.

    We’re going to modify the file wp-content/plugins/external-login/js/exlog_test.js.

    We’re going to add the line:
    console.log("EXTERNAL LOGIN JS TESTING:", xhr.responseText);

    We’re going to add this to the ajax call so that it looks like this:

                $.ajax({
                    type: "GET",
                    url: wordpressBaseUrl + "/wp-admin/admin-ajax.php",
                    data: data,
                    success: function (data) {
                        if (!data) {
                          errorMessageState(600);
                          $modal_error.show();
                        } else if (data == "") {
                          errorMessageState(601);
                          $modal_error.show();
                        } else if (data === "0") {
                          errorMessageState(501);
                        } else {
                          $modal_error.hide();
                          $modal_test_results.append(data);
                        }
                        $loader.hide();
                    },
                    error: function (xhr, ajaxOptions, thrownError){
                      console.log("EXTERNAL LOGIN JS TESTING:", xhr.responseText);
                      if(xhr.status == 404) {
                        errorMessageState(404);
                      } else if (xhr.status === 500) {
                        errorMessageState(500);
                      } else if (Math.floor(xhr.status / 100) === 5) {
                        errorMessageState(502);
                      } else {
                        errorMessageState(100);
                      }
                      $loader.hide();
                    }
                });

    Of course, this error will appear in your browsers console log.

    for the functions.php error_log output I do get the errors in the error_log

    for the js modifications exlog_test.js a couple of notes:

    in your first modification please note that the code that you say to modify does not match in my file. You say to add it to this function “exlog_test_query()” but this function does not exist in my file.

    I added it as you wrote it in full, but in testing, I do not get any errors in the error_log

    In the js console the only output I am getting is:

    Source map error: request failed with status 404 Resource URL: /wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-position,jquery-ui-draggable,jquery-u&load%5B%5D=i-droppable,jquery-ui-resizable,jquery-effects-core,jquery-effects-drop,jquery-effects-fade,jquery-effects-bounce,jquery-ui-tabs&load%5B%5D=,jquery-form&ver=5.0.3 Source Map URL: jquery.form.min.js.map

    • This reply was modified 6 years, 1 month ago by xprojectsx.
    Plugin Author tbenyon

    (@tbenyon)

    The last message I sent had three sections and I’ll go back through them below:
    1) Test that your error logs are working

    You’ve added error_log("-----------EXTERNAL LOGIN TESTING!!!!!------------"); to your functions.php and you can see this coming through. However, when you click the test button you are not getting any more error logs however you are still seeing the 500 error message.
    Let me know if this is not correct.

    2) Test if we’re getting to the test query function in the plugin
    I made a mistake here as I wrote the wrong file path.

    I meant this file:
    wp-content/plugins/external-login/login/db.php

    Could you try replacing code for the function I specified above and see what additional error logs you get.

    3) Get more information from the front end JS error
    If I’m not mistaken you tried swapping out the code with the example above and you saw no error logs.

    I’m going to ask that you replace all the code in this file (/wp-content/plugins/external-login/js/exlog_test.js)

    Could you please delete the previous code paste the following code in there instead. If you still don’t see any error logs you must be loading in the wrong file somehow.

    
    console.log("EXLOG - Test file loaded.");
    (function ($) {
        $(function () {
            console.log("EXLOG - Test file loaded jQuery.");
            var $modal = $(".exlog_modal");
            var $loader = $(".exlog_loader_container");
            var $modal_content_container = $(".exlog_test_results_inner_container", $modal);
            var $modal_test_results = $(".exlog_test_results", $modal);
            var $modal_error = $(".exlog_test_fail", $modal_content_container);
            var $modal_error_title = $(".exlog-error-title", $modal_error);
            var $modal_error_message = $(".exlog-error-message", $modal_error);
            var wordpressBaseUrl = $('[data-exlog-wp-base]').attr('data-exlog-wp-base');
    
            var error_messages = {
                unknown: {
                    title: "Error",
                    message: "This is an unknown error."
                },
                lost: {
                  title: "Error",
                  message: "Could not access the server to run the test."
                },
                server: {
                    title: "Error",
                    message: "There was an error on the server."
                },
                empty_result: {
                  title: "Error",
                  message: "No data returned from the server. Please check your settings."
                }
            };
    
            var error_codes = {
              100: error_messages.unknown,       // Ajax returned, unknown error
              101: error_messages.unknown,       // Unknown error passed to error handler
              404: error_messages.lost,          // 404 from Ajax
              500: error_messages.server,        // 500 from server - see test_results.php?
              501: error_messages.server,        // String of "0" returned - caused by missing function?
              502: error_messages.server,        // 500ish error from Ajax
              600: error_messages.empty_result,  // Empty AJAX response
              601: error_messages.empty_result   // Blank string AJAX response
    //        999: ????????????????????????      // Hard coded in markup case this system fails
            };
    
            function errorMessageState(error_code) {
              if (!error_code) {
                $modal_error.hide();
              }
    
              if (!error_codes.hasOwnProperty(error_code)) {
                error_code = 101;
              }
    
              var error_data = error_codes[error_code];
    
              $modal_error_title.text(error_data.title + ": " + error_code);
              $modal_error_message.text(error_data.message);
    
              $modal_error.show();
            }
    
            $(".exlog_close_button", $modal).click(function () {
                $modal_error.hide();
                $modal.hide();
                $modal_test_results.text("");
            });
    
            $("input.exlog_test_connection").click(function () {
                console.log("EXLOG - Test button clicked.");
                $modal.show();
                $loader.show();
                var data = {
                    'action': 'exlog_test_connection',
                    'test_results': 10
                };
    
                console.log("EXLOG - About to make request.");
                $.ajax({
                    type: "GET",
                    url: wordpressBaseUrl + "/wp-admin/admin-ajax.php",
                    data: data,
                    success: function (data) {
                        if (typeof data === 'string') {
                          data = data.trim();
                        }
    
                        if (!data) {
                          console.log("EXLOG - NO DATA");
                          errorMessageState(600);
                          $modal_error.show();
                        } else if (data == "") {
                          console.log("EXLOG - EMPTY STRING DATA");
                          errorMessageState(601);
                          $modal_error.show();
                        } else if (data === "0") {
                          errorMessageState(501);
                        } else {
                          console.log("EXLOG - SUCCESS!!! WHOOP!");
    
                          $modal_error.hide();
                          $modal_test_results.append(data);
                        }
                        $loader.hide();
                    },
                    error: function (xhr, ajaxOptions, thrownError){
                      console.log("EXLOG - Request fail!!!");
                      console.log("Status: ", xhr.status);
                      console.log("Response Text: ", xhr.responseText);
                      if(xhr.status == 404) {
                        errorMessageState(404);
                      } else if (xhr.status === 500) {
                        errorMessageState(500);
                      } else if (Math.floor(xhr.status / 100) === 5) {
                        errorMessageState(502);
                      } else {
                        errorMessageState(100);
                      }
                      $loader.hide();
                    }
                });
            });
        });
    }(jQuery));
    

    Thanks for your patience – I’m sure we’ll get there working together on this ??

    Tom

    • This reply was modified 6 years, 1 month ago by tbenyon.

    Tom,

    1) I do not see a 500 error. The only error is the javascript console and this does not display on the page.
    2) yes now with that db.php error test I do see this in the error_log
    3) there seems to be some display issue on this forum so that I am not seeing what file you are specifying. Could you please clarify?

    Thank you
    Paul

    nevermind #3 that path is displaying now and I will try that.

    For number three here are the results that I get when I use the Exclude Users beta. I do get the “Settings Saved” message at the top but what I just entered into the fields is not there. Here is the console message:

    JQMIGRATE: Migrate is installed, version 1.4.1 load-scripts.php:9:542
    EXLOG - Test file loaded. exlog_test.js:1:1
    EXLOG - Test file loaded jQuery. exlog_test.js:4:9
    Source map error: request failed with status 404
    Resource URL: /wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-position,jquery-ui-draggable,jquery-u&load%5B%5D=i-droppable,jquery-ui-resizable,jquery-effects-core,jquery-effects-drop,jquery-effects-fade,jquery-effects-bounce,jquery-ui-tabs&load%5B%5D=,jquery-form&ver=5.0.3
    Source Map URL: jquery.form.min.js.map[Learn More]
    This site appears to use a scroll-linked positioning effect. This may not work well with asynchronous panning; see https://developer.mozilla.org/docs/Mozilla/Performance/ScrollLinkedEffects for further details and to join the discussion on related tools and features! options-general.php 
    Plugin Author tbenyon

    (@tbenyon)

    If that is all you are seeing in the console, even after clicking the test button, it must be that the error that follow are preventing Javascript to continue running.

    I’m going to ask you to do something that I hate it when people ask me to do but I think may be the cause of your problem. I’m starting to think this is nothing to do with my plugin but your theme or another plugin that is causing a JS error which is blocking other JS from running.

    The reason I think this is these two lines are very basic and they should execute when you click the test button:

    
            $("input.exlog_test_connection").click(function () {
                console.log("EXLOG - Test button clicked.");
    

    –To Try–
    Please set your theme back to the default 2019 theme and disable other plugins.
    Keep turning all this off until you find this is all working.

    If you disable all and reset your theme and find it works with just my plugin you can gradually include plugins again until you find the one that is causing the issue.

    I may be wrong bit it is strange that this simple code is not running.

    If this doesn’t work for you, we could start to find out why this JS isn’t running when you click the button.

    Sorry this is taking time. It’s hard to solve when I can’t replicate.

    I won’t give up on this ??

    To be clear, the information that I posted in the previous message is based upon entering data in the “Exclude Users beta” and clicking the “Save Changes” button. This is what I have had issues with i.e. nothing saves despite getting “Settings Saved”

    If I click the “Test Connection” button I get this in the console:

    JQMIGRATE: Migrate is installed, version 1.4.1 load-scripts.php:9:542
    EXLOG - Test file loaded. exlog_test.js:1:1
    EXLOG - Test file loaded jQuery. exlog_test.js:4:9
    Source map error: request failed with status 404
    Resource URL: /wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-position,jquery-ui-draggable,jquery-u&load%5B%5D=i-droppable,jquery-ui-resizable,jquery-effects-core,jquery-effects-drop,jquery-effects-fade,jquery-effects-bounce,jquery-ui-tabs&load%5B%5D=,jquery-form&ver=5.0.3
    Source Map URL: jquery.form.min.js.map[Learn More]
    EXLOG - Test button clicked. exlog_test.js:69:13
    EXLOG - About to make request. exlog_test.js:77:13
    EXLOG - SUCCESS!!! WHOOP! exlog_test.js:98:23
    

    After deactivating all of the other plugins, the behavior is the same.

    Plugin Author tbenyon

    (@tbenyon)

    Hey @xprojectsx,

    I’m really sorry as I have got confused between two support tickets. Really embarrassed and sincere apologies.

    To update where we’re up to:

    • The repeater front end is working in that you can add values and the add items buttons work
    • When you click save the page refreshes, however the values get wiped out
    • After this when you look in the database at the “exlog_exclude_users_field_name_repeater” field you only have the value “false” stored
    • To even get this far you’ve had to modify the code in the plugin as discussed in a different support ticket here: https://www.ads-software.com/support/topic/fatal-error-3102/

    Assuming all this is correct let’s do some more checks.

    1) Is the data store updating in the JS
    I’m going to reference this image to help you find what you need to:
    https://ibb.co/2M6G4JD

    Screen-Shot-2019-01-16-at-8-19-40-AM

    Can you please

    1. Refresh the page
    2. Type something in to the exclude users boxes
    3. Inside exlog-repeater-master (red in pic) there is a hidden input with the class exlog_repeater_data_source (purple in pic) and that has a value attribute (blue in pic). Can you see any data in that?
    4. If you can see data, it should be updating everytime you type anything in to any input in the exclude users section. Is that the case?

    Again, I’m really embarrassed for my confusion – sincere apologies.

    Thanks for your patience,

    Tom

    OK I did everything you said. I see the updating but this is what happens:

    When I type in anything into the “Field Name” field, I see the code get highlighted but nothing changes.
    When I type in anything into the “Field Value” field, the code highlights and the change DOES occur in the highlighted code.

    No apologies necessary. You are rocking this and it is appreciated. Thank you for your attention and perseverance.

    Plugin Author tbenyon

    (@tbenyon)

    So typing in field name values isn’t updating the data but typing in the field values does.

    That sounds like a bug in itself but I’ll come back to that because if the data is getting updated in that field, but when you press the save button you are not seeing it in the database that is the first issue to solve.

    Let’s do a couple more checks:
    In the wp_options table you can see the field “exlog_exclude_users_field_name_repeater” and in your case this has the “option_value” of “false”?

    Could you please:

    1. Delete the row entry for this field in the database
    2. Update one of the field values in the options area
    3. Check that the “exlog_repeater_data_source” value is updated with data
    4. Click save
    5. Check that the “exlog_exclude_users_field_name_repeater” has reappeared in your datbase options table
    6. Confirm with me the value of that field in the database

    Thanks,

    Tom

Viewing 15 replies - 16 through 30 (of 50 total)
  • The topic ‘Active/Inactive Users’ is closed to new replies.