From a8d0c217e68fdac0331c0d80df511e5340a67fb7 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 30 Aug 2011 13:29:25 +0100 Subject: Present a reCaptcha on the signup form to foreign visitors (judging from their IP address). Fixes #157 (at least as a starter). --- app/controllers/user_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/controllers/user_controller.rb') 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 -- cgit v1.2.3 From 0420098e50996a033552335e94e35ade781357af Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 30 Aug 2011 13:32:13 +0100 Subject: Additional changes omitted from commit 9d8388c03d0faeaca29d233a340c58bd65f28a97 (distinguish 404s and 500s), fixes #161. --- app/controllers/user_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'app/controllers/user_controller.rb') diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index d3c42c7f1..8e4fb29ef 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -24,7 +24,7 @@ class UserController < ApplicationController @display_user = User.find(:first, :conditions => [ "url_name = ? and email_confirmed = ?", params[:url_name], true ]) if not @display_user - raise "user not found, url_name=" + params[:url_name] + raise ActiveRecord::RecordNotFound.new("user not found, url_name=" + params[:url_name]) end @same_name_users = User.find(:all, :conditions => [ "name ilike ? and email_confirmed = ? and id <> ?", @display_user.name, true, @display_user.id ], :order => "created_at") @@ -133,7 +133,6 @@ class UserController < ApplicationController # New unconfirmed user @user_signup.email_confirmed = false @user_signup.save! - send_confirmation_mail @user_signup return end @@ -454,7 +453,7 @@ class UserController < ApplicationController def get_profile_photo @display_user = User.find(:first, :conditions => [ "url_name = ? and email_confirmed = ?", params[:url_name], true ]) if !@display_user - raise "user not found, url_name=" + params[:url_name] + raise ActiveRecord::RecordNotFound.new("user not found, url_name=" + params[:url_name]) end if !@display_user.profile_photo raise "user has no profile photo, url_name=" + params[:url_name] -- cgit v1.2.3 From a2817f8877a5e37962f81dd96f5ef79ad4a6b0c4 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 30 Aug 2011 15:19:32 +0100 Subject: ensure recaptcha appears on register form, and move to end of form --- app/controllers/user_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/user_controller.rb') diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 914d2d5bb..6916b4456 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -71,7 +71,7 @@ class UserController < ApplicationController # Login form def signin work_out_post_redirect - + @request_from_foreign_country = country_from_ip != MySociety::Config.get('ISO_COUNTRY_CODE', 'GB') # make sure we have cookies if session.instance_variable_get(:@dbman) if not session.instance_variable_get(:@dbman).instance_variable_get(:@original) -- cgit v1.2.3