Add adress and phone number attributes
Change-Id: I7e69468ac6e5a05f42120a42bf02b92f18773ca7
diff --git a/User.php b/User.php
index ea144b7..5fb7307 100644
--- a/User.php
+++ b/User.php
@@ -3,50 +3,126 @@
class User
{
- public $username;
- public $name;
- public $first_name;
- public $last_name;
- public $email;
- public $organization;
- public $user_hash;
- public $password;
- function __construct()
- {
- $this->username = "";
- $this->name = "";
- $this->first_name = "";
- $this->last_name = "";
- $this->email = "";
- $this->organization = "";
- $this->user_hash = "";
- $this->password = "";
+ 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 __construct6(string $username, string $first_name, string $last_name, string $email, string $password, string $organization)
- {
- include 'config.php';
- $this->username = $username;
- $this->name = $first_name;
- $this->first_name = $first_name;
- $this->last_name = $last_name;
- $this->email = $email;
- $this->organization = $organization;
- $this->set_password($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 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;
+ 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 __construct6(string $username, string $first_name, string $last_name, string $email, string $password, string $organization)
+ {
+ include 'config.php';
+ $this->username = $username;
+ $this->first_name = $first_name;
+ $this->last_name = $last_name;
+ $this->email = $email;
+ $this->organization = $organization;
+ $this->set_password($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";
}
- $this->password = $this->user_hash;
+ $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";
+ }
}
-}
-
-?>
\ No newline at end of file
+ $table .= "</table>";
+ return $table;
+ }
+}
\ No newline at end of file