Support » Plugin: Next Active Directory Integration » Usage of another URL for custom login

  • Resolved ayssono

    (@ayssono)


    Hello!

    “Enables login using a custom login page
    If checked, NADI does also registers its hook when the URL /login is called. You have to make sure that this URL is mapped by WordPress.”

    Is there a way to use another custom login url than /login ?

    Kind regards,

    Klaus

Viewing 15 replies - 1 through 15 (of 23 total)
  • Plugin Author schakko

    (@schakko)

    Hi Klaus,
    you can use a custom filter as described at https://active-directory-wp.com/docs/FAQ/How_to_trigger_authentication_for_custom_URL.html πŸ™‚

    Thread Starter ayssono

    (@ayssono)

    Hi schakko!

    Thank you, but I tried this code, but it doesn’t work:

    add_filter(NEXT_AD_INT_PREFIX . 'auth_enable_login_check', function ($loginCheckAlreadyEnabled) {
    		if (!$loginCheckAlreadyEnabled) {
    		$loginCheckAlreadyEnabled = in_array(strtok($_SERVER["REQUEST_URI"],'?'), array (
    			"/iwi4u-iwi"
    		));
    	}
    	
    	return $loginCheckAlreadyEnabled;
    }, 10, 1);
    

    The URL is: …/iwi4u-iwi or …/iwi4u-iwi/

    When I try it with the same page and “/login” (and deactivated filter, default), it works fine.
    Also official login page works fine.

    Kind regards,

    Klaus

    • This reply was modified 7 months, 2 weeks ago by ayssono.
    • This reply was modified 7 months, 2 weeks ago by ayssono.
    Thread Starter ayssono

    (@ayssono)

    Hello!
    Ok, I tried it on another website and I couldn’t login too:

    The code there is:

    add_filter(NEXT_AD_INT_PREFIX . 'auth_enable_login_check', function ($loginCheckAlreadyEnabled) {
    		if (!$loginCheckAlreadyEnabled) {
    		$loginCheckAlreadyEnabled = in_array(strtok($_SERVER["REQUEST_URI"],'?'), array (
    			"/logreg"
    		));
    	}
    	
    	return $loginCheckAlreadyEnabled;
    }, 10, 1);

    What is my fault?

    Kind regards,

    Klaus

    Plugin Author schakko

    (@schakko)

    Hi Klaus, does your custom filter not get executed (you can check it with a simple print statement) or does it not work?

    Thread Starter ayssono

    (@ayssono)

    Hello!

    I have this code and it shows only 1 and 3, no 2:

    print "1";
    add_filter(NEXT_AD_INT_PREFIX . 'auth_enable_login_check', function ($loginCheckAlreadyEnabled) {
    print "2";
    		if (!$loginCheckAlreadyEnabled) {
    		$loginCheckAlreadyEnabled = in_array(strtok($_SERVER["REQUEST_URI"],'?'), array (
    			"/logreg"
    		));
    	}
    	
    	return $loginCheckAlreadyEnabled;
    }, 10, 1);
    print "3";

    Kind regards,

    Klaus

    Plugin Author schakko

    (@schakko)

    – How does the surrrounding code before and after your add_filter statement looks like? It seems like you are registering your filter too late and it has already been called by NADI.

    – You can check, if the method calling the filter is executed by adding print statements to https://github.com/NeosIT/active-directory-integration2/blob/master/classes/Adi/Init.php, method isOnLoginPage().

    Thread Starter ayssono

    (@ayssono)

    Hello!

    The code is just like a plugin, because I made a plugin with the code and didn’t add it to functions file. That works normally great.

    Here is the code:

    <?php
    /**
    * Plugin Name: Custom Login URL for NEXT AD Plugin
    * Plugin URI: https://active-directory-wp.com/docs/FAQ/How_to_trigger_authentication_for_custom_URL.html
    * Description: Custom URL for WP Login with activated NEXT AD Plugin and to register new users
    * Version: 1.0
    * Author: AD NEXT
    * Author URI: https://active-directory-wp.com/docs/FAQ/How_to_trigger_authentication_for_custom_URL.html
    * License: GPL12
    */
    add_filter(NEXT_AD_INT_PREFIX . 'auth_enable_login_check', function ($loginCheckAlreadyEnabled) {
    		if (!$loginCheckAlreadyEnabled) {
    		$loginCheckAlreadyEnabled = in_array(strtok($_SERVER["REQUEST_URI"],'?'), array (
    			"/logreg"
    		));
    	}
    	
    	return $loginCheckAlreadyEnabled;
    }, 10, 1);
    ?>

    Kind regards,

    Klaus πŸ™‚

    Plugin Author schakko

    (@schakko)

    – Is this a Multisite environment?
    – Have you added print statements in the Init.php to see if the isOnLoginPage method gets triggered?

    Thread Starter ayssono

    (@ayssono)

    Hello!
    No, it is not a multisite environment.

    I changed the function isOnLoginPage to:

    	public function isOnLoginPage()
    	{
    		$r = false;
    print "1";
    		$page        = $_SERVER['PHP_SELF'];
    		$required    = "wp-login.php";
    		$isOnWpLogin = substr($page, -strlen($required)) == $required;
    		$isOnXmlRpc  = $this->isOnXmlRpcPage();
    print "2";
    		if ($isOnWpLogin || $isOnXmlRpc) {
    			$r = true;
    		}
    print "3";
    		$customLoginPageEnabled = $this->dc()->getConfiguration()->getOptionValue(NextADInt_Adi_Configuration_Options::CUSTOM_LOGIN_PAGE_ENABLED);
    
    		if ($customLoginPageEnabled) {
    			if (isset($_SERVER["REQUEST_URI"]) && strpos($_SERVER["REQUEST_URI"], '/login') !== false) {
    				$r = true;
    print "4";
    			}
    		}
    
    		$r = apply_filters(NEXT_AD_INT_PREFIX . 'auth_enable_login_check', $r);
    print "5";
    		return $r;
    	}

    Result is:
    It shows up: 1,2,3,5, but no 4.

    Kind regards,

    Klaus

    Plugin Author schakko

    (@schakko)

    If you put print statements in both of your plug-in code and Init.php, in which order do they get executed?

    The correct order would be:
    – your_plugin: 1
    – your_plugin: 3
    – Init.php: 1
    – Init.php: 2
    – Init.php: 3
    ( – Init.php: 4)
    – your_plugin: 2
    – Init.php: 5

    Thread Starter ayssono

    (@ayssono)

    Hi!

    I just get:
    131235

    Which means:
    plugin 1
    plugin 3
    init 1
    init 2
    init 3
    init 5

    Kind regards,

    Klaus

    Plugin Author schakko

    (@schakko)

    – In your plug-in, what values is printed for print NEXT_AD_INT_PREFIX;?(should benext_ad_int_`). If this prints nothing, there should be also a PHP warning that the constant is not defined. You ‘next_ad_int_auth_enable_login_check’ instead.

    – You can try

    
    function my_nadi_hook($param) {
      print "3";
    }
    
    add_filter('next_ad_int_auth_enable_login_check', 'my_nadi_hook', 10, 1); 
    
    • This reply was modified 7 months ago by schakko.
    Thread Starter ayssono

    (@ayssono)

    Hi!

    When the plugin code is like this, print NEXT_AD_INT; doesn’t work, there is no output.

    print "1";
    add_filter(NEXT_AD_INT_PREFIX . 'auth_enable_login_check', function ($loginCheckAlreadyEnabled) {
    print NEXT_AD_INT;
    print "2";
    		if (!$loginCheckAlreadyEnabled) {
    		$loginCheckAlreadyEnabled = in_array(strtok($_SERVER["REQUEST_URI"],'?'), array (
    			"/logreg"
    		));
    	}
    	
    	return $loginCheckAlreadyEnabled;
    }, 10, 1);
    print "3";
    

    Kind regards,

    Klaus

    Plugin Author schakko

    (@schakko)

    The print statement must be outside your callback handler as the callback handler itself does not get executed in your case πŸ˜‰

    
    print "1";
    print NEXT_AD_INT_PREFIX; // should print "next_ad_int_"
    
    add_filter(NEXT_AD_INT_PREFIX . 'auth_enable_login_check', 
      function($loginCheckAlreadyEnabled) {
      ...
    }), 10, 1);
    
    • This reply was modified 7 months ago by schakko.
    Thread Starter ayssono

    (@ayssono)

    Hi!

    Thank you for your patience! πŸ™‚

    I get now: 1NEXT_AD_INT31235

    There is no “next_ad_int_”.

    Kind regards,
    Klaus

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘Usage of another URL for custom login’ is closed to new replies.