Cruze
Cruze

Reputation: 220

Rails Devise authentication with email and another field

Using rails with devise. On user table I have email and a field record_status. Record status will contain 'active' or 'deleted'

What do I need to change to authenticate using email and record_status = 'active'.

I have this code in place.

in my user model

def self.find_for_database_authentication(warden_conditions)
  status = 'active'
  where(:email => warden_conditions[:email], :record_status => warden_conditions[:status]).first
end

in my initializer devise.rb

config.case_insensitive_keys = [:email]

thanks for the help guys

Upvotes: 0

Views: 518

Answers (1)

MZaragoza
MZaragoza

Reputation: 10111

there is a initializers for devise its file path is config/initializers/devise.rb ruffly on line 37 you should see

# config.authentication_keys = [:email]

now you can update this to be

config.authentication_keys = [:email, :other_field]

Configuration for any authentication mechanism Configure which keys are used when authenticating a user. The default is just :email. You can configure it to use [:username, :subdomain], so for authenticating a user, both parameters are required. Remember that those parameters are used only when authenticating and not when retrieving from session. If you need permissions, you should implement that in a before filter. You can also supply a hash where the value is a boolean determining whether or not authentication should be aborted when the value is not present.

Upvotes: 2

Related Questions