Guest User

Untitled

a guest
Mar 1st, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. ## helm/acts_as/account.rb
  2. require 'helm/authentication'
  3. module Helm
  4. module ActsAs
  5. module Account
  6. def self.included(base)
  7. base.extend ClassMethods
  8. base.send :include, Helm::ActsAs::Account::InstanceMethods
  9.  
  10. base.alias_method_chain :authenticate, :helm
  11. end
  12.  
  13. module ClassMethods
  14. alias_method_chain :authenticate, :helm
  15. def authenticate_with_helm(login, password)
  16. user = authenticate_without_helm(login, password)
  17. return user unless user.nil?
  18.  
  19. # user is nil, so they weren't successfully authenticated without helm.
  20. user = find(:first, :conditions => {:login => login})
  21.  
  22. return nil unless user.nil? or not user.is_helm_account?
  23. return nil unless Helm::Authentication.verify(login, password)
  24.  
  25. # update or store the user
  26. if user
  27. user.update_attributes(:password => password, :password_confirmation => password)
  28. else
  29. create(:login => login, :password => password, :password_confirmation => password)
  30. end
  31. end
  32. end
  33.  
  34. module InstanceMethods
  35. def is_helm_account?
  36. self.is_helm_account
  37. end
  38. end
  39. end
  40. end
  41. end
Add Comment
Please, Sign In to add comment