Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting User information in beforeRender issue #145

Open
robksawyer opened this issue Aug 26, 2013 · 1 comment
Open

Getting User information in beforeRender issue #145

robksawyer opened this issue Aug 26, 2013 · 1 comment

Comments

@robksawyer
Copy link

I'd like to be able to get a Facebook user's information within the beforeRender method and the only way I've been able to do this is using the following method. Is there a better way?

$this->Connect->setAccessToken($this->current_user['facebook_oauth_token']); //Try to reset the oauth token
$this->Connect->uid = $this->current_user['facebook_id'];
$this->Connect->initialize($this);
$this->Connect->startup($this);
$this->facebook_user = $this->Connect->user();
@amjo
Copy link

amjo commented Aug 26, 2013

to solve that i've created a Session Variable within the beforeRender of the AppController:

if($this->Auth->loggedIn()){
$id = $this->Auth->user('id');
$logged_user = $this->User->findById($id); //knowing that i've saved all the user details i've grabbed from Facebook in the users table
$this->Session->write('LoggedUser', $logged_user);
}

this way you can call it from any method of any controller.
of course, don't forget to do "$this->Session->destroy();" upon logout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants