Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

impossible to access cookie in custom failure app #1682

Closed
JohnMerlino1 opened this Issue · 3 comments

2 participants

LatvianDancers José Valim
LatvianDancers

I'm trying to access a cookie in custom failure app, because when the user enters the wrong password, I want to delete a cookie called tracker_for_external_clients. However, when you add a class in lib directory, there's no way to access the cookie hash. So I tried adding a class method to CustomFailureApp:

class CustomFailureApp < Devise::FailureApp
   class << self
     attr_accessor :cookie
 end

and tried adding this to application controller:

def initialize
   CustomFailureApp.cookie cookies           
   super
end

So that I could then modify the cookie in CustomFailureApp:

def respond    
    unless request.format.to_sym == :html
      http_auth
else
    store_location!
    flash[:alert] = i18n_message

    if request.subdomain == 'abc' && i18n_message.includes?('Invalid login or password')
      CustomFailureApp.cookie.delete :tracker_for_external_clients           
      uri = URI('http://abc.com/?page_id=425')          
      params = { 'message' => i18n_message }
      uri.query = URI.encode_www_form(params)

      res = Net::HTTP.get_response(uri)

      if res.is_a?(Net::HTTPSuccess)            
        Rails.logger.info "The response is #{res.body}" 
      else
        Rails.logger.info "Something went wrong"
      end

       redirect_to redirect_url
end

end

But I get this error:
undefined method `cookie_jar' for nil:NilClass

I need to be able to delete the cookie after devise has determined the user has entered the wrong password, so that i could kill the proxy i am using between two servers.

thanks for response

José Valim
Owner

Please read: https://github.com/plataformatec/devise/wiki/Bug-reports

And please format the code in the report properly.
If you don't care enough to format it yourself, you cannot expect a bigger effort from us on helping you. Thanks.

José Valim josevalim closed this
LatvianDancers

I formatted code, and I know for fact that I will not get an answer to this on google groups. I already have asked 4 devise questions in past on google groups to which no response. So I am not sure why this issue is closed. It's clear that there is a defined issue here: "How do you have control (in this case deleting a cookie) after devise has determined that a user has entered the wrong password in the latest version of devise." Thanks for response and consideration in reopening the issue. And if you would like to reply to the question on google groups its here: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/ac4c4f2daa54dd81 thanks for response

José Valim
Owner

The thing is, this is a user issue, not a Devise issue. In any case, you should be able to access the cookies as request.cookie_jar in the failure app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.