Module: Models::PasswordAuthentication::ClassMethods

Defined in:
lib/_models/password_authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_by_password(name, password) ⇒ Object



53
54
55
56
57
# File 'lib/_models/password_authentication.rb', line 53

def authenticate_by_password name, password
  return nil if name.blank? or password.blank?
  u = Models::User.first 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



71
72
73
74
75
76
77
# File 'lib/_models/password_authentication.rb', line 71

def encrypt_password password, salt
  digest = SITE_KEY
  DIGEST_STRETCHES.times do
    digest = secure_digest(digest, salt, password, SITE_KEY)
  end
  digest
end

#generate_tokenObject



79
80
81
# File 'lib/_models/password_authentication.rb', line 79

def generate_token
  secure_digest Time.now, (1..10).map{ rand.to_s }
end