6

I need to be able to create a UserSession without having the decrypted password.

How do I go about doing this?

My current workaround is:

In user.rb

def valid_crypted_or_non_crypted_password?(password) 
   valid_password?(password) || password == crypted_password
end

In user_session.rb

verify_password_method :valid_crypted_or_non_crypted_password?

To login

UserSession.create(:login => u.login, :password => u.crypted_password) 

Is there a nicer way to do this?

Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
  • Why is it that you do not have the decrypted password? Can't you create the User with a factory before this and be explicit about the password? – ryanb Aug 18 '09 at 17:01
  • nope, in this case I would like my admin to browse the website pretending to be a different user. or in the case of open id I have the user record but the password is crypted – Sam Saffron Aug 18 '09 at 23:04

1 Answers1

12

According to the documentation you can pass a user object to UserSession.create.

UserSession.create(@some_user)

I haven't tried it though.

ryanb
  • 16,227
  • 5
  • 51
  • 46
  • Sam, I can't get this working (and detail it here): http://stackoverflow.com/questions/1234920/integration-testing-with-authlogic/1332275#1332275 any thoughts on how you got yours working are much appreciated! – kareem Aug 31 '09 at 21:46