1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
<?php
/**
* TfishUser class file.
*
* @copyright Simon Wilkinson 2013-2017 (https://tuskfish.biz)
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License (GPL) V2
* @author Simon Wilkinson <[email protected]>
* @version Release: 1.0
* @since 1.0
* @package user
*/
// Enable strict type declaration.
declare(strict_types=1);
if (!defined("TFISH_ROOT_PATH")) die("TFISH_ERROR_ROOT_PATH_NOT_DEFINED");
/**
* User object class.
*
* Represents a user. Since Tuskfish is a single-user system, this class will probably be deprecated
* in due course.
*
* @copyright Simon Wilkinson 2013-2017 (https://tuskfish.biz)
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License (GPL) V2
* @author Simon Wilkinson <[email protected]>
* @version Release: 1.0
* @since 1.0
* @package user
* @property int $id ID of this user
* @property string $admin_email email address of this user
* @property string $password_hash
* @property int $user_group
*/
class TfishUser
{
/** @var array $__data Array holding values of this object's properties. */
protected $__data = array(
'id',
'admin_email',
'password_hash',
'user_salt',
'user_group',
'yubikey_id',
'yubikey_id2',
'login_errors'
);
/**
* Get the value of a property.
*
* Intercepts direct calls to access an object property. This method can be overridden to impose
* processing logic to the value before returning it.
*
* @param string $property Name of property.
* @return mixed|null $property Value of property if it is set; otherwise null.
*/
public function __get(string $property)
{
$clean_property = TfishFilter::trimString($property);
if (isset($this->__data[$clean_property])) {
return $this->__data[$clean_property];
} else {
return null;
}
}
/**
* Set the value of a whitelisted property.
*
* Intercepts direct calls to set the value of an object property. This method is overridden by
* child classes to impose data type restrictions and range checks before allowing the property
* to be set. Tuskfish objects are designed not to trust other components; each conducts its
* own internal validation checks.
*
* @param string $property Name of property.
* @param mixed $value Value of property.
*/
public function __set(string $property, $value)
{
$clean_property = TfishFilter::trimString($property);
if (isset($this->__data[$clean_property])) {
switch ($clean_property) {
case "id":
if (TfishFilter::isInt($value, 1)) {
$clean_value = (int) $value;
$this->__data[$clean_property] = $clean_value;
} else {
trigger_error(TFISH_ERROR_NOT_INT, E_USER_ERROR);
}
break;
case "admin_email":
$clean_value = TfishFilter::trimString($value);
if (TfishFilter::isEmail($clean_value)) {
$this->__data[$clean_property] = $clean_value;
} else {
trigger_error(TFISH_ERROR_NOT_EMAIL, E_USER_ERROR);
}
break;
case "password_hash":
$clean_value = TfishFilter::trimString($value);
$this->__data[$clean_property] = $clean_value;
break;
case "user_salt":
$clean_value = TfishFilter::trimString($value);
$this->__data[$clean_property] = $clean_value;
break;
case "user_group":
if (TfishFilter::isInt($value, 1)) {
$this->__data[$clean_property] = (int) $value;
} else {
trigger_error(TFISH_ERROR_NOT_INT, E_USER_ERROR);
}
break;
case "yubikey_id":
case "yubikey_id2":
$clean_value = TfishFilter::trimString($value);
$this->__data[$clean_property] = $clean_value;
break;
case "login_errors":
if (TfishFilter::isInt($value, 0)) {
$this->__data[$clean_property] = (int) $value;
} else {
trigger_error(TFISH_ERROR_NOT_INT, E_USER_ERROR);
}
break;
}
} else {
trigger_error(TFISH_ERROR_NO_SUCH_PROPERTY, E_USER_ERROR);
}
}
/**
* Check if a property is set.
*
* Intercepts isset() calls to correctly read object properties. Can be overridden in child
* objects to add processing logic for specific properties.
*
* @param string $property Name of property.
* @return bool True if set otherwise false.
*/
public function __isset(string $property)
{
$clean_property = TfishFilter::trimString($property);
if (isset($this->__data[$clean_property])) {
return true;
} else {
return false;
}
}
/**
* Unsets a property.
*
* Intercepts unset() calls to correctly unset object properties. Can be overridden in child
* objects to add processing logic for specific properties.
*
* @param string $property Name of property.
* @return bool True on success, false on failure.
*/
public function __unset(string $property)
{
$clean_property = TfishFilter::trimString($property);
if (isset($this->__data[$clean_property])) {
unset($this->__data[$clean_property]);
return true;
} else {
return false;
}
}
}