AnApprentice
AnApprentice

Reputation: 110940

How to override the Devise Passwords Controller?

How to override the Devise Passwords Controller:

https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb

I want to do the following:

  1. downcase all emails submitted for password reset. All the emails in the DB as lowercase. If a user tried to reset a valid email with any characters uppercase, the reset fails to find a user. And devise doesn't even give a error message saying no user found
  2. If no user is found in def create, I want to add a flash that says, no user found, did you enter the right email?

How can I accomplish the 2 items above? I believe that required overriding the devise password controller. How do I do that? Or if you have a better solution that's even cleaner, I would like to hear it.

Thanks

Upvotes: 0

Views: 4488

Answers (1)

amit_saxena
amit_saxena

Reputation: 7614

the devise initializer has a option to make any field case insensitive:

config.case_insensitive_keys = [ :email ]

If I remember correctly it was added in the newer version and if you don't see some related comments in you initializer then you should upgrade your devise gem using bundle upgrade devise. I am using version 1.3.3. And this version also shows an error "Email not found" if an invalid email is entered.

If you not getting the error message add <%= devise_error_messages! %> to your view. You can customize the error messages by editing config/locales/devise.en.yml

Upvotes: 3

Related Questions