From 53357bf4998aa6087ca3d4f144de83701022a2a1 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Tue, 2 Aug 2011 14:50:57 +0200 Subject: New Request wireframe: implemente modal sign-in process --- app/controllers/user_controller.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'app/controllers/user_controller.rb') diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index d3c42c7f1..7b99be393 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -72,6 +72,10 @@ class UserController < ApplicationController def signin work_out_post_redirect + # when logging in through a modal iframe, don't display chrome around the content + @is_modal_dialog = (params[:modal].to_i != 0) + layout = @is_modal_dialog ? 'no_chrome' : 'default' + # make sure we have cookies if session.instance_variable_get(:@dbman) if not session.instance_variable_get(:@dbman).instance_variable_get(:@original) @@ -80,7 +84,7 @@ class UserController < ApplicationController redirect_to signin_url(:r => params[:r], :again => 1) return end - render :action => 'no_cookies' + render :action => 'no_cookies', :layout => layout return end end @@ -92,13 +96,13 @@ class UserController < ApplicationController if not params[:user_signin] # First time page is shown - render :action => 'sign' + render :action => 'sign', :layout => layout return else @user_signin = User.authenticate_from_form(params[:user_signin], @post_redirect.reason_params[:user_name] ? true : false) if @user_signin.errors.size > 0 # Failed to authenticate - render :action => 'sign' + render :action => 'sign', :layout => layout return else # Successful login @@ -106,7 +110,12 @@ class UserController < ApplicationController session[:user_id] = @user_signin.id session[:user_circumstance] = nil session[:remember_me] = params[:remember_me] ? true : false - do_post_redirect @post_redirect + + if @is_modal_dialog + render :action => 'signin_successful', :layout => layout + else + do_post_redirect @post_redirect + end else send_confirmation_mail @user_signin end @@ -119,11 +128,15 @@ class UserController < ApplicationController def signup work_out_post_redirect + # when logging in through a modal iframe, don't display chrome around the content + @is_modal_dialog = (params[:modal].to_i != 0) + layout = @is_modal_dialog ? 'no_chrome' : 'default' + # Make the user and try to save it @user_signup = User.new(params[:user_signup]) if !@user_signup.valid? # Show the form - render :action => 'sign' + render :action => 'sign', :layout => layout else user_alreadyexists = User.find_user_by_email(params[:user_signup][:email]) if user_alreadyexists -- cgit v1.2.3 From 07933c860cea05df05acde5b5e321e2d78911f60 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 10 Aug 2011 01:14:51 +0200 Subject: Select layout for User controller (modal/non-modal) using Rails baked-in mechanism, much cleaner and robust --- app/controllers/user_controller.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'app/controllers/user_controller.rb') diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 7b99be393..3dcdf973b 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -8,6 +8,8 @@ class UserController < ApplicationController + layout :select_layout + protect_from_forgery :only => [ :contact, :set_profile_photo, :signchangeemail, @@ -72,10 +74,6 @@ class UserController < ApplicationController def signin work_out_post_redirect - # when logging in through a modal iframe, don't display chrome around the content - @is_modal_dialog = (params[:modal].to_i != 0) - layout = @is_modal_dialog ? 'no_chrome' : 'default' - # make sure we have cookies if session.instance_variable_get(:@dbman) if not session.instance_variable_get(:@dbman).instance_variable_get(:@original) @@ -84,7 +82,7 @@ class UserController < ApplicationController redirect_to signin_url(:r => params[:r], :again => 1) return end - render :action => 'no_cookies', :layout => layout + render :action => 'no_cookies' return end end @@ -96,13 +94,13 @@ class UserController < ApplicationController if not params[:user_signin] # First time page is shown - render :action => 'sign', :layout => layout + render :action => 'sign' return else @user_signin = User.authenticate_from_form(params[:user_signin], @post_redirect.reason_params[:user_name] ? true : false) if @user_signin.errors.size > 0 # Failed to authenticate - render :action => 'sign', :layout => layout + render :action => 'sign' return else # Successful login @@ -112,7 +110,7 @@ class UserController < ApplicationController session[:remember_me] = params[:remember_me] ? true : false if @is_modal_dialog - render :action => 'signin_successful', :layout => layout + render :action => 'signin_successful' else do_post_redirect @post_redirect end @@ -128,15 +126,11 @@ class UserController < ApplicationController def signup work_out_post_redirect - # when logging in through a modal iframe, don't display chrome around the content - @is_modal_dialog = (params[:modal].to_i != 0) - layout = @is_modal_dialog ? 'no_chrome' : 'default' - # Make the user and try to save it @user_signup = User.new(params[:user_signup]) if !@user_signup.valid? # Show the form - render :action => 'sign', :layout => layout + render :action => 'sign' else user_alreadyexists = User.find_user_by_email(params[:user_signup][:email]) if user_alreadyexists @@ -513,6 +507,12 @@ class UserController < ApplicationController private + # when logging in through a modal iframe, don't display chrome around the content + def select_layout + @is_modal_dialog = (params[:modal].to_i != 0) + @is_modal_dialog ? 'no_chrome' : 'default' + end + # Decide where we are going to redirect back to after signin/signup, and record that def work_out_post_redirect # Redirect to front page later if nothing else specified -- cgit v1.2.3 From a63e598b9e0ddfa7ac695b1be41aaace6c0eb628 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Thu, 11 Aug 2011 03:50:10 +0200 Subject: Move log-in point to before Preview and fix modal sign-in and sign-up redirects --- app/controllers/user_controller.rb | 9 ++++++--- 1 file changed, 6 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 3dcdf973b..3e3913fae 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -109,7 +109,7 @@ class UserController < ApplicationController session[:user_circumstance] = nil session[:remember_me] = params[:remember_me] ? true : false - if @is_modal_dialog + if is_modal_dialog render :action => 'signin_successful' else do_post_redirect @post_redirect @@ -507,10 +507,13 @@ class UserController < ApplicationController private + def is_modal_dialog + (params[:modal].to_i != 0) + end + # when logging in through a modal iframe, don't display chrome around the content def select_layout - @is_modal_dialog = (params[:modal].to_i != 0) - @is_modal_dialog ? 'no_chrome' : 'default' + is_modal_dialog ? 'no_chrome' : 'default' end # Decide where we are going to redirect back to after signin/signup, and record that -- cgit v1.2.3 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 From 547394f4aa7d48b42b14a4b08c98e3c60a33db46 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 1 Sep 2011 18:15:57 +0100 Subject: Provide a search function on the user profile pages. Closes #138. --- app/controllers/user_controller.rb | 13 ++++++++++--- 1 file changed, 10 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 6916b4456..47a133135 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -33,9 +33,16 @@ class UserController < ApplicationController # Use search query for this so can collapse and paginate easily # XXX really should just use SQL query here rather than Xapian. begin - @xapian_requests = perform_search([InfoRequestEvent], 'requested_by:' + @display_user.url_name, 'newest', 'request_collapse') - @xapian_comments = perform_search([InfoRequestEvent], 'commented_by:' + @display_user.url_name, 'newest', nil) - + requests_query = 'requested_by:' + @display_user.url_name + comments_query = 'commented_by:' + @display_user.url_name + if !params[:user_query].nil? + requests_query += " " + params[:user_query] + comments_query += " " + params[:user_query] + @match_phrase = _("{{search_results}} matching '{{query}}'", :search_results => "", :query => params[:user_query]) + end + @xapian_requests = perform_search([InfoRequestEvent], requests_query, 'newest', 'request_collapse') + @xapian_comments = perform_search([InfoRequestEvent], comments_query, 'newest', nil) + if (@page > 1) @page_desc = " (page " + @page.to_s + ")" else -- cgit v1.2.3