tags:

views:

103

answers:

3

i use auth componnet in my cakephp project

I add type field into users Mysql table

that enum type: admin, client

i need auth component to redirect admin's to CP page, and client to their profile page and only can access one conttroller..

ofcourse without using ACL or any others related

+1  A: 

I'd recommend taking advantage of the isAuthorized() function that you can add in the controller, or the model. Set the AuthComponent::authorize = {'controller'|'model'} to choose which you want to use.

Then you write an isAuthorized() function in the model|controller that returns t/f on auth/not auth for each action. You can do some row-level checking as well, if you'd like.

Now, if instead you just wanted to redirect an admin to their correct pages on login/etc, you can add code to the beforeFilter() method (either in a specific controller, or in app_controller.php). In that, just check to see if the admin value set by the app is the same as the user's admin value (which will be stored by AuthComponent in the Session data, accessible by $this->Auth->User()). Then route appropriately to the admin/non admin areas.

Travis Leleu
A: 

isAuthorized() is the best choice. i would recommend to separate the users from their groups in the database, so User habtm Group... but It is not a problem if user belongs to one and only one group I do not recommend ACL for non record-level-based permissions system

Robust Solution
yes, I need only a simple auth only. Thank you.......
assaqqaf
A: 

Just something to pay attention to, but unless something has changed recently CakePHP does not support ENUM column types.

Your best bet is a Group model ( groups mysql table ) and a group_id field on the users table. Then you can $hasOne = array( 'Group' ); in your User model.

From there you can follow any one of a HUGE number of group access control tutorials for the Auth Component via an easy google search for "CakePHP Auth User Group"

Abba Bryant