0

我在蛋糕 2.7 框架上的 PHP 中有一个登录功能,它不会超过第一if条语句。条件似乎总是错误的,我真的很困惑为什么。我没有正确执行请求吗?任何帮助将不胜感激。

登录()

function login() { 

if (!empty($this->request->data) && $this->Auth->user()) {

  // Delete all old tokens
  $this->Tour->recursive = -1;
  $this->Tour->deleteAll(array('Tour.userid' => $this->Auth->user('userid')));
  // Create a new token

  $this->Tour->create();
  $this->Tour->save(array('token' => md5(rand()), 'userid' => $this->Auth->user('userid')));
  // Update login count
  $user = $this->User->read(null, $this->Auth->user('userid'));
  $user['User']['logincount']++;
  $this->User->saveField('logincount', $user['User']['logincount']);
  // Update last login time
  $this->User->saveField('lastlogin', date('Y-m-d h:m:s'));
  echo 'doesnt work';
  if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            echo 'authLogin';
            return $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
        }

}
}
}
4

1 回答 1

3

that will not make it past the first if statement.

Of course it won't because of the && $this->Auth->user() condition you have. Since user is not logged in $this->Auth->user() will return null and it won't enter the if block.

于 2015-10-08T14:50:38.830 回答