0
votes

I'm new to cakePHP. I'm trying to create a login page. I was able to create a login page. I've a problem with login redirect. When I submit the login credentials, I will be redirect to a page where it contains the following text.

Sweet, "App" got Baked by CakePHP! Your tmp directory is writable. The FileEngine is being used for caching. To change the config edit APP/config/core.php Your database configuration file is present. Cake is able to connect to the database.

But, this is not correct. In my app_controller, I wrote code to redirect to different page as mentioned below:

function beforeFilter() {
    //Configure AuthComponent
    $this->Auth->authorize = 'actions';
    $this->Auth->actionPath = 'controllers/';
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->loginRedirect = array('controller' => 'patients', 'action' => 'index');
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
}

What do I need to do to redirect to /patients/index?

Regards, Balu

2

2 Answers

0
votes

Im going to quote a part of the cake book first:

loginRedirect

The AuthComponent remembers what controller/action pair you were trying to get to before you were asked to authenticate yourself by storing this value in the Session, under the Auth.redirect key. However, if this session value is not set (if you're coming to the login page from an external link, for example), then the user will be redirected to the URL specified in loginRedirect.

Saying this you may see that if you came from a page inside your program it will go there afterwards.

What you can do, you can say to the authComponent not to auto redirect and you manage this part, how? like this:

1) in beforeFilter write this

$this->Auth->autoRedirect = false;

2) in the login action in your controller something likethis

if ($this->Auth->user()) {
   $this->redirect('url');
}

url can be absolute or the cakephp array you may look it in the book, this code will execute only after the validation of the login is done... you may do as well any other thing you need like last login attempt succes or something like that

hope this works for you :)

0
votes

in config->routes.php change your first line to this....

Router::connect('/', array('controller' => 'patients', 'action' => 'index'));

api55 is right but I can see your frustration so this should be instant gratification for you.