From d27ff25473285a8f1b2458285b3ca0c95d401fa5 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 11 Jun 2007 23:49:03 +0000 Subject: [PATCH] Improve handling of login/logout some more to improve the chances of us ending up on the right page afterwards. --- app/controllers/application.rb | 2 +- app/controllers/trace_controller.rb | 2 +- app/controllers/user_controller.rb | 8 ++++---- app/views/layouts/site.rhtml | 4 ++-- app/views/trace/list.rhtml | 6 +----- app/views/user/login.rhtml | 1 + config/routes.rb | 2 -- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 328148fe1..df94000be 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base end def require_user - redirect_to :controller => 'user', :action => 'login', :next_controller => controller_name, :next_action => action_name unless @user + redirect_to :controller => 'user', :action => 'login', :referer => request.request_uri unless @user end def authorize(realm='Web Password', errormessage="Couldn't authenticate you") diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 262af0f84..262dd8d2f 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -84,7 +84,7 @@ class TraceController < ApplicationController if @user list(@user, 'mine') unless @user.nil? else - redirect_to :controller => 'user', :action => 'login' + redirect_to :controller => 'user', :action => 'login', :referer => request.request_uri end end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 9a1d89da6..83845af42 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -99,8 +99,8 @@ class UserController < ApplicationController u.timeout = 1.day.from_now u.save session[:token] = u.token - if params[:next_controller] and params[:next_action] - redirect_to :controller => params[:next_controller], :action => params[:next_action] + if params[:referer] + redirect_to params[:referer] else redirect_to :controller => 'site', :action => 'index' end @@ -121,8 +121,8 @@ class UserController < ApplicationController end end session[:token] = nil - if params[:next_controller] and params[:next_action] - redirect_to :controller => params[:next_controller], :action => params[:next_action] + if params[:referer] + redirect_to params[:referer] else redirect_to :controller => 'site', :action => 'index' end diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml index 9290ea892..b34900f7b 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -26,9 +26,9 @@ <% if @user %> Welcome, <%= link_to @user.display_name, {:controller => 'user', :action => 'view', :display_name => @user.display_name}, {:id => 'loginanchor'}%> | - <%= link_to 'logout', {:controller => 'user', :action => 'logout', :next_controller => @controller.controller_name, :next_action => @controller.action_name}, {:id => 'loginanchor'}%> + <%= link_to 'logout', {:controller => 'user', :action => 'logout', :referer => request.request_uri}, {:id => 'loginanchor'}%> <% else %> - <%= link_to 'log in', {:controller => 'user', :action => 'login', :next_controller => @controller.controller_name, :next_action => @controller.action_name}, {:id => 'loginanchor'}%> | + <%= link_to 'log in', {:controller => 'user', :action => 'login', :referer => request.request_uri}, {:id => 'loginanchor'}%> | <%= link_to 'sign up', {:controller => 'user', :action => 'new'}, {:id => 'registeranchor'} %> <% end %> diff --git a/app/views/trace/list.rhtml b/app/views/trace/list.rhtml index d93e32a5b..1bf36cc60 100644 --- a/app/views/trace/list.rhtml +++ b/app/views/trace/list.rhtml @@ -5,11 +5,7 @@

<% end %> | -<% if @user %> - <%= link_to 'See just your traces, or upload a trace', {:controller => 'trace', :action => 'mine'} %> -<% else %> - <%= link_to 'login', {:controller => 'user', :action => 'login', :next_controller => 'traces', :next_action => 'mine'} %> to upload a trace or see yours alone -<% end %> +<%= link_to 'See just your traces, or upload a trace', {:controller => 'trace', :action => 'mine'} %> <% if @tag %> | <%= link_to 'See all traces', {:controller => 'trace', :action => 'list'} %> <% end %> diff --git a/app/views/user/login.rhtml b/app/views/user/login.rhtml index bde0614d5..c8cc49388 100644 --- a/app/views/user/login.rhtml +++ b/app/views/user/login.rhtml @@ -2,6 +2,7 @@ Please login or <%= link_to 'create an account', :controller => 'user', :action => 'new' %>.
<% form_tag :action => 'login' do %> +<%= hidden_field_tag('referer', params[:referer]) %> diff --git a/config/routes.rb b/config/routes.rb index e9de17dcb..f2ccdad0e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,8 +45,6 @@ ActionController::Routing::Routes.draw do |map| map.connect '/user/confirm', :controller => 'user', :action => 'confirm' map.connect '/user/go_public', :controller => 'user', :action => 'go_public' map.connect '/user/reset_password', :controller => 'user', :action => 'reset_password' - map.connect '/user/login/:next_controller/:next_action', :controller => 'user', :action => 'login' - map.connect '/user/logout/:next_controller/:next_action', :controller => 'user', :action => 'logout' map.connect '/index.html', :controller => 'site', :action => 'index' map.connect '/edit.html', :controller => 'site', :action => 'edit' map.connect '/search.html', :controller => 'way_tag', :action => 'search' -- 2.39.5
email address:<%= text_field('user', 'email',{:size => 50, :maxlength => 255}) %>
password:<%= password_field('user', 'password',{:size => 50, :maxlength => 255}) %>