faça o método de login assim:
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Usuário ou senha inválidos.'));
}
}
}
Em 19 de abril de 2013 17:25, Anderson Moraes <[email protected]>escreveu:
> Boa tarde pessoal.
>
> Eu estou começando agora no CakePHP e estou fazendo uma área restrita, o
> que tá acontecendo é o seguinte, quando eu entro em uma página onde é
> necessário estar logado, eu sou direcionado para tela de login e é exibido
> a seguinte mensagem "Área Restrita", mas o problema é que junto está
> aparecendo a mensagem "Usuário ou senha inválidos", sendo que essa mensagem
> deveria aparecer somente após a autenticação.
> Se eu entrar direto na tela de login ele me exibe somente a mensagem
> "Usuário ou senha inválidos", neste caso não deveria aparecer senha nenhuma.
>
> Alguém aqui já passou por isso e pode me ajudar???
>
> Seguem meu códigos:
>
>
> *AppController.php*
>
> <?php
>
> App::uses('Controller', 'Controller');
>
> class AppController extends Controller {
>
> public $components = array(
> //KitDebug
> 'DebugKit.Toolbar',
> 'Auth',
> 'Email',
> 'Session',
> );
>
> public $helpers = array('Html', 'Form', 'Session');
>
> public function beforeFilter()
> {
> $this->Auth->allow('display');
> $this->Auth->authError = 'Área restrita, efetue o login de acesso.';
> $this->Auth->loginError = 'Usuário ou senha inválidos.';
> }
>
> }
>
>
>
> *User.php*
>
> <?php
>
> App::uses('AuthComponent', 'Controller/Component');
>
> class User extends AppModel {
>
> public $name = 'User';
>
> public function beforeSave($options = array()) {
> if (!empty($this->data['User']['password'])) {
> $this->data['User']['password'] =
> AuthComponent::password($this->data['User']['password']);
> }
> return true;
> }
> }
>
> ?>
>
>
> *UsersController.php*
>
> <?php
>
> class UsersController extends AppController {
>
> public $name = 'Users';
>
> public function beforeFilter() {
> parent::beforeFilter();
> }
>
> public function login(){
> if($this->Auth->login()){
> $this->redirect($this->Auth->redirect());
> }else{
> $this->Session->setFlash(__('Usuário ou senha inválidos.'));
> }
> }
>
> public function logout(){
> $this->redirect($this->Auth->logout());
> }
>
> public function index(){
>
> }
>
> public function getUsers(){
> $users = $this->User->find('list', array('fields' => array('id')));
> $this->set(compact('$users'));
> }
> }
>
> ?>
>
>
>
> *login.ctp*
>
> <h2><?php echo __('Login'); ?></h2>
> <?php echo $this->Session->flash('auth'); ?>
> <?php echo $this->Form->create('User');?>
> <fieldset>
> <?php
> echo $this->Form->input('username');
> echo $this->Form->input('password');
> ?>
> </fieldset>
> <?php echo $this->Form->end('Entrar');?>
>
> *
> Desde já muito obrigado!!!*
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
*Vitor Pacheco*
*Skype: vitor.pacheco.costa
Msn: [email protected]*
*GTalk: [email protected]**
**Cel.: 71 8626-7909
Tel.: 71 3378-5778 /** 71 3287-3475*
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.