I've got the above working, by doing something like this. Where
'usertype' is defined prefix like 'admin'
if($this->Auth->User('accounttype_id')==3)
{
$this->Auth->loginRedirect = array('controller' =>
'dashboard','action'=>'index','usertype'=>'1');
$this->Auth->logoutRedirect = array('controller' => 'pages','action'
=> 'home');
}
If theres a better way then please let me know
Another question though
If I want an action to be exactly the same across the user types, is
it acceptable to do something like this
usertype_view($id = null){
$this->view($id);
$this->render('view');
}
Thanks
On Dec 14, 1:11 pm, chris <[email protected]> wrote:
> Thanks for the reply, will look at your suggestion and see what I can
> use from it.
>
> Do you have a way of automatically routing a user correct address
> after logging in, based on their role?
>
> If anyone has any further suggestions let me know.
>
> Thanks
>
> On Dec 14, 12:02 pm, "Dave Maharaj" <[email protected]> wrote:
>
> > What I did was simply write my own
>
> > Configure::write('Routing.CustomRouting', array('Admin' => 'admin', 'Owner'
> > => 'manage' , 'Employee' => 'editor'));
> > simply because my routes and Roles did not match up and I hate arrays that
> > are 0,1,2 since that's means nothing. Imagine trying to remember if
> > $something[0] = $something thru the site....forget that!
>
> > Then in isAuthorized function since everyone is routed thru their own prefix
> > simply compare the prefix (manage/profile would mean Owner role) with the
> > value.
>
> > function isAuthorized() {
> > $access = false;
>
> > if ( isset ( $this->params['prefix'] ) ) {
> > $routes = Configure::read('Routing.CustomRouting');
> > $access_role = $this->Auth->User( 'role_id' );
> > $routed_role = $routes[$access_role];
> > $this_prefix = $this->params['prefix'];
>
> > if( $this->Session->valid() && $this_prefix === $routed_role ) {
>
> > //do other stuff define layouts whatever
>
> > $access = true;
>
> > }
>
> > Return $access;
>
> > }
>
> > That worked for me. Every situation is different so it might help or get you
> > started.
>
> > Dave
>
> > -----Original Message-----
> > From: chris [mailto:[email protected]]
> > Sent: December-14-10 7:32 AM
> > To: CakePHP
> > Subject: Prefix routing and different user types
>
> > Hi
>
> > I have an application that a user can login too to access certain
> > parts of the site.
>
> > I'm using the Auth component, and have added a variable to my database
> > that has different user types.
>
> > I am then using the admin prefix routing, as well as another customer
> > prefix for one of the user types. So I have views such as
>
> > /usertype/model/add
> > /admin/model/add
>
> > etc
>
> > What I want to know is what is the best way to automatically route
> > people through to these, dependant on their user type?
>
> > One thing I want to do is automatically force the user into a route at
> > the login stage. I currently define this using
>
> > $this->Auth->loginAction =
>
> > Is there a way to define different ones dependant on my user types?
>
> > Thanks
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups
> > "CakePHP" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected] For more options, visit this group
> > athttp://groups.google.com/group/cake-php?hl=en
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en