summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2025-11-15 11:25:26 +0100
committerChristian Schneider2025-11-15 11:25:26 +0100
commit45ed8e5d57b21fff54bd2a694318779da6258e97 (patch)
tree641e01daf7ad1310f59fc64d55f267c227285ae8
parentf36bfa88dce8749046bce32d9ea4235409c8a23f (diff)
downloaditools-master.tar.gz
itools-master.tar.bz2
itools-master.zip
Revert "fix get_uid() and get_username() with select() and iterate(), remove deprecated $uid and $username, don't create records with username=uid if no username is supplied." as is causes memory problems with logn serviceHEADmaster
This reverts commit f36bfa88dce8749046bce32d9ea4235409c8a23f.
-rw-r--r--it_user.class55
1 files changed, 39 insertions, 16 deletions
diff --git a/it_user.class b/it_user.class
index 0682f27..7949861 100644
--- a/it_user.class
+++ b/it_user.class
@@ -46,6 +46,8 @@ 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
@@ -76,6 +78,23 @@ 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)
{
@@ -141,20 +160,20 @@ function get_status()
{
$this->status = IT_USER_STATUS_SESSION;
$this->_set_uid($this->session->get_uid());
- $this->read($this->get_uid());
+ $this->read($this->uid);
}
- else if (isset($_COOKIE[$this->p['uidcookiename']]) && ($uid = substr($_COOKIE[$this->p['uidcookiename']], 0, 32)))
+ else if (isset($_COOKIE[$this->p['uidcookiename']]) && ($this->uid = substr($_COOKIE[$this->p['uidcookiename']], 0, 32)))
{
- $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;
+ @$this->read($this->uid);
+ $this->status = $this->username ? IT_USER_STATUS_KNOWN : IT_USER_STATUS_ANONYMOUS;
}
else
{
$this->status = IT_USER_STATUS_UNKNOWN;
- $this->_set_uid($this->create_uid());
- $this->{$this->p['username_field']} = "";
+ $this->username = '';
+
+ if ($this->p['uid_field'])
+ $this->_set_uid($this->create_uid());
}
}
@@ -164,19 +183,19 @@ function get_status()
function get_username()
{
- return $this->{$this->p['username_field']};
+ return $this->username;
}
function get_uid()
{
- return $this->{$this->p['uid_field']};
+ return $this->uid;
}
function _set_uid($uid)
{
- $this->{$this->p['uid_field']} = $uid;
+ $this->uid = $uid;
if (!isset($_COOKIE[$this->p['uidcookiename']]) || ($_COOKIE[$this->p['uidcookiename']] != $uid))
{
@@ -221,7 +240,7 @@ function login($username, $password, $ignorepassword = false, $withsession = tru
}
if ($result && ($this->session->get_uid() == $this->workrecord->{$this->p['uid_field']}))
- $this->{$this->p['username_field']} = $this->workrecord->{$this->p['username_field']};
+ $this->username = $this->workrecord->{$this->p['username_field']};
$this->status = $result ? _IT_USER_STATUS_INVALID : IT_USER_STATUS_FAILED;
@@ -247,7 +266,7 @@ function purge()
{
$this->status = _IT_USER_STATUS_INVALID;
$this->_set_uid($this->create_uid());
- $this->{$this->p['username_field']} = "";
+ $this->username = "";
$this->session->purge();
}
@@ -260,14 +279,18 @@ function purge()
function create($tags)
{
# Make sure UID is always set in database records
- if (!$tags[$this->p['uid_field']])
+ if ($this->p['uid_field'])
{
- if (!$this->get_uid())
+ if (!$this->uid)
$this->_set_uid($this->create_uid());
- $tags[$this->p['uid_field']] = $this->get_uid();
+ $tags[$this->p['uid_field']] = $this->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']});