/** * Create a new instance of a user. * * If the username isn't given then it will be determined from the session array. * @param integer $username The id of the user in the database. or '0' (the detauls) to get it from the session * @param boolean $populate A flag to determine if the user should be automatically populated at creation. Defaults to true * @param boolean $checkSession A flag to determine if we should check the $_SESSION for user information Defaults to true * @param boolean $log. Defaults to true which means we log the activity */ public function __construct($username = '******', $populate = true, $checkSession = true, $log = true) { if ($username == '0') { if ($checkSession && I2CE_UserAccess_Mechanism::hasSession()) { $checkSession = true; $this->username = I2CE_UserAccess_Mechanism::getSessionUserName(); } else { $checkSession = false; } } else { $this->username = $username; } $userAccess = I2CE::getUserAccess(); if (!$userAccess instanceof I2CE_UserAccess_Mechanism) { I2CE::raiseError("No user access mechanism set"); return; } $this->logged_in = false; if ($this->username == '0') { if (!$userAccess->doAutoLogin()) { return; } $t_username = $userAccess->getAutoLoginUser(); if ($t_username === false) { $t_username = '******'; } $this->username = $t_username; $this->logged_in = true; } foreach ($userAccess->getAllowedDetails() as $detail) { $this->details[$detail] = null; } if ($log) { $userAccess->logActivity($this->username, 'access'); } if ($populate) { $details = null; $role = null; $id = false; if ($checkSession) { $details = I2CE_UserAccess_Mechanism::getSessionDetails(); $role = I2CE_UserAccess_Mechanism::getSessionRole(); $id = I2CE_UserAccess_Mechanism::getSessionId(); } if (!$this->populate($details, $role, $id)) { I2CE::raiseError("Could not get user information"); return; } if ($checkSession) { $this->logged_in = true; } } }
/** * Create a new instance of a user. * * If the username isn't given then it will be determined from the session array. * @param integer $username The id of the user in the database. or '0' (the detauls) to get it from the session * @param boolean $populate A flag to determine if the user should be automatically populated at creation. Defaults to true * @param boolean $checkSession A flag to determine if we should check the $_SESSION for user information Defaults to true * @param boolean $log. Defaults to true which means we log the activity */ public function __construct($username = '******', $populate = true, $checkSession = true, $log = true) { if ($username == '0') { if ($checkSession && I2CE_UserAccess_Mechanism::hasSession()) { $checkSession = true; $this->username = I2CE_UserAccess_Mechanism::getSessionUserName(); } else { $checkSession = false; } if (!$checkSession && array_key_exists('PHP_AUTH_USER', $_SERVER) && ($basic_auth_user = $_SERVER['PHP_AUTH_USER']) && array_key_exists('PHP_AUTH_PW', $_SERVER) && ($basic_auth_pass = $_SERVER['PHP_AUTH_PW'])) { $this->login($basic_auth_user, $basic_auth_pass); } } else { $this->username = $username; } $userAccess = I2CE::getUserAccess(); if (!$userAccess instanceof I2CE_UserAccess_Mechanism) { I2CE::raiseError("No user access mechanism set"); return; } if ($log && $this->username != '0' && $userAccess->hasBeenLoggedOut($this->username)) { $msg = "This username has been logged in on another computer."; $msg = I2CE::getConfig()->setIfIsSet($msg, "/config/site/single_login_message"); $this->userMessage($msg); I2CE_UserAccess_Mechanism::unsetSession(); return; } $this->logged_in = false; if ($this->username == '0') { if (!$userAccess->doAutoLogin()) { return; } $t_username = $userAccess->getAutoLoginUser(); if ($t_username === false) { $t_username = '******'; } $this->username = $t_username; $this->logged_in = true; } foreach ($userAccess->getAllowedDetails() as $detail) { $this->details[$detail] = null; } if ($log) { $userAccess->logActivity($this->username, 'access'); } if ($populate) { $details = null; $role = null; $id = false; if ($checkSession) { $details = I2CE_UserAccess_Mechanism::getSessionDetails(); $role = I2CE_UserAccess_Mechanism::getSessionRole(); $id = I2CE_UserAccess_Mechanism::getSessionId(); } if (!$this->populate($details, $role, $id)) { I2CE::raiseError("Could not get user information"); return; } if ($checkSession) { $this->logged_in = true; } } }