aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/application.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/application.rb')
-rw-r--r--app/controllers/application.rb59
1 files changed, 51 insertions, 8 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index 43dec5e5e..c06e69915 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: application.rb,v 1.7 2007-09-17 06:24:40 francis Exp $
+# $Id: application.rb,v 1.8 2007-10-03 17:13:50 francis Exp $
class ApplicationController < ActionController::Base
@@ -18,16 +18,48 @@ class ApplicationController < ActionController::Base
# Login form
def signin
- if request.post?
- user = User.authenticate(params[:email], params[:password])
- if user
- session[:user] = user.id
- redirect_to :action => session[:intended_action], :controller => session[:intended_controller]
+ if not params[:user]
+ # First time page is shown
+ render :template => 'user_accounts/signin'
+ elsif params[:returning] == "0"
+ # "I am new to FOIFA"
+ session[:email] = params[:user][:email]
+ redirect_to :action => 'signup'
+ elsif params[:returning] == "1"
+ # "I am returning to FOIFA and my password is"
+ @user = User.authenticate(params[:user][:email], params[:user][:password])
+ if @user
+ # Successful login
+ session[:user] = @user.id
+ redirect_to :action => session[:intended_action], :controller => session[:intended_controller], :post_redirect => 1
else
- flash[:error] = "Email or password not correct"
+ # Failed to authenticate
+ flash[:error] = "Email or password not correct, please try again"
end
+ @user = User.new(params[:user])
+ render :template => 'user_accounts/signin'
+ else
+ # Form submitted, but didn't specify whether had already used FOIFA or not
+ flash[:error] = "Please say whether you already have a FOIFA account or not"
+ @user = User.new(params[:user])
+ render :template => 'user_accounts/signin'
+ end
+ end
+
+ # Create new account form
+ def signup
+ # Default to value saved from signin form
+ params[:user] ||= { :email => session[:email] }
+
+ # Make the user and try to save it
+ @user = User.new(params[:user])
+ if not @user.save
+ render :template => 'user_accounts/signup'
+ else
+ # New user made, redirect back to where we were
+ session[:user] = @user.id
+ redirect_to :action => session[:intended_action], :controller => session[:intended_controller], :post_redirect => 1
end
- render :template => 'user_accounts/signin'
end
# Logout form
@@ -43,12 +75,23 @@ class ApplicationController < ActionController::Base
unless session[:user]
session[:intended_action] = action_name
session[:intended_controller] = controller_name
+ session[:intended_params] = params
redirect_to :action => "signin"
return false
end
return true
end
+ # For redirects to POST requests
+ before_filter :post_redirect
+ def post_redirect
+ #raise session[:intended_params].to_yaml
+ if params[:post_redirect]
+# XXX this is the bit where I want to set params for the controller from the session
+# CGI::QueryExtension.params = session[:intended_params]
+ end
+ end
+
# For administration interface, return display name of authenticated user
def admin_http_auth_user
if not request.env["REMOTE_USER"]