I’m try to verify users on login. Here is my code:
def self.authenticate(username,password,account_code)
employee = self.find(:all,
:select => “e.id, e.first_name, e.last_name, e.username,
e.account_id, e.department_id, o.pay_type_id, o.admin_yn, o.payroll_yn,
o.files_yn, o.dept_report_yn,e.salt, e.hashed_password”,
:conditions => [“e.deleted_yn=0 and e.username = ? and
a.account_code = ?”, username, account_code],
:joins => "as e left outer join options o on e.id = o.employee_id
left outer join accounts a on e.account_id = a.id ")
if employee
expected_password = encrypted_password(password, employee.salt)
if employee.hashed_password != expected_password
employee = nil
end
end
employee
end
I keep getting an error saying “undefined method ‘salt’”. Any ideas?
Thanks
Simply Dope wrote:
Sorry, forgot I changed it to just a “find” instead of “find_by_sql”.
Error is still the same though.
On Jul 8, 2007, at 10:21 PM, George P. wrote:
:joins => "as e left outer join options o on e.id =
end
I keep getting an error saying “undefined method ‘salt’”. Any ideas?
Thanks
The object refered to by employee is likely not of the Employee model
class. Try not overriding the :select list in your find and letting
AR’s associations do some of the heavy lifting:
Assuming associations to options and account:
class Employee < ActiveRecord::Base
has_many :options
belongs_to :account
def self.authenticate username, password, account_code
if employee = find(:first, :include => [ :account, :options ],
:conditions => [ “employees.deleted_yn = ?” +
" AND employees.username = ?" +
" AND accounts.account_code
= ?",
false, username, account_code ])
expected_password = encrypted_password(password, employee.salt)
if employee.hashed_password != expected_password
employee = nil
end
end
employee
end
end
-Rob
Rob B. http://agileconsultingllc.com
[email protected]
Thanks Rob, that worked like a champ.
George