Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
+38
-26
@@ -12,56 +12,68 @@
|
||||
namespace IPS\Login;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\DateTime;
|
||||
use IPS\Events\Event;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Login;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Device;
|
||||
use IPS\MFA\MFAHandler;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Successful Login Result
|
||||
*/
|
||||
class _Success
|
||||
class Success
|
||||
{
|
||||
/**
|
||||
* @brief The member who has successfully logged in
|
||||
*/
|
||||
public $member;
|
||||
public Member $member;
|
||||
|
||||
/**
|
||||
* @brief The device
|
||||
*/
|
||||
public $device;
|
||||
public Device $device;
|
||||
|
||||
/**
|
||||
* @brief The handler that processed the login
|
||||
*/
|
||||
public $handler;
|
||||
public Handler $handler;
|
||||
|
||||
/**
|
||||
* @brief If the "remember me" box was checked
|
||||
*/
|
||||
public $rememberMe = TRUE;
|
||||
public bool $rememberMe = TRUE;
|
||||
|
||||
/**
|
||||
* @brief If the "sign in anonymously" box was checked
|
||||
*/
|
||||
public $anonymous = FALSE;
|
||||
public bool $anonymous = FALSE;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @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 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.
|
||||
* @param Member $member The member who has successfully logged in
|
||||
* @param Handler $handler The handler that processed the login
|
||||
* @param bool $rememberMe If the "remember me" box was checked
|
||||
* @param bool|null $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 = NULL, $sendNewDeviceEmail = TRUE )
|
||||
public function __construct( Member $member, Handler $handler, bool $rememberMe = TRUE, bool $anonymous = NULL, bool $sendNewDeviceEmail = TRUE )
|
||||
{
|
||||
$this->member = $member;
|
||||
$this->device = \IPS\Member\Device::loadOrCreate( $member, $sendNewDeviceEmail );
|
||||
$this->device = Device::loadOrCreate( $member, $sendNewDeviceEmail );
|
||||
$this->handler = $handler;
|
||||
$this->rememberMe = $rememberMe;
|
||||
$this->anonymous = ( $anonymous === NULL ) ? ( $member->members_bitoptions['is_anon'] or $member->group['g_hide_online_list'] ) : $anonymous;
|
||||
@@ -70,19 +82,19 @@ class _Success
|
||||
/**
|
||||
* Get two-factor authentication form required to process login
|
||||
*
|
||||
* @param string|NULL $area The area being accessed or NULL to automatically use AuthenticateFront(Known)
|
||||
* @param string|null $area The area being accessed or NULL to automatically use AuthenticateFront(Known)
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function mfa( $area = NULL )
|
||||
public function mfa( string $area = NULL ): ?string
|
||||
{
|
||||
\IPS\MFA\MFAHandler::resetAuthentication();
|
||||
MFAHandler::resetAuthentication();
|
||||
|
||||
if ( !$area )
|
||||
{
|
||||
$area = $this->device->known ? 'AuthenticateFrontKnown' : 'AuthenticateFront';
|
||||
}
|
||||
|
||||
return \IPS\MFA\MFAHandler::accessToArea( 'core', $area, \IPS\Http\Url::internal( '' ), $this->member );
|
||||
return MFAHandler::accessToArea( 'core', $area, Url::internal( '' ), $this->member );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,19 +102,19 @@ class _Success
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process()
|
||||
public function process() : void
|
||||
{
|
||||
/* First, if we are already logged in as someone, log out */
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
if ( Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Login::logout();
|
||||
Login::logout();
|
||||
}
|
||||
|
||||
/* Log in */
|
||||
\IPS\Session::i()->setMember( $this->member );
|
||||
Session::i()->setMember( $this->member );
|
||||
if ( $this->anonymous )
|
||||
{
|
||||
\IPS\Session::i()->setAnon();
|
||||
Session::i()->setAnon();
|
||||
}
|
||||
|
||||
$this->member->last_visit = $this->member->last_activity;
|
||||
@@ -113,10 +125,10 @@ class _Success
|
||||
$this->device->updateAfterAuthentication( $this->rememberMe, $this->handler );
|
||||
|
||||
/* Remove any noCache cookies */
|
||||
\IPS\Request::i()->setCookie( 'noCache', 0, \IPS\DateTime::ts( time() - 86400 ) );
|
||||
Request::i()->setCookie( 'noCache', 0, DateTime::ts( time() - 86400 ) );
|
||||
|
||||
/* Member sync */
|
||||
$this->member->memberSync( 'onLogin' );
|
||||
Event::fire( 'onLogin', $this->member );
|
||||
$this->member->profileSync();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user