2016-10-22 114 views
0

我已经继承了一个项目,它使用Kohana MVC框架,它是Kohan_auth类来注册某个人。提交注册时,它会向下面的课程提交表格帖子。我没有看到 - >寄存器在哪里使用,或者是什么意思,或者如何调试或解决这个问题。请帮忙。Kohana PHP框架Kohan_auth不能调试或使用

Auth::instance()->register($_POST, TRUE); 

不输入数据,只是重定向回注册页面,没有错误消息。我如何调试这个,单元测试也不能正常工作,因为它们需要较老的phpunit版本。

验证::实例()似乎去这个代码

* @package Useradmin/Auth 
* @author  Gabriel R. Giannattasio 
*/ 
abstract class Useradmin_Auth extends Kohana_Auth { 

/** 
* Singleton pattern 
* 
* @return Auth 
*/ 
public static function instance() 
{ 

    if (! isset(Auth::$_instance)) 
    { 

     // Load the configuration for this type 
     $config = Kohana::$config->load('auth'); 

     if (! $type = $config->get('driver')) 
     { 
      $type = 'file'; 
     } 

     // Set the session class name 
     $class = 'Auth_'.ucfirst($type); 

     $config->set("useradmin", Kohana::$config->load('useradmin.auth')); 

     // Create a new session instance 
     Auth::$_instance = new $class($config); 
    } 

    return Auth::$_instance;    
} 
} 

延伸这个

abstract class Kohana_Auth { 

// Auth instances 
protected static $_instance; 

/** 
* Singleton pattern 
* 
* @return Auth 
*/ 
public static function instance() 
{ 
    if (! isset(Auth::$_instance)) 
    { 
     // Load the configuration for this type 
     $config = Kohana::$config->load('auth'); 

     if (! $type = $config->get('driver')) 
     { 
      $type = 'file'; 
     } 

     // Set the session class name 
     $class = 'Auth_'.ucfirst($type); 

     // Create a new session instance 
     Auth::$_instance = new $class($config); 
    } 

    return Auth::$_instance; 
} 

protected $_session; 
protected $_config; 

/** 
* Loads Session and configuration options. 
* 
* @return void 
*/ 
public function __construct($config = array()) 
{ 
    // Save the config in the object 
    $this->_config = $config; 

    $this->_session = Session::instance($this->_config['session_type']); 
} 

abstract protected function _login($username, $password, $remember); 
abstract public function password($username); 
abstract public function check_password($password); 

/** 
* Gets the currently logged in user from the session. 
* Returns NULL if no user is currently logged in. 
* 
* @return mixed 
*/ 
public function get_user($default = NULL) 
{ 
    return $this->_session->get($this->_config['session_key'], $default); 
} 

/** 
* Attempt to log in a user by using an ORM object and plain-text password. 
* 
* @param string username to log in 
* @param string password to check against 
* @param boolean enable autologin 
* @return boolean 
*/ 
public function login($username, $password, $remember = FALSE) 
{ 
    if (empty($password)) 
     return FALSE; 

    return $this->_login($username, $password, $remember); 
} 

/** 
* Log out a user by removing the related session variables. 
* 
* @param boolean completely destroy the session 
* @param boolean remove all tokens for user 
* @return boolean 
*/ 
public function logout($destroy = FALSE, $logout_all = FALSE) 
{ 
    if ($destroy === TRUE) 
    { 
     // Destroy the session completely 
     $this->_session->destroy(); 
    } 
    else 
    { 
     // Remove the user from the session 
     $this->_session->delete($this->_config['session_key']); 

     // Regenerate session_id 
     $this->_session->regenerate(); 
    } 

    // Double check 
    return ! $this->logged_in(); 
} 

/** 
* Check if there is an active session. Optionally allows checking for a 
* specific role. 
* 
* @param string role name 
* @return mixed 
*/ 
public function logged_in($role = NULL) 
{ 
    return ($this->get_user() !== NULL); 
} 

/** 
* Creates a hashed hmac password from a plaintext password. This 
* method is deprecated, [Auth::hash] should be used instead. 
* 
* @deprecated 
* @param string plaintext password 
*/ 
public function hash_password($password) 
{ 
    return $this->hash($password); 
} 

/** 
* Perform a hmac hash, using the configured method. 
* 
* @param string string to hash 
* @return string 
*/ 
public function hash($str) 
{ 
    if (! $this->_config['hash_key']) 
     throw new Kohana_Exception('A valid hash key must be set in your auth config.'); 

    return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']); 
} 

protected function complete_login($user) 
{ 
    // Regenerate session_id 
    $this->_session->regenerate(); 

    // Store username in session 
    $this->_session->set($this->_config['session_key'], $user); 

    return TRUE; 
} 
} // End Auth 

