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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Simply Dope wrote: Sorry, forgot I changed it to just a "find" instead of "find_by_sql". Error is still the same though. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 8, 2007, at 10:21 PM, George Pasley wrote:> 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? > > ThanksThe 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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Rob, that worked like a champ. George -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---