Monday, September 28, 2009

restful_authentication and rails 1.2.2

according to the github page, the restful_authentication plugin only works for 1.2.6+ -- even the backwards compatible classic version. i've got a 1.2.2 app that i want to plug it into. here's how i rammed it through.

- 'ln -s new.html.erb new.rhtml'

created a symlink for sessions view new.rhtml that points to new.html.erb. i think it used the html.erb extension because i have 2.3.4 installed on my machine too. so when i ran script/generate, it used rails 2.3.4 even tho this particular app uses 1.2.2.

- # restful authentication routes
map.resources :sessions, :only => [:new, :destroy, :create]
map.signup '/signup', :controller => 'users', :action => 'new'
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'

added these to my routes file. the last three lines you are told to add when you run the script/generate. the last one is needed because there is a reference to a named restful route in the sessions/new view. plus it's good restful form anyways.

- had to hack out some stuff from the lib/authenticated_system.rb file thats created by the generator (since calls are made to authenticate_with_http_basic wasn't added until rails 2.0) this will surely cause the unit tests to break and makes the system a bit less robust. for my purposes, that's just fine.

in current_user, replaced: @current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie) unless @current_user == false

with: @current_user ||= (login_from_session) unless @current_user == false

and in the access_denied method, commented out:
#format.any do
# request_http_basic_authentication 'Web Password'
#end

that's it. everything seems to be working now.

-h