Hello,

I've been trying to add a little Login module to my homepage and my
Layout. I'm using the Auth component and have the following code:

//app_controller.php:
    function beforeFilter() {
        $this->Auth->allow('display');
        $this->Auth->autoRedirect = false;
        $this->Auth->fields = array('username' => 'email', 'password'
=> 'password');
        $this->Auth->loginAction = array('admin' => false,
'controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller'=>'dashboard',
'action'=>'index');
        $this->Auth->logoutRedirect = array('admin' => false,
'controller' => 'pages', 'action' => 'home');

    }

//users_controller.php
    function login() {
                if ($this->Auth->user()) {
                        if (!empty($this->data) && 
$this->data['User']['remember_me']) {
                                $cookie = array();
                                $cookie['email'] = $this->data['User']['email'];
                                $cookie['password'] = 
$this->data['User']['password'];
                                $this->Cookie->write('Auth.User', $cookie, 
true, '+2 weeks');
                                unset($this->data['User']['remember_me']);
                        }
                         $this->redirect($this->Auth->redirect());
                }
                if(empty($this->data)) {
                        $cookie = $this->Cookie->read('Auth.User');
                        if (!is_null($cookie)) {
                                if ($this->Auth->login($cookie)) {
                                        $this->Session->del('Message.auth');
                                         
$this->redirect($this->Auth->redirect());
                                } else {
                                $this->Cookie->del('Auth.User');
                                }
                        }
                }
    }

//(pages) home.ctp  and  (users) login.ctp
                                        <?php
                                        echo $form->create('User', 
array('action' => 'login',
'style'=>'margin: 5px 0 0 18px;'));
                                        echo '<div class = 
"label">E-mail</div>';
                                        echo $form->input('email', 
array('label' => ''));
                                        echo '<div class = 
"label">Password</div>';
                                        echo $form->input('password', 
array('label' => ''));
                                        echo $form->input('remember_me', 
array('type' =>
'checkbox','label'=>'Remember Me'));
                                        echo $form->end(array
('label'=>'Login','class'=>'b2','style'=>'margin-top: 13px;'));
                                        ?>


The problem is that the Login only works when I access it directly
from /users/login, but if I try to login from the Homepage (or
anywhere else for that matter) with the exact same code, it gives me a
404 NOT FOUND error.

I've been browsing all over the Internet for a way to do this (a login
element or a login form in the layout) but no luck yet. Any idea of
what might be happening?

Thanks in advance!
Ponch

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

Reply via email to