I am using CakePHP-Facebook-Plugin from webtechnick (https://github.com/webtechnick/CakePHP-Facebook-Plugin/) and I am having some problems recognizing that the user has already registered on facebook. The problem is that I log into facebook, then open my site (localhost.localdomain) and I have not logged in. Then I refresh the page of my site and I am logged in. Above is the code I'm using. I tested it and in the first request, calling this this → Connect-> user () returns false (first and second), then the page is displayed, and I think that some kind of magic is executed by the init or FacebookHelper-> login method, because, if I call him without redirecting, he says I'm on the network and use my site; with a redirect set, it shows the label and on the second request that is logged in.
I tried to initialize FacebookHelper and call "login" on beforeFilter, but did not succeed (with and without redirection).
In addition, the logic that displays the Facebook login buttons or the exit buttons is executed further in the beforeFilter file, defining a specific layout based on the value of $ this-> Session-> check ('Auth.User.id').
27 public function beforeFilter() {
28
29 try {
30 $user = $this->Auth->user();
31 $fb_user = $this->Connect->user();
32 } catch (FacebookApiException $e) {
33 }
34 Configure::write('VertWeb.show_tabs', true);
35 if ($fb_user = $this->Connect->user()) {
36 if (!$this->Auth->loggedIn()) {
37 if (!isset($fb_user['error_code'])) {
38 $this->loadModel('User');
39 $this->User->recursive = -1;
40 if (($user = $this->User->findByFacebookId($fb_user['id'])) ||
41 ($user = $this->User->findByEmail($fb_user['email'])) ) {
42
43 $this->Auth->login($user);
44 $this->Session->write('Auth.FacebookUser', $fb_user);
45 $this->Session->write('Auth.User', $user['User']);
46 $this->Session->write('Auth.FacebookUserPicture', FB::api('/me?fields=picture'));
Regards, Daniel
source
share