Subversion Repositories SmartDukaan

Rev

Rev 4401 | Rev 4815 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4401 Rev 4609
Line 30... Line 30...
30
import org.apache.struts2.convention.annotation.InterceptorRefs;
30
import org.apache.struts2.convention.annotation.InterceptorRefs;
31
import org.apache.struts2.convention.annotation.Result;
31
import org.apache.struts2.convention.annotation.Result;
32
import org.apache.struts2.convention.annotation.Results;
32
import org.apache.struts2.convention.annotation.Results;
33
import org.apache.thrift.TException;
33
import org.apache.thrift.TException;
34
import org.apache.thrift.transport.TTransportException;
34
import org.apache.thrift.transport.TTransportException;
-
 
35
import nl.captcha.Captcha;
35
 
36
 
36
@SuppressWarnings("serial")
37
@SuppressWarnings("serial")
37
@InterceptorRefs({
38
@InterceptorRefs({
38
    @InterceptorRef("myDefault"),
39
    @InterceptorRef("myDefault"),
39
    @InterceptorRef("login")
40
    @InterceptorRef("login")
Line 200... Line 201...
200
     * Verifies if the recaptcha response matches the recaptcha challenge.
201
     * Verifies if the recaptcha response matches the recaptcha challenge.
201
     * 
202
     * 
202
     * @return True if the captcha was valid, false otherwise.
203
     * @return True if the captcha was valid, false otherwise.
203
     */
204
     */
204
    private boolean verifyCaptcha() {
205
    private boolean verifyCaptcha() {
205
        String remoteAddr = request.getRemoteAddr();
206
        String cookieCaptchaAnswer = getCookie(Captcha.NAME, true, "saholic");
206
        ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
207
    	String captchaReceived = (String) request.getParameter("captcha_response_field");
-
 
208
    	
207
        reCaptcha.setPrivateKey(RECAPTCHA_PRIVATE_KEY);
209
    	if (captchaReceived.equalsIgnoreCase(cookieCaptchaAnswer)) {
208
 
210
			try {
209
        String challenge = request.getParameter("recaptcha_challenge_field");
211
				DataLogger.logData(EventType.CAPTCHA_SUCCESS, getSessionId(), userinfo.getUserId(), userinfo.getEmail());
210
        String uresponse = request.getParameter("recaptcha_response_field");
212
			} catch (Exception e1) {
211
        ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);
213
	        	log.warn("Unable to log orders through the datalogger", e1);
-
 
214
	        }
-
 
215
			return true;
212
 
216
		} 
-
 
217
		else {
-
 
218
			try {
-
 
219
				DataLogger.logData(EventType.CAPTCHA_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail());
-
 
220
			} catch (Exception e1) {
213
        log.info("Recaptcha Response:" + reCaptchaResponse.isValid());
221
	        	log.warn("Unable to log orders through the datalogger", e1);
-
 
222
	        }
214
        return reCaptchaResponse.isValid();
223
			return false;
-
 
224
		}
215
    }
225
    }
216
    
226
    
217
	public String getId(){
227
	public String getId(){
218
		return id;
228
		return id;
219
	}
229
	}