<?php
defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.plugin.plugin');
require_once(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_kip'.DS.'helpers'.DS.'ipfilter.php');

class plgUserKip extends JPlugin
{
	function plgUserKip(& $subject, $config) {
		parent::__construct($subject, $config);
		$this->loadLanguage('com_kip');
	}

	function onLoginUser($user, $options = array())
	{
		jimport('joomla.user.helper');
		$userid = JUserHelper::getUserId($user['username']);
		if(KipHelperIpfilter::isIpBlockedForUser($_SERVER['REMOTE_ADDR'], $userid))
		{
			$app =& JFactory::getApplication();
			KipHelperIpfilter::logUserOut($userid, intval($app->isAdmin()));

			$config = & KipConfig::getInstance();
			if($config->get('users.filtering_warning')){
				JError::raiseWarning(ERROR_BANNED_IP, JText::sprintf( 'IP blocked for user', $_SERVER['REMOTE_ADDR'] ));
			}
		}
	}
	
}
