Advertisement:

Author Topic: [TIP] Stop Spam Registration - FINALLY  (Read 10868 times)

darmeth

  • Jr. Member
  • **
  • Posts: 75
[TIP] Stop Spam Registration - FINALLY
« on: December 14, 2014, 02:28:10 pm »
Here is a quick, easy, free solution to stop spam registration.

BEFORE: Up to 50 spam user registrations per day
AFTER: 0. Zero. Nada.

PLEASE, IF SOMEONE CAN HELP CONVERT THIS INTO A PLUGIN, THIS WILL BE MOST WELCOME

Tested on 3.5.0 - 3.5.2 with Modern theme.

In oc-include/osclass/frm/Userformclass.php, find this:

Code: [Select]
static public function info_textarea($name, $locale = 'en_US', $value = '') {
            parent::generic_textarea($name . '[' . $locale . ']', $value);
        }

UNDERNEATH IT, ADD:

Code: [Select]
static public function human_check_text($user = null) {
            parent::generic_input_text('humancheck',$value='If you are, please delete all this text',$maxlength='40') ;
        }

In oc-include/osclass/UserActions.php, find this:

Code: [Select]
if($flash_error!='') {
                osc_run_hook('user_register_failed', $error);
                return $flash_error;
            }

UNDERNEATH IT, ADD:

Code: [Select]
if( Params::getParam('humancheck', false, false) !== '') {
                return $flash_error .= _m("Human check must be empty") . PHP_EOL;
                    $error[] = 11;
            }

In Theme/user-register.php, find this:

Code: [Select]
<?php osc_run_hook('user_register_form'); ?>
                        <?php osc_show_recaptcha('register'); ?>

UNDERNEATH IT, ADD:

Code: [Select]
<div class="row">
                            <label for="humancheck"><?php _e('Are you Human?''modern') ; ?><em style="color:red"> *</em></label>
                                            <?php UserForm::human_check_text() ; ?>
                        </div>

« Last Edit: December 14, 2014, 02:31:12 pm by darmeth »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #1 on: January 10, 2015, 03:10:56 pm »
Hi Darmeth,

I like this simple solution without the need to register recaptcha though it would be nice to make it generic so it can also be used when user's are not logged in and posting comments or contact sellers. I just finished a plugin and it gave me some insights I might use to make this into a small plugin. No promisses or guarantees but I will see what I can do.  8)

If I have something working I would like you to help me testing it before putting it up for all.

Regards,
Eric

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #2 on: January 12, 2015, 08:23:54 pm »
OKAY, got something but I am STUCK!  ???

So I thought let's see if there's a bright young man here that can help us out figuring out how to add validation.
The code below is the actual plugin so far, if you save the code into 'index.php' and put it in a folder called 'ruHuman' and then zip it you can actually add this as a plugin in your admin menu. BUT, it only ads the input field and the most important part, the validation / action is missing so it's pretty much useless the way it is right now. Any help is appreciated....

(I thought about adding javascript, extending the class it concerns but .... stuck, maybe it is not possible?)

Code: [Select]
<?php
/*
  Plugin Name: ruHuman
  Plugin URI: 
  Description: This plugin adds simple Anti-Spam registration check
  Version: 1.0
  Author: Community
  Author URI: http://www.spulleboel.nl
  Author Email: Go visit the OSClass forums
  Short Name: ruHuman
  Plugin update URI: 
 */

//Set your Plugin version to 1.0
define('RUHUMAN_VERSION''1.0');

// This function adds the input box to the registration form, works fine!
function ruHuman() { ?>

<div class="row">
<label for="humancheck"><?php _e('Are you Human?''modern') ; ?><em style="color:red"> *</em></label>
<?php CheckHumanInput::human_check_text() ; ?>
</div>
<?php }

