Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reCaptcha support #2

Merged
merged 6 commits into from
Jun 4, 2020
Merged

Conversation

ccamel
Copy link
Contributor

@ccamel ccamel commented Jun 2, 2020

This PR adds reCaptcha support as an additional security layer against unwanted / spam form submission.

This is a fairly straighforward implementation which verifies the challenge code in the g-recaptcha-response POST parameter, if available.

Feel free to make any comment on this one. 😌

image

ccamel added 6 commits June 1, 2020 19:55
use `http.Handler` wrappers to split the sendmail handler into 2
distinct handlers: one for validating the query (currently, checking the allowed
domains) and the other one for the sendmail functionality.
@rchakode rchakode self-requested a review June 2, 2020 21:34
@rchakode rchakode self-assigned this Jun 2, 2020
@rchakode
Copy link
Owner

rchakode commented Jun 2, 2020

yo,
Well done, this is a great improvment on security to prevent spams/scam mails.
Let me test this on my side before merging it.

Copy link
Owner

@rchakode rchakode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @ccamel ,
I gave a try to the PR, it works very well. 👍
I would suggest the following changes:

  • remove the template file samples/hugo-partial-sample-form-recaptcha.html, and,
  • include the content to the default template as HTML comments, as below
    I think that make it easy to integrate
<div id="reply-message"></div>
<div>
   <fieldset>
      <legend>Please fill in the form to submit your request</legend>
      <form action="https://contact-request-endpoint/" method="post">
         <!-- uncomment this div block when enabling reCaptcha
         <script src="https://www.google.com/recaptcha/api.js"></script>
         -->         
         <div class="form-item">
            <label for="name">Name</label>
            <input type="text" name="name" id="name"  placeholder="Mr. Smith" />
         </div>
         <div class="form-item">
            <label for="email">Email <span class="req"></span></label>
            <input type="text" name="email" id="email"  class="required email" placeholder="[email protected]" />
         </div>
         <div class="form-item">
            <label for="organization">Organization</label>
            <input type="text" name="organization" id="organization"  placeholder="Company, Inc." />
         </div>
         {{ if in .Params.tags "contact" }}  
         <div class="form-item">
            <label for="subject">Subject</label>
            <input type="text" name="subject" id="subject"  value="" placeholder="Need help or expertise?" />
            <input type="hidden" name="target" id="target"  value="contact" />
         </div>
         <div class="form-item">
            <label for="message">Message</label>
            <textarea  rows="6" name="message" id="message"  placeholder="Please add details concerning your request."></textarea>
         </div>
         {{ else }}    
         <div class="form-item">
            <input type="hidden" name="subject" id="subject"  value="Your Access to Product Demo!" />
            <input type="hidden" name="target" id="target"  value="demo" />
         </div>
         {{ end }}
         <!-- uncomment the below div when enabling reCaptcha
         <div class="g-recaptcha" data-sitekey="{{.Site.Params.reCaptchaPrivateKey}}"></div>
         -->
         <input  class="button"  type="submit" value="Submit">
      </form>
   </fieldset>
</div>

@ccamel ccamel force-pushed the add-recaptcha-support branch 2 times, most recently from 07ff0c5 to 17082f3 Compare June 4, 2020 11:25
@ccamel ccamel requested a review from rchakode June 4, 2020 11:26
@ccamel
Copy link
Contributor Author

ccamel commented Jun 4, 2020

@rchakode I agree! I've made the change in that way. 😌
Thanks.

@rchakode rchakode merged commit cb46b06 into rchakode:master Jun 4, 2020
@ccamel ccamel deleted the add-recaptcha-support branch June 16, 2020 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants