Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function facebookloginAction() {
- require_once '/../../library/facebook/facebook.php';
- $facebook = new Facebook(array(
- 'appId' => '124350477672032',
- 'secret' => '5d23a003d42104d563d8743cc7ca6cc0',
- 'cookie' => true,
- ));
- // $this->view->url = $facebook->getLoginUrl(array('next' => $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . '/auth/facebooklogin'));
- // require_once '/../../library/facebook/facebook.php';
- // $facebook = new Facebook(array(
- // 'appId' => '124350477672032',
- // 'secret' => '5d23a003d42104d563d8743cc7ca6cc0',
- // 'cookie' => true,
- // ));
- $session = $facebook->getSession();
- if ($session) {
- try {
- $uid = $facebook->getUser();
- $me = $facebook->api('/me');
- $email = $me['email'];
- } catch (FacebookApiException $e) {
- error_log($e);
- }
- }
- if ($session) {
- $result = Model_UserMapper::getInstance()->userExistFacebook($uid);
- if ($result->count() == 1) {
- $authAdapter = $this->_getAuthAdapter();
- foreach ($result as $rez) {
- $username = $rez['username'];
- $password = $rez['password'];
- }
- $authAdapter->setIdentity($username)
- ->setCredential($password);
- $auth = Zend_Auth::getInstance();
- $result = $auth->authenticate($authAdapter);
- $identity = $authAdapter->getResultRowObject();
- $authStorage = $auth->getStorage();
- $authStorage->write($identity);
- $this->_redirect('/index/index/');
- }
- $emailExists = Model_UserMapper::getInstance()->userExistEmail($email);
- if ($emailExists == 1) {
- Model_UserMapper::getInstance()->updateFUid($uid, $email);
- $this->_redirect('/auth/facebooklogin');
- } else {
- $this->_redirect('/auth/registerfacebook');
- }
- }
- }
Add Comment
Please, Sign In to add comment