views:

597

answers:

3

Hi. I am using the registration form for different users? After a new user logs in, the registered users should redirect to an after-login page. We are using Auth component for the authentication.

How do I do this?

A: 

I'm not sure what the question is, but it sounds like you're wondering how to send a user somewhere after a successful login. If that's correct, try this:

$this->Auth->loginAction = array (
   'controller' => 'whichever_controller',
   'action'     => 'desired_action',
   'admin'      => true
);

The admin key may not be necessary if you're not accessing /admin/whichever_controller/desired_action.

Rob Wilkerson
A: 

You will have to call the login method manually from your register action.

Save the username + unhashed password in an array then call it from the method after the save like this:

$data = array('username' => 'user', 'password' => $unhashedPw);
$this->User->login($data);
Stoosh
+3  A: 

If you want the user to auto-login after registering, you can use the AuthComponent's login() method.

if ($this->User->save($this->data)) {
    $this->Auth->login($this->data);
}
Matt Huggins