Guest User

Untitled

a guest
Apr 9th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 KB | None | 0 0
  1.  public function facebookloginAction() {
  2.        
  3.          require_once '/../../library/facebook/facebook.php';
  4.         $facebook = new Facebook(array(
  5.                     'appId' => '124350477672032',
  6.                     'secret' => '5d23a003d42104d563d8743cc7ca6cc0',
  7.                     'cookie' => true,
  8.                 ));
  9.        
  10. //        $this->view->url = $facebook->getLoginUrl(array('next' => $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . '/auth/facebooklogin'));
  11.        
  12.        
  13. //        require_once '/../../library/facebook/facebook.php';
  14. //        $facebook = new Facebook(array(
  15. //                    'appId' => '124350477672032',
  16. //                    'secret' => '5d23a003d42104d563d8743cc7ca6cc0',
  17. //                    'cookie' => true,
  18. //                ));
  19.         $session = $facebook->getSession();
  20.         if ($session) {
  21.             try {
  22.                 $uid = $facebook->getUser();
  23.                 $me = $facebook->api('/me');
  24.                 $email = $me['email'];
  25.             } catch (FacebookApiException $e) {
  26.                 error_log($e);
  27.             }
  28.         }
  29.         if ($session) {
  30.             $result = Model_UserMapper::getInstance()->userExistFacebook($uid);
  31.             if ($result->count() == 1) {
  32.                 $authAdapter = $this->_getAuthAdapter();
  33.                 foreach ($result as $rez) {
  34.                     $username = $rez['username'];
  35.                     $password = $rez['password'];
  36.                 }
  37.                 $authAdapter->setIdentity($username)
  38.                         ->setCredential($password);
  39.                 $auth = Zend_Auth::getInstance();
  40.                 $result = $auth->authenticate($authAdapter);
  41.                 $identity = $authAdapter->getResultRowObject();
  42.                 $authStorage = $auth->getStorage();
  43.                 $authStorage->write($identity);
  44.                 $this->_redirect('/index/index/');
  45.             }
  46.             $emailExists = Model_UserMapper::getInstance()->userExistEmail($email);
  47.             if ($emailExists == 1) {
  48.                 Model_UserMapper::getInstance()->updateFUid($uid, $email);
  49.                 $this->_redirect('/auth/facebooklogin');
  50.             } else {
  51.                 $this->_redirect('/auth/registerfacebook');
  52.             }
  53.         }
  54.     }
Add Comment
Please, Sign In to add comment