As I had already written some articles (hard coded too...) I figured it would probably be a good idea to link to them directly. The first is an authentication plugin for CakePHP, DarkAuth.
I wrote DarkAuth as an alternative to the inbuilt "Auth" authentication system in CakePHP 1.2. I never really looked at "Auth" so cannot comment on how good it is. I can say that DarkAuth works for me and how I want it to.
"How I want it to."
That's right, how I want it to. It may be perfect for you, or it may just make your life difficult. That being said, let me walk you through the concepts, then give you the links to the article.
DarkAuth is designed around role-based authentication for actions. I call them "groups" in the tutorial but more often than not I consider them access roles. This means that if you are not using HABTM associations in your app, DarkAuth probably isn't for you. the exception to that is if you don't use groups at all, then it's probably quite good!
The other "feature" of DarkAuth is that you don't have to create a specific "login" URL. If auth is required by your app on a page and the current user is not authenticated then the login is automagically displayed. If the user is logged but doesn't have the correct "role" or "group" then the access denied page is shown instead.
It's quite clever really and allows you to do things like this:
- <?php
- class ExamplesController extends AppController {
- var $name = 'Examples';
- function index(){
- // This function is un-restricted.
- }
- function secret(){
- // this function is Auth secured.
- $this->DarkAuth->requiresAuth();
- }
- function roleOnly(){
- // this function require the "can_do_this" role
- $this->DarkAuth->requiresAuth("can_do_this");
- }
- function variedResult(){
- // this function does one thing is auth and another if not.
- if($this->DarkAuth->isAllowed()){
- // do something
- $this->set('some_data','User Authorised!');
- }else{
- // do something else...
- $this->set('some_data','No Auth!');
- }
- }
- }
- ?>
So anyway, the reason you're reading this. The article and source code is on this website at /darkauth-1 and also at the bakery.
Hope you like it.

Comments:
Sorry, comments are closed.