case someone came across the same problem.
After WEEKS of trying to figure it out, I found the solution by
accident. I accidentally commented the $components variable in my
users_controller.php file and it suddenly started working.
I started removing components to narrow down the problem and realized
that, for some reason, the Security component was being the cause of
these problems. Without it, after submitting I got access to the
controller's actions, including login, without a single issue.
I have no idea if this is a bug or an expected behavior, if someone
knows I would greatly appreciate if you told me.
Best,
P.
On Jan 5, 1:58 am, Ponch316 <ponch...@gmail.com> wrote:
> 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment