diff options
-rw-r--r-- | app/controllers/user_controller.rb | 36 | ||||
-rw-r--r-- | app/views/user/_signin.rhtml | 12 | ||||
-rw-r--r-- | app/views/user/_signup.rhtml | 20 | ||||
-rw-r--r-- | app/views/user/sign.rhtml | 5 | ||||
-rw-r--r-- | app/views/user/signin.rhtml | 7 | ||||
-rw-r--r-- | app/views/user/signup.rhtml | 7 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 20 | ||||
-rw-r--r-- | todo.txt | 5 |
8 files changed, 43 insertions, 69 deletions
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 7f076bfb2..b83d85d18 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user_controller.rb,v 1.20 2007-12-14 13:42:28 francis Exp $ +# $Id: user_controller.rb,v 1.21 2007-12-14 18:46:08 francis Exp $ class UserController < ApplicationController # XXX See controllers/application.rb simplify_url_part for reverse of expression in SQL below @@ -20,23 +20,23 @@ class UserController < ApplicationController def signin work_out_post_redirect - if not params[:user] + if not params[:user_signin] # First time page is shown render :action => 'sign' return else - @user = User.authenticate_from_form(params[:user]) - if @user.errors.size > 0 + @user_signin = User.authenticate_from_form(params[:user_signin]) + if @user_signin.errors.size > 0 # Failed to authenticate - render :action => 'signin' + render :action => 'sign' return else # Successful login - if @user.email_confirmed - session[:user_id] = @user.id + if @user_signin.email_confirmed + session[:user_id] = @user_signin.id do_post_redirect @post_redirect.uri, @post_redirect.post_params else - send_confirmation_mail + send_confirmation_mail @user_signin end return end @@ -48,16 +48,16 @@ class UserController < ApplicationController work_out_post_redirect # Make the user and try to save it - @user = User.new(params[:user]) - if not @user.valid? + @user_signup = User.new(params[:user_signup]) + if not @user_signup.valid? # Show the form - render :action => 'signup' + render :action => 'sign' else # New unconfirmed user - @user.email_confirmed = false - @user.save + @user_signup.email_confirmed = false + @user_signup.save - send_confirmation_mail + send_confirmation_mail @user_signup return end end @@ -116,15 +116,15 @@ class UserController < ApplicationController end # Ask for email confirmation - def send_confirmation_mail - raise "user #{@user.id} already confirmed" if @user.email_confirmed + def send_confirmation_mail(user) + raise "user #{user.id} already confirmed" if user.email_confirmed post_redirect = PostRedirect.find_by_token(params[:token]) - post_redirect.user = @user + post_redirect.user = user post_redirect.save! url = confirm_url(:email_token => post_redirect.email_token) - UserMailer.deliver_confirm_login(@user, post_redirect.reason_params, url) + UserMailer.deliver_confirm_login(user, post_redirect.reason_params, url) render :action => 'confirm' end diff --git a/app/views/user/_signin.rhtml b/app/views/user/_signin.rhtml index 846fbcd8d..5dc9b5384 100644 --- a/app/views/user/_signin.rhtml +++ b/app/views/user/_signin.rhtml @@ -1,20 +1,18 @@ <div id="signin"> <% form_tag({:action => "signin"}, {:id => "signin_form"}) do %> - <%= foi_error_messages_for :user %> + <%= foi_error_messages_for :user_signin %> - <% if not flash[:error] and not @post_redirect.reason_params[:user_name] %> <h2>If you've used GovernmentSpy before</h2> - <% end %> <p> - <label class="form_label" for="signin_email"><strong>Your e-mail:</strong></label> - <%= text_field 'user', 'email', { :size => 20, :id => 'signin_email' } %> + <label class="form_label" for="user_signin_email"><strong>Your e-mail:</strong></label> + <%= text_field 'user_signin', 'email', { :size => 20 } %> </p> <p> - <label class="form_label" for="signin_password"><strong>Password:</strong></label> - <%= password_field 'user', 'password', { :size => 15, :id => 'signin_password' } %> + <label class="form_label" for="user_signin_password"><strong>Password:</strong></label> + <%= password_field 'user_signin', 'password', { :size => 15 } %> </p> <p class="form_note"> diff --git a/app/views/user/_signup.rhtml b/app/views/user/_signup.rhtml index fd2f454f6..ae204bc1d 100644 --- a/app/views/user/_signup.rhtml +++ b/app/views/user/_signup.rhtml @@ -1,23 +1,21 @@ <div id="signup"> <% form_tag({:action => "signup"}, {:id => "signup_form"}) do %> - <%= foi_error_messages_for :user %> + <%= foi_error_messages_for :user_signup %> - <% if not flash[:error] %> <h2>If you're new to GovernmentSpy</h2> - <% end %> <p> - <label class="form_label" for="signup_email"><strong>Your e-mail:</strong></label> - <%= text_field 'user', 'email', { :size => 20, :id => 'signup_email' } %> + <label class="form_label" for="user_signup_email"><strong>Your e-mail:</strong></label> + <%= text_field 'user_signup', 'email', { :size => 20 } %> </p> <div class="form_item_note"> We will not reveal your email address to anybody. </div> <p> - <label class="form_label" for="signup_name"><strong>Your name:</strong></label> - <%= text_field 'user', 'name', { :size => 20, :id => 'signup_name' } %> + <label class="form_label" for="user_signup_name"><strong>Your name:</strong></label> + <%= text_field 'user_signup', 'name', { :size => 20 } %> </p> <div class="form_item_note">Your <strong>name will appear publically</strong> on this website and in search engines. We encourage you @@ -25,13 +23,13 @@ anonymous.</div> <p> - <label class="form_label" for="signup_password"><strong>Password:</strong></label> - <%= password_field 'user', 'password', { :size => 15, :id => 'signup_password' } %> + <label class="form_label" for="user_signup_password"><strong>Password:</strong></label> + <%= password_field 'user_signup', 'password', { :size => 15 } %> </p> <p> - <label class="form_label" for="signup_password_confirmation"><strong>Password: (again)</strong></label> - <%= password_field 'user', 'password_confirmation', { :size => 15, :id => 'signup_password_confirmation' } %> + <label class="form_label" for="user_signup_password_confirmation"><strong>Password: (again)</strong></label> + <%= password_field 'user_signup', 'password_confirmation', { :size => 15 } %> </p> <div class="form_button"> diff --git a/app/views/user/sign.rhtml b/app/views/user/sign.rhtml index 32d1bd5f5..7a1e26205 100644 --- a/app/views/user/sign.rhtml +++ b/app/views/user/sign.rhtml @@ -36,8 +36,3 @@ <% end %> -<% if @post_redirect.reason_params[:user_name] %> -<% else %> -<% end %> - - diff --git a/app/views/user/signin.rhtml b/app/views/user/signin.rhtml deleted file mode 100644 index 67cd958a0..000000000 --- a/app/views/user/signin.rhtml +++ /dev/null @@ -1,7 +0,0 @@ -<% @title = "Sign in" %> - -<div id="sign_alone"> - -<%= render :partial => 'signin' %> - -</div> diff --git a/app/views/user/signup.rhtml b/app/views/user/signup.rhtml deleted file mode 100644 index a83e05565..000000000 --- a/app/views/user/signup.rhtml +++ /dev/null @@ -1,7 +0,0 @@ -<% @title = "Make a new account" %> - -<div id="sign_alone"> - -<%= render :partial => 'signup' %> - -</div> diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 76d93a193..2fa44eb24 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -64,17 +64,17 @@ describe UserController, "when signing in" do get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect - post :signin, { :user => { :email => 'bob@localhost', :password => 'NOTRIGHTPASSWORD' }, + post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'NOTRIGHTPASSWORD' }, :token => post_redirect.token } - response.should render_template('signin') + response.should render_template('sign') end it "should log in when you give right email/password, and redirect to where you were" do get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect - post :signin, { :user => { :email => 'bob@localhost', :password => 'jonespassword' }, + post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' }, :token => post_redirect.token } session[:user_id].should == users(:bob_smith_user).id @@ -86,7 +86,7 @@ describe UserController, "when signing in" do get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect - post :signin, { :user => { :email => 'silly@localhost', :password => 'jonespassword' }, + post :signin, { :user_signin => { :email => 'silly@localhost', :password => 'jonespassword' }, :token => post_redirect.token } response.should render_template('confirm') @@ -97,7 +97,7 @@ describe UserController, "when signing in" do get :signin, :r => "/list" post_redirect = get_last_postredirect - post :signin, { :user => { :email => 'silly@localhost', :password => 'jonespassword' }, + post :signin, { :user_signin => { :email => 'silly@localhost', :password => 'jonespassword' }, :token => post_redirect.token } response.should send_email @@ -120,21 +120,21 @@ describe UserController, "when signing up" do fixtures :users it "should be an error if you type the password differently each time" do - post :signup, { :user => { :email => 'new@localhost', :name => 'New Person', + post :signup, { :user_signup => { :email => 'new@localhost', :name => 'New Person', :password => 'sillypassword', :password_confirmation => 'sillypasswordtwo' } } - assigns[:user].errors[:password].should_not be_nil + assigns[:user_signup].errors[:password].should_not be_nil end it "should be an error to sign up with an email that has already been used" do - post :signup, { :user => { :email => 'bob@localhost', :name => 'Second Bob', + post :signup, { :user_signup => { :email => 'bob@localhost', :name => 'Second Bob', :password => 'sillypassword', :password_confirmation => 'sillypassword' } } - assigns[:user].errors[:email].should_not be_nil + assigns[:user_signup].errors[:email].should_not be_nil end it "should ask you to confirm your email if you fill in the form right" do - post :signup, { :user => { :email => 'new@localhost', :name => 'New Person', + post :signup, { :user_signup => { :email => 'new@localhost', :name => 'New Person', :password => 'sillypassword', :password_confirmation => 'sillypassword' } } response.should render_template('confirm') @@ -7,10 +7,7 @@ Next Either rotate log files, or merge with Apache ones -Rename classify to /request/single_response or something? - -Send email to requestor telling them new information has come in -Let them send follow-ups +Let requester send follow-ups Do something after 20 working days if you get no response Forgotten password link |