0

我在系统中创建了一个登录,激活的用户可以登录,但尚未激活帐户的用户将无法登录。问题是当用户尝试使用已停用的帐户登录时没有输出闪烁消息,所以用户不会知道为什么页面在登录页面上不断刷新。

这是我的登录功能

if ($this->request->is('post')){
    if ($this->request->data['User']['password'] == 'qazwsx'){
    if ($this->Auth->login()){
    $username = $this->request->data['User']['username'];
     if (0 === $this->User->find('count',array('conditions'=>array('activated'=>1,'username'=> $username)))) {
         $this->Session->setFlash('Sorry, your account is not validated yet.');
         $this->redirect($this->referer());
    }

        $this->Auth->user('id');
        $this->redirect($this->Auth->redirect('eboxs/home')); 
        }   
    } 
    else {

        $this->Session->setFlash('Username or password is incorrect');
    }
    }else{
    $this->Session->setFlash('Welcome, please login');
    }


}

到目前为止,我还没有将我的观点包含在我不必打电话给他们的闪信中

4

1 回答 1

0

你在那里做的奇怪的身份验证方式。

就像你已经在评论中被告知的那样,检查,无论用户被重定向到哪里($this->redirect),都有一个

<?php echo $this->Session->flash(); ?>

在那个观点中。

同样使用该方法,用户无论如何都会登录。您必须再次手动注销该用户,然后再向他显示 Flash 消息/重定向他。

你也可以只写:

<?php
  ...
  $this->Auth->scope = array('User.activated' => 1);

  if ($this->Auth->login()) {
    // logged-in logic
  } else {
    // not logged-in logic
  }
?>

这将为您节省一些代码行。

于 2012-05-24T18:03:41.140 回答