Version 4.6.0

This commit is contained in:
Neo committed 2025-12-19 05:55:31 -08:00
1 parent f79dcf067a
commit 517a5e1f70
2036 files changed
+110041 -26162

No files matched your search

@@ -51,7 +51,9 @@ class _ExternalDatabase extends \IPS\Login\Handler
* @endcode
*/
public function acpForm()
{
{
$id = $this->id ?: 'new';
$return = array(
'login_external_conn',
'sql_host' => new \IPS\Helpers\Form\Text( 'login_external_host', ( isset( $this->settings['sql_host'] ) and $this->settings['sql_host'] ) ? $this->settings['sql_host'] : 'localhost', TRUE ),
@@ -128,11 +130,11 @@ class _ExternalDatabase extends \IPS\Login\Handler
}, NULL, NULL, 'db_encryption_validate' ),
'db_extra' => new \IPS\Helpers\Form\Text( 'login_external_extra', isset( $this->settings['db_extra'] ) ? $this->settings['db_extra'] : NULL ),
'login_settings',
'auth_types' => new \IPS\Helpers\Form\Select( 'login_auth_types', isset( $this->settings['auth_types'] ) ? $this->settings['auth_types'] : ( \IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL ), TRUE, array( 'options' => array(
'auth_types' => new \IPS\Helpers\Form\Select( 'login_auth_types', isset( $this->settings['auth_types'] ) ? $this->settings['auth_types'] : ( \IPS\Login::AUTH_TYPE_EMAIL ), TRUE, array( 'options' => array(
\IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL => 'username_or_email',
\IPS\Login::AUTH_TYPE_EMAIL => 'email_address',
\IPS\Login::AUTH_TYPE_USERNAME => 'username',
) ) ),
), 'toggles' => array( \IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL => array( 'form_' . $id . '_login_auth_types_warning' ), \IPS\Login::AUTH_TYPE_USERNAME => array( 'form_' . $id . '_login_auth_types_warning' ) ) ) ),
);
if ( \IPS\Settings::i()->allow_forgot_password == 'normal' or \IPS\Settings::i()->allow_forgot_password == 'handler' )
@@ -307,22 +309,15 @@ class _ExternalDatabase extends \IPS\Login\Handler
}
catch ( \UnderflowException $e )
{
switch ( $this->authType() )
$member = NULL;
if ( $this->authType() & \IPS\Login::AUTH_TYPE_EMAIL )
{
case \IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL:
$type = 'username_or_email';
break;
case \IPS\Login::AUTH_TYPE_USERNAME:
$type = 'username';
break;
case \IPS\Login::AUTH_TYPE_EMAIL:
$type = 'email_address';
break;
$member = new \IPS\Member;
$member->email = $usernameOrEmail;
}
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_err_no_account', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $type ) ) ) ), \IPS\Login\Exception::NO_ACCOUNT );
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_err_no_account', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::NO_ACCOUNT, NULL, $member );
}
/* Get a local account if one exists */
@@ -368,7 +363,7 @@ class _ExternalDatabase extends \IPS\Login\Handler
/* Verify password */
if( !$this->_passwordIsValid( $result, $password ) )
{
throw new \IPS\Login\Exception( 'login_err_bad_password', \IPS\Login\Exception::BAD_PASSWORD, NULL, $member );
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_err_bad_password', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::BAD_PASSWORD, NULL, $member );
}
/* Create account if we don't have one */
+1 -1
View File
@@ -827,7 +827,7 @@ abstract class _Handler extends \IPS\Node\Model
public function form( &$form )
{
$form->addHeader('login_method_basic_settings');
$form->add( new \IPS\Helpers\Form\Translatable( 'login_method_name', $this->id ? NULL : \IPS\Member::loggedIn()->language()->addToStack( static::getTitle() ), TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'login_method_' . $this->id : NULL ) ) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'login_method_name', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'login_method_' . $this->id : NULL ) ) ) );
if ( !( $this instanceof \IPS\Login\Handler\Standard ) )
{
$self = $this;
+14 -4
View File
@@ -52,6 +52,8 @@ class _LDAP extends \IPS\Login\Handler
*/
public function acpForm()
{
$id = $this->id ?: 'new';
$return = array(
'ldap_header',
'server_protocol' => new \IPS\Helpers\Form\Radio( 'ldap_server_protocol', isset( $this->settings['server_protocol'] ) ? $this->settings['server_protocol'] : 3, TRUE, array( 'options' => array( 3 => 'V3', 2 => 'V2' ) ) ),
@@ -68,11 +70,11 @@ class _LDAP extends \IPS\Login\Handler
'email_field' => new \IPS\Helpers\Form\Text( 'ldap_email_field', isset( $this->settings['email_field'] ) ? $this->settings['email_field'] : 'mail' ),
'filter' => new \IPS\Helpers\Form\Text( 'ldap_filter', isset( $this->settings['filter'] ) ? $this->settings['filter'] : NULL, FALSE, array( 'placeholder' => 'ou=your_department' ) ),
'login_settings',
'auth_types' => new \IPS\Helpers\Form\Select( 'login_auth_types', isset( $this->settings['auth_types'] ) ? $this->settings['auth_types'] : ( \IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL ), TRUE, array( 'options' => array(
'auth_types' => new \IPS\Helpers\Form\Select( 'login_auth_types', isset( $this->settings['auth_types'] ) ? $this->settings['auth_types'] : ( \IPS\Login::AUTH_TYPE_EMAIL ), TRUE, array( 'options' => array(
\IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL => 'username_or_email',
\IPS\Login::AUTH_TYPE_EMAIL => 'email_address',
\IPS\Login::AUTH_TYPE_USERNAME => 'username',
) ) ),
), 'toggles' => array( \IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL => array( 'form_' . $id . '_login_auth_types_warning' ), \IPS\Login::AUTH_TYPE_USERNAME => array( 'form_' . $id . '_login_auth_types_warning' ) ) ) ),
'pw_required' => new \IPS\Helpers\Form\YesNo( 'ldap_pw_required', isset( $this->settings['pw_required'] ) ? $this->settings['pw_required'] : TRUE ),
);
if ( \IPS\Settings::i()->allow_forgot_password == 'normal' or \IPS\Settings::i()->allow_forgot_password == 'handler' )
@@ -244,7 +246,15 @@ class _LDAP extends \IPS\Login\Handler
/* Don't have anything? */
if ( !$result )
{
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack('login_err_no_account', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack('username') ) ) ), \IPS\Login\Exception::NO_ACCOUNT );
$member = NULL;
if ( $this->authType() & \IPS\Login::AUTH_TYPE_EMAIL )
{
$member = new \IPS\Member;
$member->email = $usernameOrEmail;
}
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_err_no_account', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::NO_ACCOUNT, NULL, $member );
}
/* Get a local account if one exists */
@@ -274,7 +284,7 @@ class _LDAP extends \IPS\Login\Handler
/* Verify password */
if ( !$this->_passwordIsValid( $result, $password ) )
{
throw new \IPS\Login\Exception( 'login_err_bad_password', \IPS\Login\Exception::BAD_PASSWORD, NULL, $member );
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_err_bad_password', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::BAD_PASSWORD, NULL, $member );
}
/* Create account if we don't have one */
+2 -3
View File
@@ -301,13 +301,13 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
*/
public function userProfilePhoto( \IPS\Member $member )
{
if ( !( $link = $this->_link( $member ) ) )
if ( !( $link = $this->_link( $member ) ) or ( $link['token_expires'] and $link['token_expires'] < time() ) )
{
throw new \IPS\Login\Exception( $error['message'], \IPS\Login\Exception::INTERNAL_ERROR );
}
$photoVars = explode( ':', $member->group['g_photo_max_vars'] );
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$link['token_identifier']}/picture?width={$photoVars[1]}&redirect=false" )->request()->get()->decodeJson();
$response = $this->_authorizedRequest( "{$link['token_identifier']}/picture?width={$photoVars[1]}&redirect=false", $link['token_access_token'], NULL, 'get' );
if ( !$response['data']['is_silhouette'] )
{
return \IPS\Http\Url::external( $response['data']['url'] );
@@ -630,5 +630,4 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
return $link;
}
}
+5
View File
@@ -22,6 +22,11 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _LinkedIn extends \IPS\Login\Handler\OAuth2
{
/**
* @brief Does this handler support PKCE?
*/
public $pkceSupported = FALSE;
/**
* Get title
*
+18 -2
View File
@@ -220,7 +220,15 @@ abstract class _OAuth2 extends \IPS\Login\Handler
{
if( !$usernameOrEmail )
{
throw new \IPS\Login\Exception( 'login_bad_username_or_password', \IPS\Login\Exception::NO_ACCOUNT );
$member = NULL;
if ( $this->authType() & \IPS\Login::AUTH_TYPE_EMAIL )
{
$member = new \IPS\Member;
$member->email = $usernameOrEmail;
}
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_bad_username_or_password', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::NO_ACCOUNT, NULL, $member );
}
$data = array(
@@ -251,7 +259,15 @@ abstract class _OAuth2 extends \IPS\Login\Handler
{
if ( isset( $accessToken['error'] ) and $accessToken['error'] === 'invalid_grant' )
{
throw new \IPS\Login\Exception( 'login_bad_username_or_password', \IPS\Login\Exception::NO_ACCOUNT );
$member = NULL;
if ( $this->authType() & \IPS\Login::AUTH_TYPE_EMAIL )
{
$member = new \IPS\Member;
$member->email = $usernameOrEmail;
}
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_bad_username_or_password', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::NO_ACCOUNT, NULL, $member );
}
\IPS\Log::log( print_r( $accessToken, TRUE ), 'oauth' );
+14 -4
View File
@@ -182,6 +182,16 @@ class _Wordpress extends \IPS\Login\Handler\OAuth2
return "core_custom_oauth_{$this->id}";
}
/**
* Should client credentials be sent as an "Authoriation" header, or as POST data?
*
* @return string
*/
protected function _authenticationType()
{
return static::AUTHENTICATE_POST; // Just because it's possible their server isn't configured to accept HTTP Authorization whereas we know this will always work
}
/**
* Grant Type
*
@@ -211,7 +221,7 @@ class _Wordpress extends \IPS\Login\Handler\OAuth2
*/
protected function authorizationEndpoint( \IPS\Login $login )
{
return \IPS\Http\Url::external( rtrim( $this->settings['wordpress_url'], "/" ) . "/wp-content/plugins/miniorange-oauth-20-server/web/moserver/authorize" );
return \IPS\Http\Url::external( rtrim( $this->settings['wordpress_url'], "/" ) . "/wp-json/moserver/authorize" );
}
/**
@@ -221,7 +231,7 @@ class _Wordpress extends \IPS\Login\Handler\OAuth2
*/
protected function tokenEndpoint()
{
return \IPS\Http\Url::external( rtrim( $this->settings['wordpress_url'], "/" ) . "/wp-content/plugins/miniorange-oauth-20-server/web/moserver/token" );
return \IPS\Http\Url::external( rtrim( $this->settings['wordpress_url'], "/" ) . "/wp-json/moserver/token" );
}
/**
@@ -361,7 +371,7 @@ class _Wordpress extends \IPS\Login\Handler\OAuth2
{
if ( !isset( $this->_cachedUserData[ $accessToken ] ) )
{
$data = \IPS\Http\Url::external( rtrim( $this->settings['wordpress_url'], "/" ) . "/wp-content/plugins/miniorange-oauth-20-server/web/moserver/resource" )
$data = \IPS\Http\Url::external( rtrim( $this->settings['wordpress_url'], "/" ) . "/wp-json/moserver/resource" )
->request()
->setHeaders( array(
'Authorization' => "Bearer {$accessToken}"
@@ -372,7 +382,7 @@ class _Wordpress extends \IPS\Login\Handler\OAuth2
/* As with the Custom handler - if we did not get expected data, try using the query string method. */
if ( !\count( $data ) )
{
$data = \IPS\Http\Url::external( rtrim( $this->settings['wordpress_url'], "/" ) . "/wp-content/plugins/miniorange-oauth-20-server/web/moserver/resource" )
$data = \IPS\Http\Url::external( rtrim( $this->settings['wordpress_url'], "/" ) . "/wp-json/moserver/resource" )
->setQueryString( 'access_token', $accessToken )
->request()
->get()
+12 -4
View File
@@ -54,7 +54,7 @@ class _Standard extends \IPS\Login\Handler
case \IPS\Login::AUTH_TYPE_USERNAME:
$type = 'username';
break;
break;
case \IPS\Login::AUTH_TYPE_EMAIL:
$type = 'email_address';
@@ -64,7 +64,7 @@ class _Standard extends \IPS\Login\Handler
/* Make sure we have the username or email */
if( !$usernameOrEmail )
{
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack('login_err_no_account', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $type ) ) ) ), \IPS\Login\Exception::NO_ACCOUNT );
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_err_no_account', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::NO_ACCOUNT );
}
/* Get member(s) */
@@ -97,7 +97,15 @@ class _Standard extends \IPS\Login\Handler
/* If we didn't match any, throw an exception */
if ( !\count( $members ) )
{
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack('login_err_no_account', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $type ) ) ) ), \IPS\Login\Exception::NO_ACCOUNT );
$member = NULL;
if ( $this->authType() & \IPS\Login::AUTH_TYPE_EMAIL )
{
$member = new \IPS\Member;
$member->email = $usernameOrEmail;
}
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_err_no_account', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::NO_ACCOUNT, NULL, $member );
}
/* Check the password for each possible account */
@@ -118,7 +126,7 @@ class _Standard extends \IPS\Login\Handler
}
/* Still here? Throw a password incorrect exception */
throw new \IPS\Login\Exception( 'login_err_bad_password', \IPS\Login\Exception::BAD_PASSWORD, NULL, $member );
throw new \IPS\Login\Exception( \IPS\Member::loggedIn()->language()->addToStack( 'login_err_bad_password', FALSE, array( 'pluralize' => array( $this->authType() ) ) ), \IPS\Login\Exception::BAD_PASSWORD, NULL, $member );
}
/**
@@ -53,12 +53,13 @@ trait UsernamePasswordHandler
*/
public function acpForm()
{
$id = $this->id ?: 'new';
return array(
'auth_types' => new \IPS\Helpers\Form\Select( 'login_auth_types', isset( $this->settings['auth_types'] ) ? $this->settings['auth_types'] : ( \IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL ), TRUE, array( 'options' => array(
'auth_types' => new \IPS\Helpers\Form\Select( 'login_auth_types', isset( $this->settings['auth_types'] ) ? $this->settings['auth_types'] : ( \IPS\Login::AUTH_TYPE_EMAIL ), TRUE, array( 'options' => array(
\IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL => 'username_or_email',
\IPS\Login::AUTH_TYPE_EMAIL => 'email_address',
\IPS\Login::AUTH_TYPE_USERNAME => 'username',
) ) )
), 'toggles' => array( \IPS\Login::AUTH_TYPE_USERNAME + \IPS\Login::AUTH_TYPE_EMAIL => array( 'form_' . $id . '_login_auth_types_warning' ), \IPS\Login::AUTH_TYPE_USERNAME => array( 'form_' . $id . '_login_auth_types_warning' ) ) ) )
);
}
+43 -31
View File
@@ -235,6 +235,7 @@ class _Login
$leastOffensiveException = NULL;
$success = NULL;
$fails = array();
$failsNoAccount = array();
foreach ( $this->usernamePasswordMethods() as $method )
{
@@ -265,7 +266,7 @@ class _Login
if ( $member )
{
static::checkIfAccountIsLocked( $member, TRUE );
$success = new Login\Success( $member, $method, isset( \IPS\Request::i()->remember_me ), $member->members_bitoptions['is_anon'] );
$success = new Login\Success( $member, $method, isset( \IPS\Request::i()->remember_me ) );
break;
}
}
@@ -275,6 +276,10 @@ class _Login
{
$fails[ $e->member->member_id ] = $e->member;
}
elseif( $e->getCode() === \IPS\Login\Exception::NO_ACCOUNT and $e->member AND $e->member->email )
{
$failsNoAccount[ $e->member->email ] = $e->member;
}
if ( $leastOffensiveException === NULL or $leastOffensiveException->getCode() < $e->getCode() )
{
@@ -294,6 +299,24 @@ class _Login
$failedMember->save();
}
}
foreach( $failsNoAccount as $failedMember )
{
if ( !$success or $success->member->email != $failedMember->email )
{
try
{
$failedLogins = \is_array( \IPS\Data\Store::i()->failedLogins ) ? \IPS\Data\Store::i()->failedLogins : array();
}
catch( \OutOfRangeException $e )
{
$failedLogins = array();
}
$failedLogins[ $failedMember->email ][ \IPS\Request::i()->ipAddress() ][] = time();
\IPS\Data\Store::i()->failedLogins = $failedLogins;
}
}
if ( $success )
{
@@ -335,7 +358,7 @@ class _Login
if ( $member = $method->authenticateButton( $this ) )
{
static::checkIfAccountIsLocked( $member, TRUE );
return new Login\Success( $member, $method, isset( \IPS\Request::i()->remember_me ), $member->members_bitoptions['is_anon'] );
return new Login\Success( $member, $method, isset( \IPS\Request::i()->remember_me ) );
}
}
}
@@ -348,7 +371,12 @@ class _Login
{
static::checkIfAccountIsLocked( $e->member );
}
/* Or if the account doesn't exist but we've tried the brute-force number of times, show the account is locked even though it doesn't exist */
elseif( $e->getCode() === \IPS\Login\Exception::NO_ACCOUNT and $e->member AND $e->member->email )
{
static::checkIfAccountIsLocked( $e->member );
}
/* If we're still here, throw the error we got */
throw $e;
}
@@ -362,6 +390,7 @@ class _Login
*
* @param \IPS\Member $member The account
* @param bool $success Boolean value indicating if the login was successful. If TRUE, and the account is not locked, failed logins will be removed.
* @note The $member object may be a guest object with an email address set
* @return void
* @throws \Exception
*/
@@ -371,7 +400,7 @@ class _Login
if ( $unlockTime !== FALSE )
{
/* Notify the member if they've been locked */
if( \count( $member->failed_logins[ \IPS\Request::i()->ipAddress() ] ) == \IPS\Settings::i()->ipb_bruteforce_attempts )
if( $member->failedLoginCount( \IPS\Request::i()->ipAddress() ) == \IPS\Settings::i()->ipb_bruteforce_attempts )
{
/* Can we get a physical location */
try
@@ -382,8 +411,12 @@ class _Login
{
$location = \IPS\Request::i()->ipAddress();
}
\IPS\Email::buildFromTemplate( 'core', 'account_locked', array( $member, $location, isset( $unlockTime ) ? $unlockTime : NULL ), \IPS\Email::TYPE_TRANSACTIONAL )->send( $member );
$member->logHistory( 'core', 'login', array( 'type' => 'lock', 'count' => \count( $member->failed_logins[ \IPS\Request::i()->ipAddress() ] ), 'unlockTime' => isset( $unlockTime ) ? $unlockTime->getTimestamp() : NULL ) );
if( $member->member_id )
{
\IPS\Email::buildFromTemplate( 'core', 'account_locked', array( $member, $location, isset( $unlockTime ) ? $unlockTime : NULL ), \IPS\Email::TYPE_TRANSACTIONAL )->send( $member );
$member->logHistory( 'core', 'login', array( 'type' => 'lock', 'count' => \count( $member->failed_logins[ \IPS\Request::i()->ipAddress() ] ), 'unlockTime' => isset( $unlockTime ) ? $unlockTime->getTimestamp() : NULL ) );
}
}
if ( \IPS\Settings::i()->ipb_bruteforce_period and \IPS\Settings::i()->ipb_bruteforce_unlock )
@@ -474,7 +507,8 @@ class _Login
$existingMember = \IPS\Member::load( $email, 'email' );
if ( $existingMember->member_id and ( !$exclude or $exclude->member_id != $existingMember->member_id ) )
{
return \IPS\Member::loggedIn()->language()->addToStack('member_email_exists');
$url = \IPS\Http\Url::internal( "app=core&module=system&controller=lostpass", "front", "lostpassword" );
return \IPS\Member::loggedIn()->language()->addToStack( 'member_email_exists', FALSE, array( 'sprintf' => array( (string) $url ) ) );
}
/* Check each handler */
@@ -488,7 +522,8 @@ class _Login
}
else
{
return \IPS\Member::loggedIn()->language()->addToStack('member_email_exists');
$url = \IPS\Http\Url::internal( "app=core&module=system&controller=lostpass", "front", "lostpassword" );
return \IPS\Member::loggedIn()->language()->addToStack( 'member_email_exists', FALSE, array( 'sprintf' => array( (string) $url ) ) );
}
}
}
@@ -619,27 +654,4 @@ class _Login
/* Member sync callback */
\IPS\Member::loggedIn()->memberSync( 'onLogout', array( $redirectUrl ?: \IPS\Http\Url::internal('') ) );
}
/* !Backwards Compatibility for login handlers created before 4.3 */
/**
* Get Legacy Handlers
*
* @deprecated
* @return array
*/
public static function handlers()
{
$return = array();
foreach ( \IPS\Db::i()->select( '*', 'core_login_methods', array( 'login_enabled=1' ) ) as $method )
{
$method = \IPS\Login\Handler::constructFromData( $method );
if ( $method instanceof \IPS\Login\LoginAbstract )
{
$return[ mb_substr( \get_class( $method ), 10 ) ] = $method;
}
}
return $return;
}
}
-202
View File
@@ -1,202 +0,0 @@
<?php
/**
* @brief 4.2 and below Backwards Compatibilty Login Handler
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 16 May 2017
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Login;
/* 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;
}
/**
* 4.2 and below Backwards Compatibilty Login Handler
*
* @deprecated This class exists only to provide backwards compatibility for login handlers created before 4.3
*/
abstract class _LoginAbstract extends \IPS\Login\Handler
{
/**
* Get title
*
* @return string
*/
public static function getTitle()
{
return 'login_handler_' . mb_substr( \get_called_class(), 10 );
}
/**
* Get type
*
* @return int
*/
public function type()
{
if ( method_exists( $this, 'loginForm' ) )
{
return \IPS\Login::TYPE_BUTTON;
}
else
{
return \IPS\Login::TYPE_USERNAME_PASSWORD;
}
}
/**
* Get auth type
*
* @return int
*/
public function authType()
{
return $this->authTypes;
}
/**
* Get button
*
* @return string
*/
public function button()
{
$destination = NULL;
if ( isset( \IPS\Request::i()->ref ) )
{
try
{
$url = \IPS\Http\Url::createFromString( base64_decode( \IPS\Request::i()->ref ) );
if ( $url instanceof \IPS\Http\Url\Internal and !$url->openRedirect() )
{
$destination = $url;
}
}
catch ( \Exception $e ) { }
}
try
{
return $this->loginForm( \IPS\Request::i()->url(), FALSE, $destination );
}
catch ( \Exception $exception )
{
\IPS\Log::log( $exception, 'login_handler' );
}
}
/**
* Authenticate
*
* @param \IPS\Login $login The login object
* @param string $usernameOrEmail The username or email address provided by the user
* @param object $password The plaintext password provided by the user, wrapped in an object that can be cast to a string so it doesn't show in any logs
* @return \IPS\Member
* @throws \IPS\Login\Exception
*/
public function authenticateUsernamePassword( \IPS\Login $login, $usernameOrEmail, $password )
{
return $this->authenticate( array( 'auth' => $usernameOrEmail, 'password' => (string) $password ) );
}
/**
* Authenticate
*
* @param \IPS\Login $login The login object
* @return \IPS\Member
* @throws \IPS\Login\Exception
*/
public function authenticateButton( \IPS\Login $login )
{
return $this->authenticate( $login->url );
}
/**
* Create an account from login - checks registration is enabled, the name/email doesn't already exists and calls the spam service
*
* @param \IPS\Member|NULL $member The existing member, if one exists
* @param array $memberProperties Any properties to set on the member (whether registering or not) such as IDs from third-party services
* @param string|NULL $name The desired username. If not provided, not allowed, or another existing user has this name, it will be left blank and the user prompted to provide it.
* @param string|NULL $email The user's email address. If it matches an existing account, an \IPS\Login\Exception object will be thrown so the user can be prompted to link those accounts. If not provided, it will be left blank and the user prompted to provide it.
* @param mixed $details If $email matches an existing account, this is wgat will later be provided to link() - include any data you will need to link the accounts later
* @param array|NULL $profileSync If creating a new account, the default profile sync settings for this provider
* @param string|NULL $profileSyncClass If $profileSync is enabled, the profile sync service with a name matching this login handler will be used. Provide an alternative classname to override (e.g. for Windows login, the login handler class is Live, but the profile sync class is Microsoft)
* @return \IPS\Member
* @throws \IPS\Login\Exception If email address matches (\IPS\Login\Exception::MERGE_SOCIAL_ACCOUNT), registration is disabled (IPS\Login\Exception::REGISTRATION_DISABLED) or the spam service denies registration (\IPS\Login\Exception::REGISTRATION_DENIED_BY_SPAM_SERVICE)
*/
protected function createOrUpdateAccount( $member, $memberProperties=array(), $name=NULL, $email=NULL, $details=NULL, $profileSync=NULL, $profileSyncClass=NULL )
{
/* Create an account */
if ( !$member or !$member->member_id )
{
try
{
$member = $this->createAccount( $name, $email );
}
catch ( \IPS\Login\Exception $e )
{
if ( $details )
{
$e->details = $details;
}
throw $e;
}
/* Member properties */
foreach ( $memberProperties as $k => $v )
{
$member->$k = $v;
}
$member->save();
}
/* Or just update? */
else
{
foreach ( $memberProperties as $k => $v )
{
$member->$k = $v;
if( $k == 'members_pass_hash' or $k == 'email' )
{
$member->invalidateSessionsAndLogins( \IPS\Session::i()->id );
}
}
$member->save();
}
/* Return */
return $member;
}
/**
* Can this handler process a password change for a member?
*
* @param \IPS\Member $member The member
* @return bool
*/
public function canChangePassword( \IPS\Member $member )
{
return method_exists( $this, 'canChange' ) ? $this->canChange( 'password', $member ) : FALSE;
}
/**
* Link Account
*
* @param \IPS\Member $member The member
* @param mixed $details Details as they were passed to the exception
* @return void
*/
public function completeLink( \IPS\Member $member, $details )
{
static::link( $member, $details );
}
}
+5 -8
View File
@@ -54,17 +54,17 @@ class _Success
* @param \IPS\Member $member The member who has successfully logged in
* @param \IPS\Login\Handler $handler The handler that processed the login
* @param bool $rememberMe If the "remember me" box was checked
* @param bool $anonymous If the "sign in anonymously" box was checked
* @param NULL|bool $anonymous If, NULL, honour the member's anonymous setting, if TRUE or FALSE then override with that value
* @param bool $sendNewDeviceEmail Should a new device email be sent.
* @return void
*/
public function __construct( \IPS\Member $member, \IPS\Login\Handler $handler, $rememberMe = TRUE, $anonymous = FALSE, $sendNewDeviceEmail = TRUE )
public function __construct( \IPS\Member $member, \IPS\Login\Handler $handler, $rememberMe = TRUE, $anonymous = NULL, $sendNewDeviceEmail = TRUE )
{
$this->member = $member;
$this->device = \IPS\Member\Device::loadOrCreate( $member, $sendNewDeviceEmail );
$this->handler = $handler;
$this->rememberMe = $rememberMe;
$this->anonymous = ( $anonymous or $member->group['g_hide_online_list'] );
$this->anonymous = ( $anonymous === NULL ) ? ( $member->members_bitoptions['is_anon'] or $member->group['g_hide_online_list'] ) : $anonymous;
}
/**
@@ -102,17 +102,14 @@ class _Success
\IPS\Session::i()->setMember( $this->member );
if ( $this->anonymous )
{
if ( !\IPS\Settings::i()->disable_anonymous )
{
\IPS\Session::i()->setAnon();
}
\IPS\Session::i()->setAnon();
}
$this->member->last_visit = $this->member->last_activity;
$this->member->save();
/* Log device */
$this->device->anonymous = $this->anonymous and !\IPS\Settings::i()->disable_anonymous;
$this->device->anonymous = $this->anonymous;
$this->device->updateAfterAuthentication( $this->rememberMe, $this->handler );
/* Remove any noCache cookies */