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



250
251
252
253
# File 'lib/blue_light_special/user.rb', line 250

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



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/blue_light_special/user.rb', line 255

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