Module: MongoMapper::Plugins::PasswordAuthentication::ClassMethods
- Defined in:
- lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb
Instance Method Summary collapse
- #acts_as_authenticated_by_password ⇒ Object
- #authenticate_by_password(name, password) ⇒ Object
-
#encrypt_password(password, salt) ⇒ Object
def by_secure_token token first :conditions => { :secure_token => token, :secure_token_expires_at => => Time.now.utc } end.
- #generate_token ⇒ Object
Instance Method Details
#acts_as_authenticated_by_password ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb', line 74 def acts_as_authenticated_by_password key :crypted_password, String, :protected => true key :salt, String, :protected => true attr_reader :password validates_confirmation_of :password, :if => :validate_password? validates_length_of :password, :within => PASSWORD_LENGTH, :if => :validate_password? end |
#authenticate_by_password(name, password) ⇒ Object
83 84 85 86 87 |
# File 'lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb', line 83 def authenticate_by_password name, password return nil if name.blank? or password.blank? u = User.first :conditions => {:state => 'active', :name => name} u && u.authenticated_by_password?(password) ? u : nil end |
#encrypt_password(password, salt) ⇒ Object
def by_secure_token token
first :conditions => {
:secure_token => token,
:secure_token_expires_at => {:$gt => Time.now.utc}
}
end
def by_open_id id
return nil if id.blank?
first :open_ids => id
end
101 102 103 104 105 106 107 |
# File 'lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb', line 101 def encrypt_password password, salt digest = SITE_KEY DIGEST_STRETCHES.times do digest = secure_digest(digest, salt, password, SITE_KEY) end digest end |
#generate_token ⇒ Object
109 110 111 |
# File 'lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb', line 109 def generate_token secure_digest Time.now, (1..10).map{ rand.to_s } end |