User/rework
This commit is contained in:
@@ -24,26 +24,40 @@ class User extends mfBaseModel {
|
||||
/**
|
||||
* Loads currently logged in user
|
||||
*/
|
||||
public function loadMe() {
|
||||
if(defined("INTERNAL_USER_ID") && is_numeric(INTERNAL_USER_ID)) {
|
||||
$this->fetch(INTERNAL_USER_ID);
|
||||
return true;
|
||||
public function loadMe($ignoreImpersonate = false): bool
|
||||
{
|
||||
if (defined("INTERNAL_USER_ID") && is_numeric(INTERNAL_USER_ID)) {
|
||||
return $this->fetch(INTERNAL_USER_ID);
|
||||
}
|
||||
|
||||
$username = $_SESSION[MFAPPNAME.'_username'] ?? null;
|
||||
if (!$username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->db->select($this->table,"*","username='$username' and active=1 LIMIT 1");
|
||||
$user = null;
|
||||
if ($this->db->num_rows($res)) {
|
||||
$user = $this->db->fetch_object($res);
|
||||
// If Impersonating, load the user that is being impersonated
|
||||
if (isset($_SESSION[MFAPPNAME.'_impersonate']) && !$ignoreImpersonate) {
|
||||
$username = $_SESSION[MFAPPNAME.'_impersonate'];
|
||||
$res = $this->db->select($this->table, "*", "username='$username' and active=1 LIMIT 1");
|
||||
if ($this->db->num_rows($res)) {
|
||||
$user = $this->db->fetch_object($res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
mfLoginController::staticLogout();
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->load($user);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!isset($_SESSION) || !is_array($_SESSION) || !array_key_exists(MFAPPNAME.'_username', $_SESSION)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$username = $_SESSION[MFAPPNAME.'_username'];
|
||||
$res = $this->db->select($this->table,"*","username='$username' LIMIT 1");
|
||||
if($this->db->num_rows($res)) {
|
||||
$data = $this->db->fetch_object($res);
|
||||
$this->load($data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function loadByUsername($username) {
|
||||
$username = $this->db->escape($username);
|
||||
if(!$username) {
|
||||
|
||||
Reference in New Issue
Block a user