Take the 2-minute tour ×

Sometimes I'm a bit troubled by how to do things in Cake. Therefor I would like your opinion on the following use case:

I'm building a login form that a user can also use to create an account, the user needs to provide a certain registration number and an e-mail address. After submitting I'm checking if the user already exists in the database, if not I create the user. After creation the user needs to verified by an employee of our company and the user needs to verify his/her e-mail address.

Ofcourse this is easy to code in a controller, but I'm also looking into building this logic as a CustomAuthentication class. The CustomAuthentication class then handles all the logic described above, so creates a user if a record doesn't exist and also gives usefull feedback based on whether the user has been verified by us or if he has already verified his e-mailaddress.

So would I be better off creating a lean Controller with a Custom Authentication class... or is this logic better written in the controller itself.

In general: Is there some place I can find information on best practices in using MVC frameworks... I often find myself troubled deciding where to put the code.

share|improve this question
add comment

1 Answer

I don't see a need for a custom auth class, seeing as this doesn't have a whole lot to do with authentication as it does with the registration process. Authentication is usually a one step process, where what you described here is multiple steps - register, verify, enable. Once the user logs in, that's where authentication comes in.

As far as best practices, I've just learned over time by understanding what each component (Controller, Model, View, DataSource, Component, Behavior, Helper, etc.) does. When it comes down to it, just ask if it's layout logic, business logic, or connecting logic and that should point you to the right spot (View, Model, Controller respectively). I'm sure there are plenty of resources out there that can help you, SO not excluded. As for Cake, if you have questions regarding the proper place to put things check out #cakephp in IRC. People are usually there to point you in the right direction.

share|improve this answer
I think you mean Authentication - as Authorization is everything "after" he logged in (role based access). other than that nothing to add here. but the OP already started out with the wrong name - so in the end that's the source of misunderstanding here. –  mark Apr 12 '12 at 17:16
Yes I did. Wow what a typo hah. Thanks I updated the answer. –  jeremyharris Apr 12 '12 at 17:17
I editted my OP also... In the mean time I created the Authorization class, it seems very DRY to me... but I still don't know how to determine what's best practice for specific problems. I'll check the IRC, thanks. Edit: btw, the main reason I wanted to do things another way is that for each error logging in, I had to check an array and set a seperate flash message... I basically wanted to get all those messages in one place. –  bo-oz Apr 12 '12 at 17:47
add comment

Your Answer


