Posted By

sulco on 08/14/13


Tagged


Versions (?)

FB app login


 / Published in: PHP
 

FB app login

  1. Route::filter('auth.fb', function()
  2. {
  3. $facebook = new Facebook(array(
  4. 'appId' => Config::get('facebook.appId'),
  5. 'secret' => Config::get('facebook.appSecret'),
  6. ));
  7.  
  8. $fbUser = $facebook->getUser();
  9.  
  10. if ($fbUser) {
  11. try {
  12. $fbUser = $facebook->api('/me');
  13.  
  14. $fbid = $fbUser['id'];
  15. $user = User::where('fbid', '=', $fbid)->first();
  16. if (!$user) {
  17. $user = new User;
  18. (�����)
  19. $user->save();
  20. }
  21. Auth::login($user);
  22.  
  23. } catch (FacebookApiException $e) {
  24. return Redirect::to('/');
  25. }
  26.  
  27. } else {
  28. $loginUrl = $facebook->getLoginUrl(array(
  29. 'scope' => 'email (����)',
  30. 'redirect_uri' => 'http://apps.facebook.com/' . Config::get('facebook.appNamespace') . '/',
  31. ));
  32.  
  33. return View::make('facebook/login', compact('loginUrl'));
  34. }
  35. });

Report this snippet  

You need to login to post a comment.