0
votes

I'm building my first Cakephp application, but I'm pulling my hairs over this problem: I need my application (mydomain.com/cake-app) to co-operate with another non-cake php application (mydomain.com/custom-class) on the same server.

Both applications should share authentications and sessions, and I would like Cakephp to handle these.

However, custom-class will need to see who's logged in, and also add/edit users to my cake-app db, either by accessing my User Model, or by calling an setUser action in my UsersController. custom-class does not have access to the cake-app database.

How can I access Cakephp's AuthComponent and my User Model / UsersController from outside the Cakephp framework? What cake files do I need to include in my custom-class in order to accomplish this?

1
However, ... add/edit users to my cake-app db, ... custom-class does not have access to the cake-app database. ???? - Salines
Why not use a REST inteface that the non cake app can interact with? - Colonel Mustard

1 Answers

1
votes

custom-class does not have access to the cake-app database.

The only way is an API then that doesn't require direct DB access. Implement a RESTful API for example that your none-cake app can call.

However, custom-class will need to see who's logged in, and also add/edit users to my cake-app db, either by accessing my User Model, or by calling an setUser action in my UsersController.

You'll have to read the cookie then and the cookie needs to require something you can send along with your API request so that the API knows who is asking for what.

You won't be able to simply require() or include() a few files from Cake and it will work, this isn't going to happen because the Auth system is a complete stack, you would have to initialize a request, controller, component collection, auth component and the auth adpater(s). Instead check how Cake writes and reads the Cookie and implement the same way in your custom class. But pay attention, Cake saves the cookie encrypted.