回答

0

application/bootstrap.phpphp.ini和使用启用日志记录:

Kohana::$log->add(Log::MESSAGE, $msg); 

Kohana::$log->add(Log::MESSAGE, Kohana_Exception::text($e), Array(),Array('exception'=>$e)); 

看到Log::MESSAGE

BTW:把我的日志类:

<?php defined('SYSPATH') OR die('No direct script access.'); 

class Log extends Kohana_Log { 

    public function add($level, $message, array $values = NULL, array $additional = NULL){ 


     if(strpos($message,'~') == FALSE) { 
      $message .= ' ~ '; 
     } 

     if(!isset($_SERVER['REQUEST_METHOD'])) 
      $message .= " !!! TASK"; 
      else 
      $message .= " !!! ($_SERVER[REQUEST_METHOD])//$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
     $message = strtr($message,"\r\n\t",' '); 
     if(count($_POST) > 0){ 
      if(isset($_POST['csrf'])) 
       unset($_POST['csrf']); 
      if(isset($_POST['f_pass'])) 
       unset($_POST['f_pass']); 
      if(isset($_POST['password'])) 
       $_POST['password'] = 'strlen() = '.strlen($_POST['password']); 
      if(isset($_POST['password2'])) 
       $_POST['password2'] = 'strlen() = '.strlen($_POST['password2']).', pass==pass2: '.($_POST['password2'] == $_POST['password']?'tak':'nie'); 
      $message .= '??'.http_build_query($_POST); 
     } 

     if (isset($additional['exception'])){ 
      if($additional['exception'] instanceof HTTP_Exception_301) 
       return false; 
      if($additional['exception'] instanceof HTTP_Exception_302) 
       return false; 
      if($additional['exception'] instanceof ORM_Validation_Exception){ 
       $message .= "\n".print_r($additional['exception']->errors('models'),TRUE)."\n"; 
      } 
      if($additional['exception'] instanceof GuzzleHttp\Exception\RequestException) { 
       parent::add(self::DEBUG, 'HTTP request error [ 1 ]: :url'."\r\n".':body',[':url'=>$additional['exception']->getRequest()->getUrl(), ':body'=>$additional['exception']->getRequest()->getBody()]); 
      } 
      if($additional['exception'] instanceof GuzzleHttp\Exception\BadResponseException) { 
       $_body = $additional['exception']->getResponse()->getBody(); 
        parent::add(self::DEBUG, 'HTTP reponse error [ 2 ]: :err', [':err'=> $_body]); 
      } 
     } 

     return parent::add($level, $message, $values, $additional); 
    } 

    public function add_exception($e, $error_level = Log::ERROR){ 
     return $this->add($error_level, Kohana_Exception::text($e), Array(),Array('exception'=>$e)); 
    } 
    public static function catch_ex($ex, $error_level = Log::ERROR){ 
     return Kohana::$log->add_exception($ex, $error_level); 
    } 

    public static function msg($msg, $error_level = Log::ERROR) { 
     return Kohana::$log->add($error_level, $msg); 
    } 
}