// This function should create / add validation for the input field we just added to the form
// The code as mentioned in the forums can be added by extending the class BUT I have no clue how to get this working.
function ruHumanCheck() { ?>


<!-- HOW DO WE ADD THE FORM VALIDATION ? IS THIS POSSIBLE OR IS IT BETTER TO JUST MAKE THE WHOLE THING IN THE THEME ?? -->

<?php }

// We create an extended class so we can add the new input field to the registration form
class CheckHumanInput extends UserForm {
static public function human_check_text($user null) {
            
parent::generic_input_text('humancheck',$value='If you are, please delete all this text',$maxlength='40') ;
}
}

// Let's add the ruHuman to the registration form, we use the hook 'user_register_form' for this et voila :)
osc_add_hook('user_register_form','ruHuman');

// Underneith I tried to add a validation using header/footer hook but the fact is that the form has OSClass validation
// which I do not know how to use for what we want to achieve.
// ==> osc_add_hook('should we use a hook?','ruHumanCheck'); <==

// This is needed in order to be able to activate the plugin
osc_register_plugin(osc_plugin_path(__FILE__)) ;
// This is a hack to show a Uninstall link at plugins table
osc_add_hook(osc_plugin_path(__FILE__) . '_uninstall') ;
?>



Regards,
Eric

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #3 on: January 12, 2015, 11:34:09 pm »
Hi,

This seems to work for me:

Code: [Select]
<?php
function ruHumanCheck() { 

    if(
Params::getParam('humancheck') != '') { // Text hasn't been deleted
        
osc_add_flash_error_message('Get out, you nasty robot!');
        
osc_redirect_toosc_item_post_url()) ;        
    }
}

osc_add_hook('pre_item_add''ruHumanCheck');
?>


Regards

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #4 on: January 13, 2015, 01:44:16 am »
Hi teseo,

thanks for looking along, your code is meant for item publish :)

Here's my current index.php code, it MIGHT work, haven't tested it yet.

Code: [Select]
<?php
/*
  Plugin Name: ruHuman
  Plugin URI: 
  Description: This plugin adds simple Anti-Spam registration check
  Version: 1.0
  Author: Community
  Author URI: 
  Author Email: Go visit the OSClass forums
  Short Name: ruHuman
  Plugin update URI: 
 */

//Set your Plugin version
define('RUHUMAN_VERSION''1.0');

// This function adds the input box to the registration form, works fine!
function ruHuman() { ?>

<div class="row">
<label for="humancheck"><?php _e('Are you Human?''modern') ; ?><em style="color:red"> *</em></label>
<?php CheckHumanInput::human_check_text() ; ?>
</div>
<?php }

// This function should create / add validation for the input field we just added to the form
// The code as mentioned in the forums can be added by extending the class BUT I have no clue how to get this working.
function ruHumanCheck() { 

    if(
Params::getParam('humancheck') != '') { // Text hasn't been deleted
        
osc_add_flash_error_message('Get out, you nasty robot!');
        
osc_redirect_toosc_register_account_url() ) ;        
    }
}

// We create an extended class so we can add the new input field to teh registration form
class CheckHumanInput extends UserForm {
static public function human_check_text($user null) {
            
parent::generic_input_text('humancheck',$value='If you are, please delete all this text',$maxlength='40') ;
}
}

// Let's add the ruHuman to the registration form, we use the hook 'user_register_form' for this et voila :)
osc_add_hook('user_register_form','ruHuman');

// Underneith I tried to add a validation using header/footer hook but the fact is that the form has OSClass validation
// which I do not know how to use for what we want to achieve.
osc_add_hook('pre_user_post''ruHumanCheck');

// This is needed in order to be able to activate the plugin
osc_register_plugin(osc_plugin_path(__FILE__)) ;
// This is a hack to show a Uninstall link at plugins table
osc_add_hook(osc_plugin_path(__FILE__) . '_uninstall') ;
?>

« Last Edit: January 13, 2015, 02:02:23 am by SmaRTeY »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #5 on: January 13, 2015, 01:59:54 am »
Hi SmaRTey,

