Wednesday, May 23, 2012

forwarding user to dashboard after login by prefix

Hi 
i have prefixes like "admin", "student"  
and i need to use prefixed dashboards (/admin/users/dashboard, /student/users/dashboard)
here my working code

AppController.php

function beforeFilter() {
$this->__checkAuth();
$this->layout = $this->__setLayout();
}

function __checkAuth() {
        $this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers'));
        $this->Auth->loginAction = '/users/login';
        $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = '/users/dashboard';
        $this->Auth->redirect = false;

       $loggeduser = $this->User->findById($this->Auth->user('id'));
        $this->Session->write('loggeduser', $loggeduser);

}


UsersController.php

public function dashboard() {
$this->layout = 'user';

$prefixes = Configure::read('Routing.prefixes');
$loggeduser = $this->Session->read('loggeduser');
if (in_array($loggeduser['Group']['name'], $prefixes)) {
$this->redirect('/'.$loggeduser['Group']['name'].'/users/dashboard');
}
}


is it ok? or you suggest to use another logic

thanks in advance
Baurzhan

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: