Saturday, July 3, 2010

Integrating CKEditor and CakePHP : Part 5

In Part 4 of the session, I covered how to integrate CakePHP database session into CKFinder. In this article, I will cover how to integrate CakePHP Authentication.

This is only going to cover basic authentication for the moment. No tricky ACLs, and no roles.

First, we'll need to set up our application to have someone log in. I created a users table with id, username and password. Let the baking ensue!

Because I'm aiming for the simplest set up, and least amount of code, I followed the Authentication example over from the CakePHP Authentication documentation. Namely, use the Auth and Session components in the AppController, provide login and logout actions on the Users controller, and a login view. Once you've set this up, you may wish to temporarily set the allowActions on the Users controller to '*', so you can set up at least one user entry. Then return the allowedActions back to array('login','logout').

Now we can tie in CakePHP Authentication with our CKFinder configuration file.

Comment out or remove the CheckAuthentication() function from ckfinder/config.php, and add it to vendors/ckfinder/

function CheckAuthentication() {
    $Session = new CakeSession();
    return $Session->check('Auth.User');

There are multiple ways to check for a valid authenticated session, but this is the easiest. Of course, it makes an assumption that your authentication model is the User table.

You may wish to use the Auth component directly, and use $Auth->user() to retrieve the user details. I'll probably use that mention when I take a look at integrating ACLs.

Series Index : Part 1, Part 2, Part 3, Part 4, Part 5, Part 6

No comments:

Post a Comment