Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+38 -25
View File
@@ -11,16 +11,27 @@
namespace IPS\Helpers\Form;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use InvalidArgumentException;
use IPS\Db;
use IPS\Login;
use IPS\Member;
use IPS\Settings;
use function count;
use function defined;
use function mb_stripos;
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;
}
/**
* Email input class for Form Builder
*/
class _Email extends Text
class Email extends Text
{
/**
* @brief Default Options
@@ -30,89 +41,91 @@ class _Email extends Text
);
* @endcode
*/
public $childDefaultOptions = array(
public array $childDefaultOptions = array(
'accountEmail' => FALSE,
'htmlAutocomplete' => "email",
'bypassProfanity' => \IPS\Helpers\Form\Text::BYPASS_PROFANITY_ALL
'bypassProfanity' => Text::BYPASS_PROFANITY_ALL
);
/**
* Validate
*
* @param string $value The provided value (an email address)
* @param bool|\IPS\Member $accountEmail If TRUE, additional checks will be performed to ensure provided email address is acceptable for use on a user's account. If an \IPS\Member object, that member will be excluded
* @throws \InvalidArgumentException
* @throws \DomainException
* @param string $value The provided value (an email address)
* @param bool|Member $accountEmail If TRUE, additional checks will be performed to ensure provided email address is acceptable for use on a user's account. If an \IPS\Member object, that member will be excluded
* @return TRUE
*@throws DomainException
* @throws InvalidArgumentException
*/
public static function validateEmail( $value, $accountEmail )
public static function validateEmail(string $value, bool|Member $accountEmail=NULL )
{
/* Check it's generally an acceptable email */
if ( $value !== '' and filter_var( $value, FILTER_VALIDATE_EMAIL ) === FALSE )
{
throw new \InvalidArgumentException('form_email_bad');
throw new InvalidArgumentException('form_email_bad');
}
/* If it's for a user account, do additional checks */
if ( $accountEmail )
{
/* Check if it exists */
if ( $error = \IPS\Login::emailIsInUse( $value, ( $accountEmail instanceof \IPS\Member ) ? $accountEmail : NULL, \IPS\Member::loggedIn()->isAdmin() ) )
if ( $error = Login::emailIsInUse( $value, ( $accountEmail instanceof Member ) ? $accountEmail : NULL, Member::loggedIn()->isAdmin() ) )
{
throw new \DomainException( $error );
throw new DomainException( $error );
}
/* Check Banned and Allowed Emails only if the data are not coming from an administrator */
if ( !\IPS\Member::loggedIn()->isAdmin() )
if ( !Member::loggedIn()->isAdmin() )
{
/* Check it's not known to be undeliverable */
if ( \IPS\Email::emailIsBlocked( $value ) )
{
throw new \DomainException( 'member_email_blocked_info' );
throw new DomainException( 'member_email_blocked_info' );
}
/* Check it's not a banned address */
foreach ( \IPS\Db::i()->select( 'ban_content', 'core_banfilters', array( "ban_type=?", 'email' ) ) as $bannedEmail )
foreach ( Db::i()->select( 'ban_content', 'core_banfilters', array( "ban_type=?", 'email' ) ) as $bannedEmail )
{
if ( preg_match( '/^' . str_replace( '\*', '.*', preg_quote( $bannedEmail, '/' ) ) . '$/i', $value ) )
{
throw new \DomainException( 'form_email_banned' );
throw new DomainException( 'form_email_banned' );
}
}
/* Check it's an allowed domain */
if ( \IPS\Settings::i()->allowed_reg_email !== '' AND $allowedEmailDomains = explode( ',', \IPS\Settings::i()->allowed_reg_email ) )
if ( Settings::i()->allowed_reg_email !== '' AND $allowedEmailDomains = explode( ',', Settings::i()->allowed_reg_email ) )
{
$matched = FALSE;
foreach ( $allowedEmailDomains AS $domain )
{
if( \mb_stripos( $value, "@" . $domain ) !== FALSE )
if( mb_stripos( $value, "@" . $domain ) !== FALSE )
{
$matched = TRUE;
}
}
if ( \count( $allowedEmailDomains ) AND !$matched )
if ( count( $allowedEmailDomains ) AND !$matched )
{
throw new \DomainException( 'form_email_banned' );
throw new DomainException( 'form_email_banned' );
}
}
}
}
return TRUE;
}
/**
* Validate
*
* @throws \InvalidArgumentException
* @throws \DomainException
* @throws InvalidArgumentException
* @throws DomainException
* @return TRUE
*/
public function validate()
public function validate(): bool
{
parent::validate();
static::validateEmail( $this->value, $this->options['accountEmail'] );
return static::validateEmail( $this->value, $this->options['accountEmail'] );
}
}