Hello,
I''m setting up an authentication module that will be called from
application.rb. I want to save a rrequest.request_uri into a
session to be used as a place holder that
will take users back to the page they were on before they logged in.
I''m trying to call the store_location method for all methods EXCEPT
login by putting login in an except before filter.
For some reason, when I login the last request.request_uri address that
is stored in the session is /login. For some reason, the
store_location method is still getting called when the login method is
called and then throws a "Redirect Loop" message in the brower
Here''s the authentication module code:
[code]
module Authentication
def store_location
session[''return-to''] = request.request_uri
end
def login
user = User.find_authenticated_user(params[:username],
params[:password])
unless user.blank? || user.nil?
session[:user] = user
end
redirect_to store_location
end
end
and here''s the code I have so far in application.rb
[/code]
[code]
class ApplicationController < ActionController::Base
before_filter :verify_user, :except => :login
before_filter :store_location, :except => :login
include Authentication
helper :all # include all helpers, all the time
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you''re not using the cookie session store
protect_from_forgery #:secret =>
''f2966dd9b280aee941288062544d2aa9''
def index
end
end
[/code]
Any ideas how I can make this work?
Thanks,
Clem
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
hmmm I''m just guessing here, but have you tried creating a method in your ApplicationController called store_location, which then makes the appropriate module calls? I''m guessing that ApplicationController can''t see the store_location method in your module. On Nov 5, 3:41 pm, Clem Rock <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, > I''m setting up an authentication module that will be called from > application.rb. I want to save a rrequest.request_uri into a > session to be used as a place holder that > will take users back to the page they were on before they logged in. > I''m trying to call the store_location method for all methods EXCEPT > login by putting login in an except before filter. > > For some reason, when I login the last request.request_uri address that > is stored in the session is /login. For some reason, the > store_location method is still getting called when the login method is > called and then throws a "Redirect Loop" message in the brower > > Here''s the authentication module code: > [code] > module Authentication > def store_location > session[''return-to''] = request.request_uri > end > > def login > user = User.find_authenticated_user(params[:username], > params[:password]) > unless user.blank? || user.nil? > session[:user] = user > end > redirect_to store_location > end > end > > and here''s the code I have so far in application.rb > [/code] > > [code] > class ApplicationController < ActionController::Base > > before_filter :verify_user, :except => :login > before_filter :store_location, :except => :login > > include Authentication > > helper :all # include all helpers, all the time > # See ActionController::RequestForgeryProtection for details > # Uncomment the :secret if you''re not using the cookie session store > protect_from_forgery #:secret => ''f2966dd9b280aee941288062544d2aa9'' > > def index > end > end > [/code] > > Any ideas how I can make this work? > > Thanks, > Clem > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
torm3nt wrote:> hmmm > > I''m just guessing here, but have you tried creating a method in your > ApplicationController called store_location, which then makes the > appropriate module calls? > > I''m guessing that ApplicationController can''t see the store_location > method in your module.Thanks for getting back to me. The store location method is clearly getting called each time. I can verify this by putting in logger.debugs in that method and they are showing it''s getting called each time. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5 Nov 2008, at 04:41, Clem Rock wrote:> > For some reason, when I login the last request.request_uri address > that > is stored in the session is /login. For some reason, the > store_location method is still getting called when the login method is > called and then throws a "Redirect Loop" message in the brower > > Here''s the authentication module code: > [code] > module Authentication > def store_location > session[''return-to''] = request.request_uri > end > > def login > user = User.find_authenticated_user(params[:username], > params[:password]) > unless user.blank? || user.nil? > session[:user] = user > end > redirect_to store_location > end > end >store_location is getting called because you''re calling it from the login method :-) You probably meant to do redirect_to session[''return- to''] (possibly checking whether session[''return-to''] is nil and redirecting the user to some where appropriate if that is the case --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---