Jump to content

Custom login handler


Recommended Posts

I am trying to add a custom login handler following this documentation https://invisioncommunity.com/developers/docs/members-authentication/login-methods/introduction-to-login-methods-r172/ but can't get it working. Here are the steps I follow:

1. Enabled dev mode.

2. Created a new application named "testapp".

3. In the application's developer center created a hook to the class IPS\Login\Handler (file name LoginHandlerHook):

//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

abstract class testapp_hook_LoginHandlerHook extends _HOOK_CLASS_
{
	public static function handlerClasses()
	{
		$return = parent::handlerClasses();
		$return[] = 'IPS\mycustomloginhandler\MyLoginHandler';
		return $return;
	}
}

4. Now I need to create the login handler itself, but I am not sure how. The documentation says "Create a class for your login handler using the skeleton below.", but it doesn't mention WHERE should I create it. I assume it's the application's folder, so I create a new file "MyCustomLoginHandler.php" in the application's folder: 

<?php
	
namespace IPS\mycustomloginhandler;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

class _MyCustomLoginHandler extends \IPS\Login\Handler
{
	/**
	 * @brief	Can we have multiple instances of this handler?
	 */
	public static $allowMultiple = FALSE;
		
	/**
	 * Get title
	 *
	 * @return	string
	 */
	public static function getTitle()
	{
		return 'my_cusom_login_handler'; // Create a langauge string for this
	}
}

 5. I go to the admin CP -> Login & Registration and click on the button "Create New" and get this error:

Error: Class 'IPS\mycustomloginhandler\MyLoginHandler' not found (0)
#0 C:\Websites\forum2.tomhess.my\system\Helpers\Wizard\Wizard.php(181): IPS\core\modules\admin\settings\_login->IPS\core\modules\admin\settings\{closure}(Array)
#1 C:\Websites\forum2.tomhess.my\applications\core\modules\admin\settings\login.php(207): IPS\Helpers\_Wizard->__toString()
#2 C:\Websites\forum2.tomhess.my\system\Dispatcher\Controller.php(85): IPS\core\modules\admin\settings\_login->form()
#3 C:\Websites\forum2.tomhess.my\system\Node\Controller.php(62): IPS\Dispatcher\_Controller->execute()
#4 C:\Websites\forum2.tomhess.my\applications\core\modules\admin\settings\login.php(43): IPS\Node\_Controller->execute()
#5 C:\Websites\forum2.tomhess.my\system\Dispatcher\Dispatcher.php(152): IPS\core\modules\admin\settings\_login->execute()
#6 C:\Websites\forum2.tomhess.my\admin\index.php(14): IPS\_Dispatcher->run()
#7 {main}

Question: where I am supposed to place the MyCustomLoginHandler.php file to get the handler class recognized?

Link to comment
Share on other sites

Read 

 

8 minutes ago, Alexander Yuganov said:

2. Created a new application named "testapp".

- Create MyCustomLoginHandler.php

/applications/testapp/sources/MyCustomLoginHandler/MyCustomLoginHandler.php

<?php
	
namespace IPS\testapp;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

class _MyCustomLoginHandler extends \IPS\Login\Handler
{
	// ....
}

		$return[] = 'IPS\mycustomloginhandler\MyLoginHandler';

change to 

		$return[] = 'IPS\testapp\MyCustomLoginHandler';

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...