Project

General

Profile

Need help with creating a plugin that adds extra cookie to authenticated users

Added by George Notaras about 8 years ago

Hello everybody!

First of all, I should clarify that I'm totally clueless about Ruby and Ruby-on-Rails.

I tried to follow the page about utilizing the available hooks in order to customize the functionality of Redmine.

My goal is to set an extra custom cookie at login and remove it at logout.

After much effort and trial'n'error, I created a plugin which contains the following in lib/my_auth_cookie/hooks.rb:

module MyAuthenticatedCookie
  class Hooks < Redmine::Hook::ViewListener
    def controller_account_success_authentication_after(context={ })
      cookie_options = {
        :value => '1',
        :expires => 1.year.from_now,
        :path => '/',
        :httponly => true
      }
      cookies[:redmine_authenticated] = cookie_options
    end
  end
end

The problem is that I'm getting an error in the log:

NameError (undefined local variable or method `cookies' for [...]

How can I make the cookies method available in my function? I could not find a solution and I'd appreciate any help with it.

Some info about what I'm trying to do. I want to add an extra cookie to authenticated users which I'm going to use in order to exclude authenticated users from getting cached pages. I intent to serve cached pages to non authenticated users. This is a little vague method, but it's better than nothing. This extra cookie won't be used for access control.

George


Replies (1)

RE: Need help with creating a plugin that adds extra cookie to authenticated users - Added by George Notaras about 8 years ago

Alternatively, adding a custom HTTP header in the response for authenticated users would also do the job nicely. Any help is appreciated.

    (1-1/1)