Marc Kupietz | d871d88 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 1 | <?php |
| 2 | require_once 'vendor/autoload.php'; |
| 3 | |
| 4 | class User |
| 5 | { |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 6 | public $username; |
| 7 | public $first_name; |
| 8 | public $last_name; |
| 9 | public $organization; |
| 10 | public $user_hash; |
| 11 | public $password; |
| 12 | public $street; |
| 13 | public $zip; |
| 14 | public $city; |
| 15 | public $country; |
| 16 | public $email; |
| 17 | public $phone; |
| 18 | public bool $eula_signed; |
| 19 | public bool $privacy_policy_signed; |
| 20 | |
| 21 | function __construct() |
| 22 | { |
| 23 | $this->username = ""; |
| 24 | $this->first_name = ""; |
| 25 | $this->last_name = ""; |
| 26 | $this->email = ""; |
| 27 | $this->organization = ""; |
| 28 | $this->user_hash = ""; |
| 29 | $this->password = ""; |
| 30 | $this->city = ""; |
| 31 | $this->country = ""; |
| 32 | $this->zip = ""; |
| 33 | $this->street = ""; |
| 34 | $this->phone = ""; |
| 35 | $this->eula_signed = false; |
| 36 | $this->privacy_policy_signed = false; |
| 37 | } |
| 38 | |
| 39 | function __construct1(object $data) |
| 40 | { |
| 41 | foreach ($data as $key => $value) { |
| 42 | if (array_key_exists($key, (array) $this)) |
| 43 | $this->{$key} = $value; |
Marc Kupietz | a57befa | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 44 | } |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 45 | if (isset($data->password)) $this->set_password($data->password); |
| 46 | } |
Marc Kupietz | d871d88 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 47 | |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 48 | function init_from_object(object $data) |
| 49 | { |
| 50 | foreach ($data as $key => $value) { |
| 51 | if (array_key_exists($key, (array) $this)) |
| 52 | $this->{$key} = $value; |
Marc Kupietz | a57befa | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 53 | } |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 54 | if (isset($data->password)) $this->set_password($data->password); |
| 55 | } |
Marc Kupietz | a57befa | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 56 | |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 57 | function init_from_array(array $data) |
| 58 | { |
| 59 | foreach ($data as $key => $value) { |
| 60 | if (array_key_exists($key, (array) $this)) { |
| 61 | if (is_bool(gettype($this->{$key})) && is_string($value)) |
| 62 | $this->{$key} = !empty($value); |
| 63 | else |
| 64 | $this->{$key} = $value; |
| 65 | } |
| 66 | } |
| 67 | if (!empty($data["password"])) $this->set_password($data["password"]); |
| 68 | } |
| 69 | |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 70 | |
| 71 | function set_password(string $password) |
| 72 | { |
| 73 | include 'config.php'; |
| 74 | if ($ENCRYPT_PASSWORDS) { |
| 75 | $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$'); |
| 76 | # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true)); |
| 77 | } else { |
| 78 | $this->user_hash = "{CLEAR}" . $password; |
| 79 | } |
| 80 | $this->password = $this->user_hash; |
| 81 | } |
| 82 | |
| 83 | function to_string() |
| 84 | { |
| 85 | $tmp_user = $this; |
| 86 | $tmp_user->password = "***"; |
| 87 | $tmp_user->user_hash = "***"; |
| 88 | return json_encode($tmp_user); |
| 89 | } |
| 90 | |
| 91 | function backup_in_session() |
| 92 | { |
| 93 | global $_SESSION; |
| 94 | foreach ($this as $key => $value) { |
| 95 | $_SESSION[$key] = $value; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | function to_table() { |
| 100 | $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>"; |
| 101 | foreach ($this as $key => $value) { |
| 102 | if ($key != "password" && $key != "user_hash" && !empty($value)) { |
| 103 | if (is_bool($value)) { |
| 104 | if ($value) $value = "yes"; |
| 105 | else $value = "no"; |
Marc Kupietz | d871d88 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 106 | } |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 107 | $value = str_replace("\r\n", "<br>", $value); |
| 108 | $key = str_replace("_", " ", ucfirst($key)); |
| 109 | $table .= " <tr> |
| 110 | <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td> |
| 111 | <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td> |
| 112 | </tr>\n"; |
| 113 | } |
Marc Kupietz | d871d88 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 114 | } |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 115 | $table .= "</table>"; |
| 116 | return $table; |
| 117 | } |
| 118 | } |