Sent to Andriy but thought it might be helpful to others too.
Begin forwarded message: Date: November 16, 2009 10:46:52 AM CST Subject: Re: [Dspace-tech] (no subject)
Hi Andriy,
Here are the code you need update/add for captcha implementation-
1. in dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/eperson/StartRegistration.java
Add the following variable definitions along with others in StartRegistration.java ---------------------------------- private static final Message T_captcha_label = message("xmlui.EPerson.Captcha.label");
private static final Message T_captcha_helptext = message("xmlui.EPerson.Captcha.helptext");
private static final Message T_captcha_error = message("xmlui.EPerson.WrongCaptcha.para1");
/** The captcha characters */ private String captchaString; ----------------------------------
***************************************************************************************************************************
In method public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException{
find the line - this.accountExists = parameters.getParameterAsBoolean("accountExists",false);
add the lines below after it -
---------------------------- this.captchaString = parameters.getParameter("captcha", "captcha"); System.out.println("Captcha String: " + captchaString); ----------------------------
***************************************************************************************************************************
In method public void addBody(Body body) throws WingException {
find the lines - if (errors.contains("email")) email.addError(T_error_bad_email);
add the lines below after it -
---------------------------- Text captcha = form.addItem().addText("captcha"); captcha.setRequired(); captcha.setLabel(T_captcha_label); captcha.setHelp(T_captcha_helptext); captcha.setValue(); if (errors.contains("captcha")) captcha.addError(T_captcha_error);
// add the image Figure figure = form.addItem().addFigure(contextPath + "/captchaa?source=" + captchaString, null, null); ----------------------------
2. in dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/EPerson/eperson.js add this function at the end of eperson.js ---------------------------------- function getText(length) { var allChar = "a b c n w x d e f p u v 2 3 g h 4 5 i j k 6 7 q r s t 8 9 m z y"; var allCharArray = allChar.split(" "); var randomContext = allCharArray.length - 1; var text = ""; for (var i = 0; i < length; i++) { var rand = Math.floor(Math.random()*randomContext); text += allCharArray[rand]; }
return text; } ----------------------------------
***************************************************************************************************************************
In function doRegister(), you can find
var email = cocoon.request.getParameter("email");
add the lines below after it -
----------------------------------------- var captcha = getText(7); cocoon.sendPageAndWait("register/start",{"email" : email, "errors" : errors.join(','), "accountExists" : accountExists, "captcha" : captcha}); -----------------------------------------
***************************************************************************************************************************
Again, in this function, find the lines -
----------------------------------------- if (canRegister) { try { // May throw the AddressException or a varity of SMTP errors. AccountManager.sendRegistrationInfo(getDSContext(),email); } catch (error) { // If any errors occure while trying to send the email set the field in error. errors = new Array("email"); continue; } -----------------------------------------
Add the lines below after it -
----------------------------------------- var inputCaptcha = cocoon.request.getParameter("captcha"); if(inputCaptcha == null || inputCaptcha != captcha){ errors = new Array("captcha"); continue; } -----------------------------------------
3. in dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/sitemap.xmap add this line to <map:readers default="resource"> section -
<map:reader name="Captcha" src=""/>
add following lines to <!-- non-bitstream pipeline --> <map:pipeline> section --------------------------------- <map:match pattern="captchaa"> <map:read type="Captcha" src=""> <map:parameter name="width" value="100" /> <map:parameter name="height" value="50" /> <map:parameter name="foreground" value="black" /> <map:parameter name="background" value="grey" /> <map:parameter name="font" value="serif" /> <map:parameter name="scale" value="6" /> <map:parameter name="amount" value="1" /> <map:parameter name="quality" value="0.75" /> </map:read> </map:match> ---------------------------------
4. in dspace-xmlui/dspace-xmlui-webapp/src/main/resources/aspects/EPerson/sitemap.xmap add the following line to the <map:match pattern="register/start"> section
<map:parameter name="captcha" value="{flow-attribute:captcha}"/>
5. add attached file CaptchaReader.java to directory dspace-xmlui/dspace-xmlui-webapp/src/main/java/org/dspace/app/xmlui/cocoon, adopted from cocoon 2.2 captcha block. Made a little update.
|
CaptchaReader.java
Description: Binary data
6. in dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/i18n/messages.xml add the following messages to the messages.xml. ----------------------------------------- <message key="xmlui.EPerson.WrongCaptcha.para1">Your anti-spam string was incorrect. Please try again.</message> <message key="xmlui.EPerson.Captcha.label">An anti-spam measure</message> <message key="xmlui.EPerson.Captcha.helptext">Please enter the string that appears in the image below.</message> ----------------------------------------- Since it was implemented on DSpace 1.5.0, you may need to update it for 1.5.2. Please let me know if you have any problems to integrate it. Best, Ying On Nov 14, 2009, at 1:36 AM, [email protected] wrote: Thanks for answer. I am using XMLUI and JSPUI. The main interface is JSPUI but XMLUI i am using additionally. I have found those links
http://d.hatena.ne.jp/zuki_ebetsu/20071209 and
http://blog.lib.umn.edu/silvi003/codenotes/2009/09/putting_captchas_into_dspace_u.html
but there are mistakes in source code.
I will be VERY VERY thankful if you can help me in any way.
Hi Andriy,
What UI interface you are using? XMLUI or JSPUI? A year ago, I implemented one using captcha code from cocoon on Dspace 1.5.0 XMLUI interface.
If you are using XMLUI and feel comfortable to change DSpace code a bit, I can find out the code for you.
Best,
Ying
On Nov 13, 2009, at 11:52 AM, [email protected] wrote:
Hello, my name is Andriy and i am from Lviv Polytechnik National
University ( Ukraine). I
have the next question:
How can i integrate jcaptcha in dspace 1.5.2 . It's very important for
me. In internet i
can't find any usefull information about it. Can anyone propose easy
steps o integrate jcaptcha( or simpleCaptcha or other captcha) in
dspace.
Thanks all
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech
|
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech