Auth未登录(CakePHP 2.7.5)

时间:2015-10-06 19:53:04

标签: php cakephp authentication login

我有一个CakePHP应用程序,我试图从1.3升级到2.7.5我可以点击登录页面但是当我去登录时,它没有做任何事情,没有错误,只是基本上刷新页面。我真的很困惑,为什么会发生这种情况,并且非常感谢我能得到的任何帮助。我发布了另一个关于此的问题,但删除了它,因为它没有提供足够的代码来解决问题。我已经包含了AppController以及下面的Users控件。

AppController.php

?php

class AppController extends Controller {

  var $components = array('Auth', 'Session', 'RequestHandler');
  var $uses = array('Tour');

  function beforeFilter() {
    $this->setLayout();
    $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'find_home');
    $this->Auth->autoRedirect = false;
    if ($this->Session->check('Auth.User.userid')) {
      $tour = $this->Tour->findByUserid($this->Session->read('Auth.User.userid'));
      $user = $this->Auth->user();
      $tour = $this->Tour->findByUserid($user['User']['userid']);
      $user['Tour'] = $tour['Tour'];
      $this->set('user', $user);
    }else if (isset($_GET['token'])) {
      $tour = $this->Tour->read(null, $_GET['token']);
      if ($tour) {
        $tour['Tour']['sessionmodified'] = date('Y-m-d H:i:s');
        $this->Tour->save($tour);
        $this->set('user', $tour);
      }
    }
  }

  private function setLayout() {
    if (array_key_exists('prefix', $this->params)) {
      if ($this->params['prefix'] == 'admin') {
        $this->layout = 'admin';
      }else if ($this->params['prefix'] == 'teacher') {
        $this->layout = 'teacher';
      }
    }
  }

}

?>

UserController.php

 function login() { 
    if (!empty($this->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'));
      $this->redirect($this->find_home());
    }
  }

  function logout() { 
    if (!empty($this->data) && $this->Auth->user()) {
      // Delete any tours
      $this->Tour->recursive = -1;
      $this->Tour->deleteAll(array('Tour.userid' => $this->Auth->user('userid')));
    }
    $this->redirect($this->Auth->logout());
  }

  function index() {
    $this->layout = false;
    $this->autoRender = false;
    Configure::write('debug', 0);
    ini_set('soap.wsdl_cache_enabled', '0');
    $server = new SoapServer('http://' . $_SERVER['HTTP_HOST'] . $this->webroot . 'users/wsdl');
    $server->setClass('User');
    $server->handle();
  }

0 个答案:

没有答案