DBA (owner)

Revisions

gist: 42980 Download_button fork
public
Public Clone URL: git://gist.github.com/42980.git
Ruby
1
2
3
4
5
6
7
8
9
  # This custom version of the authenticate method allows the user to use login or email as unique keys.
  # Please note that if using this method it's highly recommended that you make the email property, of the user model, a required one.
  # Also consider adding a unique index to the email field. For that create a migration with: add_index :users, :email, :unique => true
  # It's equally advisable to remove the nullable option from the email field.
  def self.authenticate(login, password)
    return nil if login.blank? || password.blank?
    u = find :first, :conditions => ['(email = ? OR login = ?) and activated_at IS NOT NULL', login, login] # need to get the salt
    u && u.authenticated?(password) ? u : nil
  end