function __construct($stdclass, $id)
 {
     foreach ($stdclass as $key => $value) {
         $this->{$key} = $value;
     }
     parent::__construct($id);
 }
示例#2
0
 /**
  * Overload saving to set the created time and to create a new token
  * when the object is saved.
  */
 public function save()
 {
     if ($this->data['id'] == 0) {
         // Set the created time, token, and hash of the user agent
         $this->data['created'] = $this->now;
         $this->data['user_agent'] = sha1(Kohana::$user_agent);
     }
     // Create a new token each time the token is saved
     $this->data['token'] = $this->create_token();
     return parent::save();
 }
示例#3
0
 public function __construct($id = NULL)
 {
     parent::__construct();
     //if user id
     if ($id != NULL and (ctype_digit($id) or is_int($id))) {
         // try and get a row with this ID
         $this->load($id);
     } else {
         if ($id != NULL and is_string($id)) {
             // try and get a row with this username/email
             $this->load($id, Kohana::config('simple_auth.unique'));
         } else {
             if ($id != NULL and is_array($id)) {
                 $data = array(Kohana::config('simple_auth.unique') => $id['username'], Kohana::config('simple_auth.password') => Simple_Auth::instance()->hash($id['password']));
                 $this->load($data);
             }
         }
     }
 }
示例#4
0
 /**
  * Log a user out.
  *
  * @param   boolean  completely destroy the session
  * @return  boolean
  */
 public function logout($destroy = FALSE)
 {
     //get user ID
     $user = $this->get_user();
     if (intval($user['id']) !== 0) {
         //delete user tokens
         Simple_Modeler::factory('auth_user_tokens')->delete_user_tokens($user['id']);
     }
     if ($destroy === TRUE) {
         // Destroy the session completely
         Session::instance()->destroy();
     } else {
         // Remove the user from the session
         $this->session->delete($this->config['session_key']);
         // Regenerate session_id
         $this->session->regenerate();
     }
     //delete cookie. tokens from db will be deleted on next login.
     cookie::delete($this->config['cookie_key']);
     // Double check
     return !$this->logged_in();
 }