Skip to content

Commit

Permalink
Merge pull request #289 from SarahBA/master
Browse files Browse the repository at this point in the history
Fixing 'Request Data' form
  • Loading branch information
emanueldima committed Apr 30, 2014
2 parents f52064e + b81725e commit 81bed05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions simplestore/etc/templates/request_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ <h2>Send a Request For Data Owner</h2>
</div>
</li>
<script type="text/javascript"
src="http://api.recaptcha.net/challenge?k=6LefTu0SAAAAAC71iUJWSThHS4uweNKp40tBhLt7">
src="https://www.google.com/recaptcha/api/challenge?k={{ recaptcha_public_key }}">
</script>

<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=6LefTu0SAAAAAC71iUJWSThHS4uweNKp40tBhLt7"
<iframe src="https://www.google.com/recaptcha/api/noscript?k={{ recaptcha_public_key }}"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
Expand Down
43 changes: 22 additions & 21 deletions simplestore/lib/request_data_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from invenio.config import CFG_SITE_SUPPORT_EMAIL
from recaptcha.client import captcha
from invenio.config import CFG_CAPTCHA_PRIVATE_KEY
from invenio.config import CFG_CAPTCHA_PUBLIC_KEY
from validate_email import validate_email
from invenio.config import CFG_SITE_URL
import re
Expand All @@ -43,11 +44,11 @@ def request_data_form(request,recid):
link_txt = ""
else:
link_txt = CFG_SITE_URL + "/record/" + recid
return render_template('request_data.html',full_link=link_txt)
return render_template('request_data.html',full_link=link_txt, recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

def request_data_submit(request):
link = request.form.get('element_9_1','')
#subject = request.form.get('element_1','')
#subject = request.form.get('element_1','')
reason = request.form.get('element_7','')
first_name = request.form.get('element_3_1','')
last_name = request.form.get('element_3_2','')
Expand All @@ -58,46 +59,46 @@ def request_data_submit(request):
recaptcha_challenge = request.form.get('recaptcha_challenge_field','')
recaptcha_response = request.form.get('recaptcha_response_field','')
subject_text = "Request Data"
if(link == '' or len(link)>256):
return render_template('request_data.html',warning_msg="Link is missing")

if(link == '' or len(link)>256):
return render_template('request_data.html',warning_msg="Link is missing", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(reason == ''):
return render_template('request_data.html',warning_msg="Message body is missing")
return render_template('request_data.html',warning_msg="Message body is missing", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(first_name == '' or len(first_name) > 256):
return render_template('request_data.html',warning_msg="First Name is missing")
return render_template('request_data.html',warning_msg="First Name is missing", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(last_name == '' or len(last_name) > 256):
return render_template('request_data.html',warning_msg="Last Name is missing")
return render_template('request_data.html',warning_msg="Last Name is missing", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(affiliation == '' or len(affiliation) > 256):
return render_template('request_data.html',warning_msg="Affiliation is missing")
if(email == '' or validate_email(email,verify=True) == False):
return render_template('request_data.html',warning_msg="Email address missing or format is invalid")
return render_template('request_data.html',warning_msg="Affiliation is missing", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(email == '' or validate_email(email,verify=False) == False):
return render_template('request_data.html',warning_msg="Email address missing or format is invalid", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(country == ''or len(country) > 256):
return render_template('request_data.html',warning_msg="Country is missing")
return render_template('request_data.html',warning_msg="Country is missing", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(phone == '' or check_phone(phone) == False or len(phone) > 30):
return render_template('request_data.html',warning_msg="Phone is missing or invalid format")
return render_template('request_data.html',warning_msg="Phone is missing or invalid format", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(recaptcha_challenge == ''):
return render_template('request_data.html',warning_msg="Recaptcha Challenge is missing")
return render_template('request_data.html',warning_msg="Recaptcha Challenge is missing", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

if(recaptcha_response == ''):
return render_template('request_data.html',warning_msg="Recaptcha Response is missing")
return render_template('request_data.html',warning_msg="Recaptcha Response is missing", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

submit_response = captcha.submit(
recaptcha_challenge,
recaptcha_response,
CFG_CAPTCHA_PRIVATE_KEY,
request.remote_addr
)

if not submit_response.is_valid:
return render_template('request_data.html',warning_msg="Incorrect Captcha response")
return render_template('request_data.html',warning_msg="Incorrect Captcha response", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

else:
msg_content = """
Expand All @@ -118,4 +119,4 @@ def request_data_submit(request):
send_email(email,CFG_SITE_SUPPORT_EMAIL,
subject='Request Data',content=msg_content)

return render_template('request_data.html',warning_msg="Request Data submitted!")
return render_template('request_data.html',warning_msg="Request Data submitted!", recaptcha_public_key=CFG_CAPTCHA_PUBLIC_KEY)

0 comments on commit 81bed05

Please sign in to comment.