Closed joshuaswilcox closed 12 years ago
What model are you associating Auth to use? How have you setup your Auth/Facebook in your AppController?
The Auth is associated with my Users model but defined in the AppController, for use everywhere (to save users related content). The following is my AppController setup.
<?php class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),
'authError' => 'Did you really think you are allowed to see that?',
'authorize' => array('Controller') // Added this line
),
'RequestHandler',
'Facebook.Connect'
);
public $helpers = array(
'Html',
'Js',
'Form',
'Session',
'Facebook.Facebook'
);
public function isAuthorized($user) {
if (isset($user['role']) && $user['role'] === 'admin') {
return true; //Admin can access every action
}
return false; // The rest don't
}
function beforeFilter() {
$this->Auth->allow('display');
}
} ?> Again, thanks for your work on this plugin, and any help.
Also it is doing this on every page for every controller, So I imagine its an AppController issue or something.
Also when I manually override the $useTable in AppModel.php to false, to not throw the app_model table error, the Facebook login works, but doesn't create a new user in the Users table and doesn't seem to be interacting with the Auth component at all.
EDIT: Heres the print_r from the $this->Component->Auth: <?php [Connect] => ConnectComponent Object ( [uid] => 32203736 [me] => [hasAccount] => [authUser] => [noAuth] => [errors] => Array ( )
[createUser] => 1
[_Collection:protected] => ComponentCollection Object
RECURSION [settings] => Array ( )
[components] => Array
(
)
[_componentMap:protected] => Array
(
)
[Controller] => PagesController Object
RECURSION [FB] => FB Object ( )
[User] => AppModel Object
(
[useDbConfig] => default
[useTable] => app_models
[id] =>
[data] => Array
(
)
[table] => app_models
[primaryKey] => id
[_schema:protected] =>
[validate] => Array
(
)
[validationErrors] => Array
(
)
[validationDomain] =>
[tablePrefix] =>
[name] => AppModel
[alias] => AppModel
[tableToModel] => Array
(
[app_models] => AppModel
)
[cacheQueries] =>
[belongsTo] => Array
(
)
[hasOne] => Array
(
)
[hasMany] => Array
(
)
[hasAndBelongsToMany] => Array
(
)
?>
Ok, so I seems to have figured most of what I need out, with some tinkering inside the plugin as well as some additions to my AppModel and AppController. I do have one question though that I can't figure out. When using the normal cake auth, you can check for a logged-in user using
$this->Session->read('Auth.User.id');
but for facebook logged in users i have to do:
$this->Session->read('Auth.User.AppModel.id');
This is slightly inconvienent, as I need to go through my whole app and adjust interactions based on logged in users to accomodate this, but before I did that, I was curious the reason for this.
Hey, I have the same issues. Is a fix aviable? I use the following settings in my global app controller:
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email', 'password' => 'password')
)
),
'loginRedirect' => '/shootings/',
'loginAction' => '/'
), 'Facebook.Connect', 'Session');
so I use the default 'users' Table for storing user information.
Which issue the initial issue or the one after the inital fix of the:
$this->Session->read('Auth.User.AppModel.id');
The latter I am still waiting for, the initial database issue, I was able to fix. Let me know, and I'll let you know what I did.
The changes from 1.3 to 2.0 in the plugin were going based on the migration path, there have been changes to the Auth component that I haven't had time to figure out best integration with the plugin out of the box. Auth.User.idwas the default place to find the user_id session in Auth for 1.3. If it's changed in 2.0 I will need to update the plugin accordingly. It's odd that's now Auth.User.AppModel.id.
Nick
On Thu, Nov 10, 2011 at 1:34 PM, Joshua Wilcox < reply@reply.github.com>wrote:
Which issue the initial issue or the one after the inital fix of the:
$this->Session->read('Auth.User.AppModel.id');
The latter I am still waiting for, the initial database issue, I was able to fix. Let me know, and I'll let you know what I did.
Reply to this email directly or view it on GitHub:
https://github.com/webtechnick/CakePHP-Facebook-Plugin/issues/30#issuecomment-2700731
Hi folks,
thanks for the fast reply. Sorry I forgot to mention. I have the initial problem, when I use Auth together with Facebook.Connect he tries to:
/app/Plugin/Facebook/Controller/Component/ConnectComponent.php(108): Model->hasField('facebook_id')
whichs finally fails becaus the script tries to load a model called app_model which does not exist.
oh and by the way: great plugin what I have seen so far. :D (just started to use it with cake 2.0)
Well the Auth didn't really change from what I can tell, because for my normal registration i still access Auth.User.id, but the session for the FB component is being saved in Auth.User.AppModel.id, and i can't figure out why its saving in a nested array like that.
@tfelix For that issue i created an AppModel.php in my model folder and had nothing in it but a class definition:
class AppModel extends Model { public $useTable = 'Users'; }
Then in every other model I had to define the $useTable variable for the particular table. But this is still a hack that is related to the second issue of the FB session being stored in Auth.User.AppModel.id.
Hi Nick - Thanks for what appears to be a great plugin from what I can see so far. I'm also experiencing the same issue and am looking forward to a potential fix,
This has been resolved in the latest cakephp2.0 branch commit. https://github.com/webtechnick/CakePHP-Facebook-Plugin/commit/2e83573883d767cc6814a726b29840351b2f3dbb
Because of how Auth was re-worked a lot of the automagic that happened can't happen anymore (as they took out a lot of the automagic from the new AuthComponent). as such you'll now have to define the model in which you want Facebook to interact with for Auth integration (default is false).
Here's a sample setup:
public $components = array('Session',
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
),
'authorize' => 'Controller'
),
'Facebook.Connect' => array('model' => 'User')
);
Working great for me! Thanks!!
Hi joshuaswilcox
your comment on Model->hasField('facebook_id') problum saved me lot
thanks and welcome
Hi there, I get the following when trying to initialize the plugin. The actual button for login works, but the page is filled with an error when the plugin is active: Missing Database Table Error: Database table app_models for model AppModel was not found. Notice: If you want to customize this error message, create app/View/Errors/missing_table.ctp Stack Trace
0 /Users/jwilcox/Projects/web-applications/akzo-color/lib/Cake/Model/Model.php(3236): Model->setSource('app_models')
1 /Users/jwilcox/Projects/web-applications/akzo-color/lib/Cake/Model/Model.php(1206): Model->getDataSource()
2 /Users/jwilcox/Projects/web-applications/akzo-color/lib/Cake/Model/Model.php(1292): Model->schema()
3 /Users/jwilcox/Projects/web-applications/akzo-color/app/Plugin/Facebook/Controller/Component/ConnectComponent.php(108): Model->hasField('facebook_id')
4 /Users/jwilcox/Projects/web-applications/akzo-color/app/Plugin/Facebook/Controller/Component/ConnectComponent.php(80): ConnectComponent->__syncFacebookUser()
5 [internal function]: ConnectComponent->startup(Object(PagesController))
6 /Users/jwilcox/Projects/web-applications/akzo-color/lib/Cake/Utility/ObjectCollection.php(110): call_user_func_array(Array, Array)
7 /Users/jwilcox/Projects/web-applications/akzo-color/lib/Cake/Controller/Controller.php(606): ObjectCollection->trigger('startup', Array)
8 /Users/jwilcox/Projects/web-applications/akzo-color/lib/Cake/Routing/Dispatcher.php(104): Controller->startupProcess()
9 /Users/jwilcox/Projects/web-applications/akzo-color/lib/Cake/Routing/Dispatcher.php(89): Dispatcher->_invoke(Object(PagesController), Object(CakeRequest), Object(CakeResponse))
10 /Users/jwilcox/Projects/web-applications/akzo-color/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
11 {main}
I wasnt sure if I had to create a new table for some reason, but I couldn't figure out the problem. I am using Cake 2.0 and trying to hook into the Auth I already have. Thanks for any support!