Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 1 | <?php |
| 2 | require_once 'vendor/autoload.php'; |
Marc Kupietz | baf8d91 | 2023-03-15 09:13:03 +0100 | [diff] [blame] | 3 | include_once 'utils.php'; |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 4 | |
| 5 | class User |
| 6 | { |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 7 | public $id; |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 8 | public $username; |
| 9 | public $first_name; |
| 10 | public $last_name; |
| 11 | public $organization; |
| 12 | public $user_hash; |
| 13 | public $password; |
| 14 | public $street; |
| 15 | public $zip; |
| 16 | public $city; |
| 17 | public $country; |
| 18 | public $email; |
| 19 | public $phone; |
| 20 | public bool $eula_signed; |
| 21 | public bool $privacy_policy_signed; |
Marc Kupietz | cdf2957 | 2023-03-09 08:14:12 +0100 | [diff] [blame] | 22 | public bool $author; |
| 23 | public $accepted_paper_id; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 24 | public bool $participation_confirmed; |
Marc Kupietz | cdf2957 | 2023-03-09 08:14:12 +0100 | [diff] [blame] | 25 | public $participation_confirmed_at; |
| 26 | public bool $student; |
| 27 | public bool $conference_dinner; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 28 | public $registered_at; |
| 29 | public bool $earlybird_registration; |
Marc Kupietz | 79eaa0b | 2023-03-16 17:33:43 +0100 | [diff] [blame^] | 30 | public $lunch_day_1; |
| 31 | public $lunch_day_2; |
| 32 | public $lunch_day_3; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 33 | public float $total_due; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 34 | public $invoice; |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 35 | |
| 36 | function __construct() |
| 37 | { |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 38 | $this->id = ""; |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 39 | $this->username = ""; |
| 40 | $this->first_name = ""; |
| 41 | $this->last_name = ""; |
| 42 | $this->email = ""; |
| 43 | $this->organization = ""; |
| 44 | $this->user_hash = ""; |
| 45 | $this->password = ""; |
| 46 | $this->city = ""; |
| 47 | $this->country = ""; |
| 48 | $this->zip = ""; |
| 49 | $this->street = ""; |
| 50 | $this->phone = ""; |
| 51 | $this->eula_signed = false; |
| 52 | $this->privacy_policy_signed = false; |
Marc Kupietz | cdf2957 | 2023-03-09 08:14:12 +0100 | [diff] [blame] | 53 | $this->author = false; |
| 54 | $this->accepted_paper_id = ""; |
| 55 | $this->participation_confirmed = false; |
| 56 | $this->participation_confirmed_at = ""; |
| 57 | $this->student = false; |
| 58 | $this->conference_dinner = false; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 59 | $this->registered_at = date("Y-m-d H:i:s") . "UTC"; |
| 60 | $this->earlybird_registration = false; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 61 | $this->total_due = 0.0; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 62 | $this->invoice = ""; |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | function __construct1(object $data) |
| 66 | { |
| 67 | foreach ($data as $key => $value) { |
| 68 | if (array_key_exists($key, (array) $this)) |
| 69 | $this->{$key} = $value; |
Marc Kupietz | ade9e3c | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 70 | } |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 71 | if (isset($data->password)) $this->set_password($data->password); |
| 72 | } |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 73 | |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 74 | function init_from_object(object $data) |
| 75 | { |
| 76 | foreach ($data as $key => $value) { |
| 77 | if (array_key_exists($key, (array) $this)) |
| 78 | $this->{$key} = $value; |
Marc Kupietz | ade9e3c | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 79 | } |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 80 | if (isset($data->password)) $this->set_password($data->password); |
| 81 | } |
Marc Kupietz | ade9e3c | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 82 | |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 83 | function init_from_array(array $data) |
| 84 | { |
| 85 | foreach ($data as $key => $value) { |
| 86 | if (array_key_exists($key, (array) $this)) { |
| 87 | if (is_bool(gettype($this->{$key})) && is_string($value)) |
| 88 | $this->{$key} = !empty($value); |
| 89 | else |
| 90 | $this->{$key} = $value; |
| 91 | } |
| 92 | } |
| 93 | if (!empty($data["password"])) $this->set_password($data["password"]); |
| 94 | } |
| 95 | |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 96 | |
| 97 | function set_password(string $password) |
| 98 | { |
| 99 | include 'config.php'; |
Marc Kupietz | 7f5e527 | 2023-03-10 13:54:21 +0100 | [diff] [blame] | 100 | if ($CONFERENCE_REGISTRATION) { |
| 101 | $this->password = generateRandomString(32); |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 102 | # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true)); |
| 103 | } else { |
Marc Kupietz | 7f5e527 | 2023-03-10 13:54:21 +0100 | [diff] [blame] | 104 | if ($ENCRYPT_PASSWORDS) { |
| 105 | $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$'); |
| 106 | # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true)); |
| 107 | } else { |
| 108 | $this->user_hash = "{CLEAR}" . $password; |
| 109 | } |
| 110 | $this->password = $this->user_hash; |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 111 | } |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | function to_string() |
| 115 | { |
| 116 | $tmp_user = $this; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 117 | $tmp_user->invoice = ""; |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 118 | $tmp_user->password = "***"; |
| 119 | $tmp_user->user_hash = "***"; |
| 120 | return json_encode($tmp_user); |
| 121 | } |
| 122 | |
| 123 | function backup_in_session() |
| 124 | { |
| 125 | global $_SESSION; |
| 126 | foreach ($this as $key => $value) { |
| 127 | $_SESSION[$key] = $value; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | function to_table() { |
| 132 | $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>"; |
| 133 | foreach ($this as $key => $value) { |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 134 | if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") { |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 135 | if (is_bool($value)) { |
| 136 | if ($value) $value = "yes"; |
| 137 | else $value = "no"; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 138 | } elseif(is_float($value)) { |
| 139 | $key .= " €"; |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 140 | } |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 141 | $value = str_replace("\r\n", "<br>", $value); |
| 142 | $key = str_replace("_", " ", ucfirst($key)); |
| 143 | $table .= " <tr> |
| 144 | <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td> |
| 145 | <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td> |
| 146 | </tr>\n"; |
| 147 | } |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 148 | } |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 149 | $table .= "</table>"; |
| 150 | return $table; |
| 151 | } |
| 152 | } |