tags:

views:

167

answers:

2

hi to all i am using cakephp framework for my project. but problem is that in my project there are four users like admin,user,employer,bla bla.if all are simultaneously login than how can i authenticate them to right access. so plz help me.....

thanks in advance

+1  A: 

You'll want to use the Auth component. Have a look on the manual page, http://book.cakephp.org/view/172/Authentication

Then, what I tend to use is in my Users table, I'll add a column, permissions or similar, and then add in the user type to this column.

Then you can use the isAuthorized() function in your app_controller.php to check the levels for various controller actions.

There are lots of possible ways of achieving this, you could even use the ACL if you wanted.

DavidYell
thanks for this
Praveen kalal
A: 

By default CakePHP uses a model like User fro Auth component. You can use this model for one type of users, and different Models for rest of the user types... This way all types of users can login to your site simultaneously, from a single machine. If you don't do this, only one type of users can login at a time.

Muhammad Yasir
thanks but can u give a demo of this
Praveen kalal
Sorry I meant 'sessionKey', not 'model' in above comment.Demo? nope I can't. I don't know your level of understanding of Cake but you need to learn about Auth component from the link already provided. After that do this in beforeFilter() of AppControllerif($user_type=='admin'){ $this->Auth->loginRedirect = array('controller' => 'admin_after_login', 'action' => 'index', 'admin'=>true); $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'logout', 'admin'=>true); $this->Auth->sessionKey = 'Admin'; $this->layout = "admin";}See sessionKey above? its important.
Muhammad Yasir