Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## helm/acts_as/account.rb
- require 'helm/authentication'
- module Helm
- module ActsAs
- module Account
- def self.included(base)
- base.extend ClassMethods
- base.send :include, Helm::ActsAs::Account::InstanceMethods
- base.alias_method_chain :authenticate, :helm
- end
- module ClassMethods
- alias_method_chain :authenticate, :helm
- def authenticate_with_helm(login, password)
- user = authenticate_without_helm(login, password)
- return user unless user.nil?
- # user is nil, so they weren't successfully authenticated without helm.
- user = find(:first, :conditions => {:login => login})
- return nil unless user.nil? or not user.is_helm_account?
- return nil unless Helm::Authentication.verify(login, password)
- # update or store the user
- if user
- user.update_attributes(:password => password, :password_confirmation => password)
- else
- create(:login => login, :password => password, :password_confirmation => password)
- end
- end
- end
- module InstanceMethods
- def is_helm_account?
- self.is_helm_account
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment