Module: Headstart::User::ClassMethods
- Defined in:
- lib/headstart/user.rb
Instance Method Summary collapse
-
#authenticate(email, password) ⇒ User?
Authenticate with email and password.
- #find_facebook_user(facebook_code, full_app_path) ⇒ Object
Instance Method Details
#authenticate(email, password) ⇒ User?
Authenticate with email and password.
253 254 255 256 257 |
# File 'lib/headstart/user.rb', line 253 def authenticate(email, password) email.downcase! if email.present? return nil unless user = find_by_email(email) return user if user.authenticated?(password) end |
#find_facebook_user(facebook_code, full_app_path) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/headstart/user.rb', line 259 def find_facebook_user(facebook_code, full_app_path) return nil unless Headstart.configuration.use_facebook_connect && facebook_code begin access_token_hash = MiniFB.oauth_access_token(Headstart.configuration.facebook_app_id, full_app_path + "/sessions/create", Headstart.configuration.facebook_secret_key, facebook_code) @response_hash = MiniFB.get(access_token_hash['access_token'], 'me', :type=> nil, :metadata=>true) @response_hash["user"] == @response_hash.user rescue MiniFB::FaceBookError @response_hash = nil end return nil unless @response_hash user = ::User.find_by_facebook_uid(@response_hash['id']) || ::User.find_by_email(@response_hash['email']) || ::User.new user.tap do |user| user.facebook_uid = @response_hash['id'] user.email = @response_hash['email'] user.first_name = @response_hash['first_name'] user.last_name = @response_hash['last_name'] user.save end end |