replace the hook
Code: [Select]
osc_add_hook('pre_item_add', 'ruHumanCheck');

with

Code: [Select]
osc_add_hook('before_user_register', 'ruHumanCheck');

and it should work.

Regards

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #6 on: January 13, 2015, 02:04:38 am »
Okay, thanks again, will check it tomorrow....noticed I used the 'old' hook which was mentioned in the forums. :-X


Best Regards,
Eric

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #7 on: January 13, 2015, 02:13:58 am »
Sorry, I didn't realize you were operating over users, @dev101's is the equivalent to mine for items. Anyway, here's a good mechanism for server side validation of any form field.  ;)

Regards

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #8 on: January 13, 2015, 09:43:19 pm »
It works!  8)

Guys.... thanks for helping out!
Nice there's another small plugin that is not only pretty easy to understand also gives more insight to others...I hope!

So, Darmeth, here's what you wished for, hope it will tickle you (and others) into making plugins as well  ;D


Regards,
Eric

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #9 on: January 25, 2015, 01:12:06 am »
I am analysing how to expand this plugin so it can also be used in item-contact, item-post, item-comment and maybe other parts of Osclass. Item-contact I have working now as well so on to the next....

I know there are at least 3 plugins available (sweet captcha / recaptcha en math plugin (paid)) but both the sweet and recaptcha depend on 3rd parties and there is no other free captcha plugin as far as I know.

Anybody else interested in this?  ::)


Regards,
Eric

maakuone

  • Newbie
  • *
  • Posts: 39
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #10 on: January 25, 2015, 07:55:47 pm »
frosticek - that one is paid

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #11 on: January 25, 2015, 08:53:35 pm »
@maakuone
I though you are considering also paid solutions

I know there are at least 3 plugins available (sweet captcha / recaptcha en math plugin (paid)) but both ...

If you consider hours of work to making such solution 100% working, you will see you lost much more. I prefer looking for different solutions that those already existing.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #12 on: January 26, 2015, 06:01:58 pm »
Hi,

I am much in favor of Open Source Frosticek that is why I am asking here as well as spending time in 'learning' Osclass and helping others in understanding Osclass better hoping they will also contribute Open Source in return  8)

I do not like the dependancies in my website and I do not want to pay for a plugin I can create myself.
Also I am not trying to create a 100% Anti Spam solution, just a simple captcha like the paid math captcha but open source and free...

In the mean time I am also looking into the osclass_pm plugin from Trains, I have nearly finished all I want for having a good working messaging plugin that fits the theme I bought. I will share it for free with the theme creator hoping ALL themes will have more and better support for the existing plugins so joy for all. Same for the 'offer' plugin from Trains, I found it not to be working 100% but close to so this will be my next personal project....

I will probably also look into a plugin that combines some things from existing plugins... since they are also open source and free I will keep mine free as well. Once I get to that you'll know it in the forums as well  ;D

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #13 on: January 27, 2015, 12:46:54 am »
@SmaRTeY
Writing your message you got back to my question: ... that fits the theme I bought ...
So, why you would buy something if you can do it by yourself? Because it is lose of time and you can invest that time to more valuable activity, like doing something that is already not.
Why you would do same captcha as is paid math? Again, losing of time.

Anyway, I am big fan of osclass progress and looking for more and more cool plugins, but those that brings something new and are not just copies, paid of free ;)  ... because even you finish your plugin, it does not bring anything new, anything that does not already exists and expand osclass  ::)

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: [TIP] Stop Spam Registration - FINALLY
« Reply #14 on: January 27, 2015, 12:59:56 am »
Ha but in this case it would actually be something new.... in a sense that people can use something without the need to pay and have the ability to go without the 3rd party websites  ;)

But I agree, other more interesting plugins are very welcome! (open source of course!)  8)

Regards,
Eric