Beispiel #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 );
					}
				}
			}
		}
	}
	/**
	 * Saves a user block
	 *
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function saveBlock( $id, $user )
	{
		global $_CB_framework, $ueConfig;

		$profileUrl		=	$_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $this->_tab );

		if ( ! $user->get( 'id' ) ) {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}

		$row			=	new cbantispamBlockTable();

		$row->load( (int) $id );

		$row->set( 'type', $this->input( 'type', $row->get( 'type' ), GetterInterface::STRING ) );
		$row->set( 'value', $this->input( 'value', $row->get( 'value' ), GetterInterface::STRING ) );
		$row->set( 'reason', $this->input( 'reason', $row->get( 'reason' ), GetterInterface::STRING ) );
		$row->set( 'date', $this->input( 'date', $row->get( 'date', '0000-00-00 00:00:00' ), GetterInterface::STRING ) );
		$row->set( 'duration', $this->input( 'duration', $row->get( 'duration' ), GetterInterface::STRING ) );

		if ( $row->get( 'type' ) == '' ) {
			$row->setError( CBTxt::T( 'Type not specified!' ) );
		} elseif ( $row->get( 'value' ) == '' ) {
			$row->setError( CBTxt::T( 'Value not specified!' ) );
		} elseif ( ( $row->get( 'date' ) == '' ) || ( $row->get( 'date' ) == '0000-00-00 00:00:00' ) ) {
			$row->setError( CBTxt::T( 'Date not specified!' ) );
		}

		if ( $row->getError() || ( ! $row->store() ) ) {
			$this->showBlock( $id, $row->get( 'type' ), $user, CBTxt::T( 'BLOCK_SAVE_FAILED', 'Block failed to save! Error: [error]', array( '[error]' => $row->getError() ) ) );
			return;
		}

		if ( $row->get( 'type' ) == 'user' ) {
			if ( isset( $ueConfig['allowUserBanning'] ) && $ueConfig['allowUserBanning'] ) {
				if ( $this->input( 'ban_user', 0, GetterInterface::INT ) && ( ! $user->get( 'banned' ) ) ) {
					if ( ! $user->banUser( 1, null, $this->input( 'ban_reason', null, GetterInterface::STRING ) ) ) {
						$this->showBlock( $id, $row->get( 'type' ), $user, CBTxt::T( 'BLOCK_PROFILE_BAN_FAILED', 'Block saved successfully, but Profile Ban failed to save! Error: [error]', array( '[error]' => $user->getError() ) ) );
						return;
					}
				}
			}

			if ( $this->input( 'block_user', 0, GetterInterface::INT ) && ( ! $user->get( 'block' ) ) ) {
				$user->set( 'block', 1 );

				if ( ! $user->storeBlock() ) {
					$this->showBlock( $id, $row->get( 'type' ), $user, CBTxt::T( 'BLOCK_PROFILE_BLOCK_FAILED', 'Block saved successfully, but Profile Block failed to save! Error: [error]', array( '[error]' => $user->getError() ) ) );
					return;
				}
			}
		}

		cbRedirect( $profileUrl, CBTxt::T( 'Block saved successfully!' ) );
	}