OpenCart

Класс User { ... }

Название свойства Описание
User::$user_id private mixed $user_id
User::$username private mixed $username
User::$permission private mixed $permission = array();
Тип Возвр. Описание
public mixed __construct ( $registry )
Исходный код метода:
$this->db = $registry->get('db');
$this->request = $registry->get('request');
$this->session = $registry->get('session');

if (isset($this->session->data['user_id'])) {
	$user_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user WHERE user_id = '" . (int)$this->session->data['user_id'] . "' AND status = '1'");

	if ($user_query->num_rows) {
		$this->user_id = $user_query->row['user_id'];
		$this->username = $user_query->row['username'];

		$this->db->query("UPDATE " . DB_PREFIX . "user SET ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE user_id = '" . (int)$this->session->data['user_id'] . "'");

		$user_group_query = $this->db->query("SELECT permission FROM " . DB_PREFIX . "user_group WHERE user_group_id = '" . (int)$user_query->row['user_group_id'] . "'");

		$permissions = unserialize($user_group_query->row['permission']);

		if (is_array($permissions)) {
			foreach ($permissions as $key => $value) {
				$this->permission[$key] = $value;
			}
		}
	} else {
		$this->logout();
	}
}
public boolean login ( string $username, string $password )
Исходный код метода:
$user_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user WHERE username = '" . $this->db->escape($username) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1'");

if ($user_query->num_rows) {
	$this->session->data['user_id'] = $user_query->row['user_id'];

	$this->user_id = $user_query->row['user_id'];
	$this->username = $user_query->row['username'];			

	$user_group_query = $this->db->query("SELECT permission FROM " . DB_PREFIX . "user_group WHERE user_group_id = '" . (int)$user_query->row['user_group_id'] . "'");

	$permissions = unserialize($user_group_query->row['permission']);

	if (is_array($permissions)) {
		foreach ($permissions as $key => $value) {
			$this->permission[$key] = $value;
		}
	}

	return true;
} else {
	return false;
}
public void logout ( )
Исходный код метода:
unset($this->session->data['user_id']);

$this->user_id = '';
$this->username = '';

session_destroy();
public mixed hasPermission ( $key, $value )
Исходный код метода:
if (isset($this->permission[$key])) {
	return in_array($value, $this->permission[$key]);
} else {
	return false;
}
public int|null isLogged ( )
Исходный код метода:
return $this->user_id;
public int|null getId ( )
Исходный код метода:
return $this->user_id;
public string|null getUserName ( )
Исходный код метода:
return $this->username;

Связанные классы:

Название класса Роль
class DB { ... } Компонент Db используется в данном классе
class Request { ... } Компонент Request используется в данном классе
class Session { ... } Компонент Session используется в данном классе

Комментарии