3

I have my User model authenticating with Devise and I want to overwrite the valid_password method as this, in my user.rb inside the class definition I have

class User < ActiveRecord::Base
  devise  :database_authenticatable

  # overwriting the valid_password from database_authenticatable
  module PostDatabaseAuthenticatable 

   def valid_password?(password)
    if old_password
      # do something new
    else
      # call valid_password from DatabaseAuthenticatable
      super
    end 
   end 

  end 

  include PostDatabaseAuthenticatable

end

So First we include the database_authenticatable through devise then include my PostDatabaseAuthenticatable so according to what I read Rails 3: alias_method_chain still used? it should totally overwrite devise's valid_password method.

But when I run my code it always calls this first and then no mather what calls devise, so doesn't overwrite it at all.

Any ideas why?

Community
  • 1
  • 1
Matilda
  • 1,708
  • 3
  • 25
  • 33

1 Answers1

1

Actually this was working all along, I was debugging it wrong. Also I don't need the module overrride, just createing a valid_password?(password) method insdie of the user class does the job

Matilda
  • 1,708
  • 3
  • 25
  • 33
  • I am also trying this but not working for me. I need to login without password authentication means login with only username. – Ankit Tyagi May 20 '14 at 08:20
  • The `valid_password?` method is only called when you have a valid email or username. Perhaps you're testing with an invalid one? – Tim Fletcher Dec 11 '14 at 03:36