blob: b16fd6e05bd6ed769053198d979e8d3c0aea4eab [file] [log] [blame]
<?php
require_once 'vendor/autoload.php';
class User
{
public $username;
public $first_name;
public $last_name;
public $organization;
public $user_hash;
public $password;
public $street;
public $zip;
public $city;
public $country;
public $email;
public $phone;
public bool $eula_signed;
public bool $privacy_policy_signed;
function __construct()
{
$this->username = "";
$this->first_name = "";
$this->last_name = "";
$this->email = "";
$this->organization = "";
$this->user_hash = "";
$this->password = "";
$this->city = "";
$this->country = "";
$this->zip = "";
$this->street = "";
$this->phone = "";
$this->eula_signed = false;
$this->privacy_policy_signed = false;
}
function __construct1(object $data)
{
foreach ($data as $key => $value) {
if (array_key_exists($key, (array) $this))
$this->{$key} = $value;
}
if (isset($data->password)) $this->set_password($data->password);
}
function init_from_object(object $data)
{
foreach ($data as $key => $value) {
if (array_key_exists($key, (array) $this))
$this->{$key} = $value;
}
if (isset($data->password)) $this->set_password($data->password);
}
function init_from_array(array $data)
{
foreach ($data as $key => $value) {
if (array_key_exists($key, (array) $this)) {
if (is_bool(gettype($this->{$key})) && is_string($value))
$this->{$key} = !empty($value);
else
$this->{$key} = $value;
}
}
if (!empty($data["password"])) $this->set_password($data["password"]);
}
function set_password(string $password)
{
include 'config.php';
if ($ENCRYPT_PASSWORDS) {
$this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
# $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
} else {
$this->user_hash = "{CLEAR}" . $password;
}
$this->password = $this->user_hash;
}
function to_string()
{
$tmp_user = $this;
$tmp_user->password = "***";
$tmp_user->user_hash = "***";
return json_encode($tmp_user);
}
function backup_in_session()
{
global $_SESSION;
foreach ($this as $key => $value) {
$_SESSION[$key] = $value;
}
}
function to_table() {
$table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
foreach ($this as $key => $value) {
if ($key != "password" && $key != "user_hash" && !empty($value)) {
if (is_bool($value)) {
if ($value) $value = "yes";
else $value = "no";
}
$value = str_replace("\r\n", "<br>", $value);
$key = str_replace("_", " ", ucfirst($key));
$table .= " <tr>
<td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
<td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
</tr>\n";
}
}
$table .= "</table>";
return $table;
}
}