SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple app - problems w/ before_filter getting ignored

    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:
    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
    Any ideas how I can make this work?

    Thanks,
    Clem

  2. #2
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, can I ask why you're not using the Restful Authentication plugin? I'm just curious; I'm always curious when someone decides to write code that someone else has already written. I find out all sorts of new things that way.

    As for the question, try adding "return false" after the redirect_to in your before filter, to stop all other activity from that method at that point.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •