Improve handling of login/logout some more to improve the chances of

us ending up on the right page afterwards.
This commit is contained in:
Tom Hughes 2007-06-11 23:49:03 +00:00
parent 0fd11224af
commit d27ff25473
7 changed files with 10 additions and 15 deletions

View file

@ -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")

View file

@ -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

View file

@ -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

View file

@ -26,9 +26,9 @@
<span id="greeting">
<% 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 %>
</span>

View file

@ -5,11 +5,7 @@
<br/><br/>
<% end %>
<span class="rsssmall"><a href="<%= url_for :controller => 'trace', :action => 'georss' %>"><img src="/images/RSS.gif" border="0"></a></span> |
<% 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 %>

View file

@ -2,6 +2,7 @@
Please login or <%= link_to 'create an account', :controller => 'user', :action => 'new' %>.<br>
<% form_tag :action => 'login' do %>
<%= hidden_field_tag('referer', params[:referer]) %>
<table>
<tr><td>email address:</td><td><%= text_field('user', 'email',{:size => 50, :maxlength => 255}) %></td></tr>
<tr><td>password:</td><td><%= password_field('user', 'password',{:size => 50, :maxlength => 255}) %></td></tr>

View file

@ -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'