Jump to content

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.');
            }
        }
    }
    
}

?> 


This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.