Difference between revisions of "Recaptcha"

From EPrints Documentation
Jump to: navigation, search
m (Added categories)
m
 
Line 39: Line 39:
 
<component surround="None"><field ref="captcha" /></component>
 
<component surround="None"><field ref="captcha" /></component>
 
</source>
 
</source>
''If you are running multiple archives and some need reCAPTCHA and others don't, copy the register.pl file into ~/archives/ARCHIVEID/workflows/user/ and edit it there.''
+
''If you are running multiple archives and some need reCAPTCHA and others don't, copy the register.xml file into ~/archives/ARCHIVEID/workflows/user/ and edit it there.''
  
 
Reload the configuration again, and then visit your 'Create Account' page - you should have a nice shiny reCAPTCHA added to the registration!
 
Reload the configuration again, and then visit your 'Create Account' page - you should have a nice shiny reCAPTCHA added to the registration!

Latest revision as of 15:08, 5 March 2014

NOTE: This has been written based on my experience of an EPrints 3.3.10 install.

Configuring reCAPTCHA for user registration

Recent versions of EPrints (3.2+?) have configuration that allows reCAPTCHA to be used for user registration and/or document requests. If your version of EPrints has the file: ~/perl_lib/EPrints/MetaField/Recaptcha.pm, these instructions *should* work...

What to do

  1. Register for a reCAPTCHA key at http://www.google.com/recaptcha (Click on the 'Use reCAPTCHA on your site' link).
  2. Add reCAPTCHA keys to config
  3. Configure a field to use reCAPTCHA
  4. Add field to workflow

Adding the config

Create a file: ~/archives/ARCHIVEID/cfg/cfg.d/recaptcha.pl

# Used by recaptcha fields. See ~/perl_lib/EPrints/MetaField/Recaptcha.pm
# Captcha registered by you@your-institution
$c->{recaptcha}->{public_key} = "...";
$c->{recaptcha}->{private_key} = "...";

Add the keys you got when registering for reCAPTCHA.

You can create either domain specific keys, or general purpose keys. If you run multiple archives you might want to create general keys and add the config file to ~/lib/cfg.d/ instead.

Adding reCAPTCHA to User Registration

First we have to add the reCAPTCHA field to the user config. I added the following code to the end of my recaptcha.pl file, but you could also add the field definition directly to the 'user_fields.pl' file.

#Add field to user dataset
$c->add_dataset_field( "user", {
        name => "captcha",
        type => "recaptcha",
});

Now reload the configuration and update the database (through the web interface Admin->Config. Tools -> Reload Config / Update Database) - or via the command line.

Next, we have to add the field to the user registration workflow. If you haven't edited the registration workflow, look at ~/lib/workflows/user/register.xml. Add the following component after the existing Field::Multi component.

<component surround="None"><field ref="captcha" /></component>

If you are running multiple archives and some need reCAPTCHA and others don't, copy the register.xml file into ~/archives/ARCHIVEID/workflows/user/ and edit it there.

Reload the configuration again, and then visit your 'Create Account' page - you should have a nice shiny reCAPTCHA added to the registration!


Adding reCAPTCHA to Document requests

This is similar to the above, basically add a field to the request dataset, render it in the workflow (did you know that requests now have a workflow? I didn't!).

Add the following to recaptcha.pl - or another suitable cfg.d/...pl file:

#Add field to requests
$c->add_dataset_field( "request", {
        name => "captcha",
        type => "recaptcha",
});

Add the field to the workflow for requests ~/lib/workflows/request/default.xml

<component surround="None"><field ref="captcha" /></component>

Reload config, update database etc. and test it works!

Good work EPrints developers - it took about 10 minutes to get it working (and about 30 minutes to write this page :o)!