aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb11
-rw-r--r--app/controllers/user_controller.rb9
-rw-r--r--app/views/user/_signup.rhtml7
3 files changed, 23 insertions, 4 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index cb64cb922..cae3cb213 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -447,6 +447,17 @@ class ApplicationController < ActionController::Base
return query
end
+ def country_from_ip
+ gaze = MySociety::Config.get('GAZE_URL', '')
+ default = MySociety::Config.get('ISO_COUNTRY_CODE', '')
+ country = ""
+ if !gaze.empty?
+ country = open("#{gaze}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}").read.strip
+ end
+ country = default if country.empty?
+ return country
+ end
+
# URL generating functions are needed by all controllers (for redirects),
# views (for links) and mailers (for use in emails), so include them into
# all of all.
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index d3c42c7f1..cd46b6ea4 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -118,10 +118,15 @@ class UserController < ApplicationController
# Create new account form
def signup
work_out_post_redirect
-
+ @request_from_foreign_country = country_from_ip != MySociety::Config.get('ISO_COUNTRY_CODE', 'GB')
# Make the user and try to save it
@user_signup = User.new(params[:user_signup])
- if !@user_signup.valid?
+ error = false
+ if @request_from_foreign_country && !verify_recaptcha
+ flash.now[:error] = _("There was an error with the words you entered, please try again.")
+ error = true
+ end
+ if error || !@user_signup.valid?
# Show the form
render :action => 'sign'
else
diff --git a/app/views/user/_signup.rhtml b/app/views/user/_signup.rhtml
index 6b0a1f8c7..1f586b5e9 100644
--- a/app/views/user/_signup.rhtml
+++ b/app/views/user/_signup.rhtml
@@ -2,6 +2,9 @@
<% form_tag({:action => "signup"}, {:id => "signup_form"}) do %>
<%= foi_error_messages_for :user_signup %>
+ <% if @request_from_foreign_country %>
+ <%= recaptcha_tags %>
+ <% end %>
<h2><%= _('If you\'re new to {{site_name}}', :site_name=>site_name)%></h2>
@@ -10,8 +13,8 @@
<%= text_field 'user_signup', 'email', { :size => 20 } %>
</p>
<div class="form_item_note">
- <%= ('We will not reveal your email address to anybody unless you or
- the law tell us to (<a href="%s">_details</a>). ') %[help_privacy_path] %>
+ <%= _('We will not reveal your email address to anybody unless you or
+ the law tell us to (<a href="%s">details</a>). ') %[help_privacy_path] %>
</div>
<p>