Jump to content

Redirect to another controller with sessions


Iluvatar+

Recommended Posts

I am have build an auth controller in cakephp but for some reason when i try and redirect the once the user is authenticated it only allows access actions within that controller. I have tried to redirect it to another controller which which is what i want the user to authenticate them selfs for, but all i get in a blank screen. :S.

 

<?php
class UsersController extends AppController
{
    var $name = "Users";
var $layout = "login";
    var $helpers = array('Html', 'Form');
    
    function index()
    {

    }
    
    function beforeFilter()
    {
        $this->__validateLoginStatus();

    }
    
    function login()
    {
        if(empty($this->data) == false)
        {
            if(($user = $this->User->validateLogin($this->data['User'])) == true)
            {
                $this->Session->write('User', $user);
                $this->Session->setFlash('You\'ve successfully logged in.');

            }
            else
            {
                $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.');
            }
        }
    } 
    
    function logout()
    {
        $this->Session->destroy('user');
        $this->Session->setFlash('You\'ve successfully logged out.');
        $this->redirect('login');
    }
        
    function __validateLoginStatus()
    {
        if($this->action != 'login' && $this->action != 'logout')
        {
            if($this->Session->check('User') == false)
            {
                $this->redirect('login');
                $this->Session->setFlash('The URL you\'ve followed requires you login.');
            }
        }
    }
    
}

?> 


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.