beck24 / spam_login_filter

1 stars 2 forks source link

Country Blacklist Feature #8

Closed rohit1290 closed 5 years ago

rohit1290 commented 8 years ago

I really loved the feature where I can restrict country from registering on my elgg website. I understand that it was fassim feature and you removed it when you removed fassim. That is why I have a new code that can help in bringing back the feature without fassim. You just need to paste the below code in your lib/function.php file in the check_spammer() function.

if (!$spammer) {
    //Country Blacklist
    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$register_ip));    
        if($ip_data && $ip_data->geoplugin_countryName != null){
            $geo_country = $ip_data->geoplugin_countryCode;
        }

        $country_blacklisted = elgg_get_plugin_setting('fassim_blocked_country_list', "spam_login_filter");
        $country_blacklisted = str_replace(' ', '', $country_blacklisted); // cleanup
        $country_list = explode(",",$country_blacklisted);
        if (in_array($geo_country, $country_list)) {
            register_error(elgg_echo('Access denied as the service is not available in your country.'));
            notify_admin($register_email, $register_ip, "Country blacklist");
            $spammer = true;
        }
}
rohit1290 commented 8 years ago

And in spam_login_filter\views\default\plugins\spam_login_filter\setting.php add this:

// Country BlackList
$title = elgg_echo("Country Blacklist");

$content = "<div class='mbs'>";     
$content .= elgg_echo("Block the following countries:");        
$content .= elgg_view("input/text", array("name" => "params[fassim_blocked_country_list]", "value" => $plugin->fassim_blocked_country_list));       
$content .= elgg_view("output/longtext", array("value" => elgg_echo("(Just type in the country abbreviation of the countries you want to block, for multiple countries separated by comma, e.g. US,LV,HK. For a full list of supported country abbreviations click <a href='http://www.worldatlas.com/aatlas/ctycodes.htm' target='_blank'>Country Codes</a>)"), "class" => "elgg-subtext"));       
$content .= "</div>";

echo elgg_view_module("inline", $title, $content);
beck24 commented 8 years ago

I'll add this back in at some point, thanks

rohit1290 commented 6 years ago

@beck24 will this be included in next version of the plugin.