SAP Hybris suite , Hybris tutorial, Java, J2ee Stuff Online-

0
How to Add Captcha to Hybris customer Register page | Captcha in Hybris

Open 2 Answers 17158 Views

In My Hybris Project I have to implement Captcha on my Register page as well as in login page. So i have implemented ReCaptch with Steps below

1. Get API Key from  https://www.google.com/recaptcha/admin#createsite. 

2. Download the latest jar from: https://code.google.com/p/recaptcha/downloads/list?q=label:java-Latest.

3. Now create captcha.tag . Now paste code on register page.

<script type="text/javascript"
     src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
  </script>
  <noscript>
     <iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
         height="300" width="500" frameborder="0"></iframe><br>
     <textarea name="recaptcha_challenge_field" rows="3" cols="40">
     </textarea>
     <input type="hidden" name="recaptcha_response_field"
         value="manual_challenge">
  </noscript>

  <!-- ... your HTML content ... -->
  <form action="" method="post">
    <!-- ... your form code here ... -->
    <script type="text/javascript"
       src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
    </script>
    <noscript>
       <iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
           height="300" width="500" frameborder="0"></iframe><br>
       <textarea name="recaptcha_challenge_field" rows="3" cols="40">
       </textarea>
       <input type="hidden" name="recaptcha_response_field"
           value="manual_challenge">
    </noscript>
    <!-- ... more of your form code here ... -->
  </form>
  <!-- ... more of your HTML content ... -->
  
 

 4. Now verify catcha in server side by using code below
  
    A. create util class for captcha as below
 

@Component
@Scope("tenant")
public class CaptchaUtil
{
    public boolean verifyCaptcha(final HttpServletRequest request, final String challenge, final String input,
            final String privateKey)
    {
        final String remoteAddr = request.getRemoteAddr();
        final ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
        reCaptcha.setPrivateKey(privateKey);
        final ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, input);
        return reCaptchaResponse.isValid();
    }
}

   B. Now call in controller 
   

 @RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(@Valid final RegisterForm form, final BindingResult bindingResult, final Model model,
        final HttpServletRequest request, final HttpServletResponse response) throws CMSItemNotFoundException
{
    boolean verifyCaptcha;
    try
    {
        verifyCaptcha = captchaUtil.verifyCaptcha(request, request.getParameter("recaptcha_challenge_field"),
                request.getParameter("recaptcha_response_field"), getCaptchaSecretKey());
    }
    catch (final Exception e)
    {
        LOG.error("Failed to verify captcha", e);
        verifyCaptcha = false;
    }
    if (!verifyCaptcha)
    {
        model.addAttribute("wrongCaptcha", "true");
        storeCmsPageInModel(model, getLoginCmsPage());
        return getLoginView();
    }
}

2 Answers

0

As per functional part and tester knowledge configuring captcha in registration page is as below,

1. Open HMC and navigate to Base Commerce option.
2. Click on Base Store option.
3. Click on search button.
4. Select preferred store.
5. Select Properties tab.
6. uncheck the Captcha Widget Enabled option displayed at the end of the page.

answered Apr 21, 2016 by Satish DM
0
Новый Автоломбард на Коломенской предлагает займы практически под любые суммы,
вы получите деньги всего за 30 минут: приезжайте, и получайте!
 
Нужны средства на достойное проведение отпуска? Не проблема!
Всё, что для этого нужно - это Ваш паспорт, ПТС, и свидетельство о регистрации.
 
Выдаём суммы до трёх с половиной миллионов рублей.
Никаких бюрократических сложностей и лишних вопросов.
Мы выдаем деньги под залог автомобиля, мотоцикла, квадроцикла и других транспортных средств.
 
Заинтересованы?
Добро пожаловать!
http://andropova22lombard.ru
answered Aug 24 by JamesTap

...