Пример #1
0
	/**
	 * Handles registration blocking
	 *
	 * @param UserTable $user
	 * @param UserTable $userDuplicate
	 */
	public function onBeforeUserRegistration( &$user, &$userDuplicate )
	{
		global $_CB_framework, $_CB_database, $_PLUGINS;

		$ipAddresses					=	cbGetIParray();
		$ipAddress						=	trim( array_shift( $ipAddresses ) );
		$blocked						=	cbantispamClass::getUserBlock( $user, $ipAddress );

		if ( $blocked ) {
			$this->blockRegistration( $blocked->get( 'reason' ), $blocked->get( 'duration' ), $blocked->get( 'date' ), $blocked->getExpire() );
		} elseif ( ( ( ! $_PLUGINS->is_errors() ) && ( ! $user->getError() ) ) ) {
			if ( $this->params->get( 'reg_duplicate', 0 ) ) {
				if ( ! cbantispamClass::isUserBlockable( $user, $ipAddress ) ) {
					return;
				}

				$timeframe				=	$this->params->get( 'reg_duplicate_timeframe', '-1 YEAR' );

				$query					=	'SELECT COUNT(*)'
										.	"\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_log' ) . " AS l"
										.	"\n INNER JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS u"
										.	' ON u.' . $_CB_database->NameQuote( 'id' ) . ' = l.' . $_CB_database->NameQuote( 'user_id' )
										.	"\n WHERE l." . $_CB_database->NameQuote( 'ip_address' ) . " = " . $_CB_database->Quote( $ipAddress );
				if ( $timeframe ) {
					$query				.=	"\n AND l." . $_CB_database->NameQuote( 'date' ) . " >= " . $_CB_database->Quote( $_CB_framework->getUTCDate( 'Y-m-d H:i:s', $timeframe ) );
				}
				$_CB_database->setQuery( $query );
				$accounts				=	$_CB_database->loadResult();

				$count					=	(int) $this->params->get( 'reg_duplicate_count', 1 );

				if ( ! $count ) {
					$count				=	1;
				}

				if ( $accounts >= $count ) {
					$method				=	(int) $this->params->get( 'reg_duplicate_method', 0 );
					$reason				=	$this->params->get( 'reg_duplicate_reason', 'Already registered.' );

					if ( $method == 1 ) {
						$row			=	new cbantispamBlockTable();

						$row->set( 'type', 'ip' );
						$row->set( 'value', $ipAddress );
						$row->set( 'date', $_CB_framework->getUTCDate() );
						$row->set( 'duration', $this->params->get( 'reg_duplicate_dur', '+1 HOUR' ) );
						$row->set( 'reason', $reason );

						$row->store();

						$this->blockRegistration( $row->get( 'reason' ), $row->get( 'duration' ), $row->get( 'date' ), $row->getExpire() );
					} else {
						$this->blockRegistration( $reason );
					}
				}
			}
		}
	}