Module: BlueLightSpecial::User::ClassMethods

Defined in:
lib/blue_light_special/user.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(email, password) ⇒ User?

Authenticate with email and password.

Examples:

User.authenticate("[email protected]", "password")

Parameters:

  • email (String, String)

    and password

Returns:

  • (User, nil)

    authenticated user or nil



212
213
214
215
# File 'lib/blue_light_special/user.rb', line 212

def authenticate(email, password)
  return nil  unless user = find_by_email(email)
  return user if     user.authenticated?(password)
end

#find_facebook_user(facebook_session, facebook_uid) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/blue_light_special/user.rb', line 217

def find_facebook_user(facebook_session, facebook_uid)
  return nil unless BlueLightSpecial.configuration.use_facebook_connect && facebook_session && facebook_uid
  
  begin
    facebook_user = MiniFB::Session.new(BlueLightSpecial.configuration.facebook_api_key,
                                        BlueLightSpecial.configuration.facebook_secret_key,
                                        facebook_session, facebook_uid).user
  rescue MiniFB::FaceBookError
    facebook_user = nil
  end
  return nil unless facebook_user
  
  user = ::User.find_by_facebook_uid(facebook_uid) || ::User.find_by_email(facebook_user['email']) || ::User.new
  user.tap do |user|
    user.facebook_uid     = facebook_uid
    user.email            = facebook_user['email']
    user.first_name       = facebook_user['first_name']
    user.last_name        = facebook_user['last_name']
    user.save
  end
end