diff options
| -rw-r--r-- | it_user.class | 55 |
1 files changed, 16 insertions, 39 deletions
diff --git a/it_user.class b/it_user.class index 7949861..0682f27 100644 --- a/it_user.class +++ b/it_user.class @@ -46,8 +46,6 @@ class it_user extends it_dbi var $secret; var $urlauthenticationcode = 'uac'; # Name of UAC url parameter - var $uid; - var $username; /* * Used by login(), contains unvalidated user data to give overloading @@ -78,23 +76,6 @@ function __construct($p = array()) $this->status = _IT_USER_STATUS_INVALID; } -/** - * Minimalistic post processing to fill uid and username fields after calling read() on it_user - */ -function read($id = null) -{ - $result = parent::read($id); - - # If read succeeded, get UID. This is necessary because it's only set if a cookie is present (i.e. in web-context) - if (isset($this->{$this->p['uid_field']})) - $this->uid = $this->{$this->p['uid_field']}; - - # Get username from database field (shortcut) - $this->username = $this->{$this->p['username_field']}; - - return $result; -} - function set_session_cookie_name($sessioncookiename) { @@ -160,20 +141,20 @@ function get_status() { $this->status = IT_USER_STATUS_SESSION; $this->_set_uid($this->session->get_uid()); - $this->read($this->uid); + $this->read($this->get_uid()); } - else if (isset($_COOKIE[$this->p['uidcookiename']]) && ($this->uid = substr($_COOKIE[$this->p['uidcookiename']], 0, 32))) + else if (isset($_COOKIE[$this->p['uidcookiename']]) && ($uid = substr($_COOKIE[$this->p['uidcookiename']], 0, 32))) { - @$this->read($this->uid); - $this->status = $this->username ? IT_USER_STATUS_KNOWN : IT_USER_STATUS_ANONYMOUS; + $this->_set_uid($uid); + $this->{$this->p['username_field']} = ""; + @$this->read($uid); + $this->status = $this->get_username() ? IT_USER_STATUS_KNOWN : IT_USER_STATUS_ANONYMOUS; } else { $this->status = IT_USER_STATUS_UNKNOWN; - $this->username = ''; - - if ($this->p['uid_field']) - $this->_set_uid($this->create_uid()); + $this->_set_uid($this->create_uid()); + $this->{$this->p['username_field']} = ""; } } @@ -183,19 +164,19 @@ function get_status() function get_username() { - return $this->username; + return $this->{$this->p['username_field']}; } function get_uid() { - return $this->uid; + return $this->{$this->p['uid_field']}; } function _set_uid($uid) { - $this->uid = $uid; + $this->{$this->p['uid_field']} = $uid; if (!isset($_COOKIE[$this->p['uidcookiename']]) || ($_COOKIE[$this->p['uidcookiename']] != $uid)) { @@ -240,7 +221,7 @@ function login($username, $password, $ignorepassword = false, $withsession = tru } if ($result && ($this->session->get_uid() == $this->workrecord->{$this->p['uid_field']})) - $this->username = $this->workrecord->{$this->p['username_field']}; + $this->{$this->p['username_field']} = $this->workrecord->{$this->p['username_field']}; $this->status = $result ? _IT_USER_STATUS_INVALID : IT_USER_STATUS_FAILED; @@ -266,7 +247,7 @@ function purge() { $this->status = _IT_USER_STATUS_INVALID; $this->_set_uid($this->create_uid()); - $this->username = ""; + $this->{$this->p['username_field']} = ""; $this->session->purge(); } @@ -279,18 +260,14 @@ function purge() function create($tags) { # Make sure UID is always set in database records - if ($this->p['uid_field']) + if (!$tags[$this->p['uid_field']]) { - if (!$this->uid) + if (!$this->get_uid()) $this->_set_uid($this->create_uid()); - $tags[$this->p['uid_field']] = $this->uid; + $tags[$this->p['uid_field']] = $this->get_uid(); } - # Create dummy but unique username if none given - if (!$tags[$this->p['username_field']] && !$this->{$this->p['username_field']}) - $tags[$this->p['username_field']] = $this->uid; - if ($result = $this->insert($tags)) $this->_set_uid($this->{$this->p['uid_field']}); |