From 774386eec438f95bd84b6dee2eb53e3036f83e22 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 20 Aug 2019 15:37:34 +0200 Subject: [PATCH] Fixed minor issues --- src/objects/account.php | 5 +- src/objects/user_info.php | 2 +- src/xmlrpc/user-info.php | 152 -------------------------------------- src/xmlrpc/user_info.php | 2 + 4 files changed, 6 insertions(+), 155 deletions(-) delete mode 100644 src/xmlrpc/user-info.php diff --git a/src/objects/account.php b/src/objects/account.php index 15d9c0a..c7dd6c1 100644 --- a/src/objects/account.php +++ b/src/objects/account.php @@ -211,7 +211,7 @@ class Account { } function getAll() { - $query = "SELECT ac.id, ac.username, ac.domain, ac.activated, ac.confirmation_key, al.alias FROM " . ACCOUNTS_DB_TABLE . + $query = "SELECT ac.id, ac.username, ac.domain, ac.activated, ac.confirmation_key, ac.email, al.alias FROM " . ACCOUNTS_DB_TABLE . " ac LEFT JOIN " . ALIAS_DB_TABLE . " al ON ac.id = al.account_id"; $stmt = $this->conn->prepare($query); Logger::getInstance()->debug("GetAll " . (string)$this); @@ -220,7 +220,7 @@ class Account { } function getOne() { - $query = "SELECT ac.id, ac.username, ac.domain, ac.activated, ac.confirmation_key, al.alias FROM " . ACCOUNTS_DB_TABLE . + $query = "SELECT ac.id, ac.username, ac.domain, ac.activated, ac.confirmation_key, ac.email, al.alias FROM " . ACCOUNTS_DB_TABLE . " ac LEFT JOIN " . ALIAS_DB_TABLE . " al ON ac.id = al.account_id"; if (!empty($this->id)) { @@ -271,6 +271,7 @@ class Account { $this->id = $row['id']; $this->username = $row['username']; $this->domain = $row['domain']; + $this->email = $row['email']; $this->activated = $row['activated']; $this->confirmation_key = $row['confirmation_key']; $this->alias = $row['alias']; diff --git a/src/objects/user_info.php b/src/objects/user_info.php index f3a014f..cb7952d 100644 --- a/src/objects/user_info.php +++ b/src/objects/user_info.php @@ -24,7 +24,7 @@ class UserInfo { public $id; public $account_id; public $firstname; - public $lastname; + public $lastname; public $gender; public $subscribe; diff --git a/src/xmlrpc/user-info.php b/src/xmlrpc/user-info.php deleted file mode 100644 index 6dcec49..0000000 --- a/src/xmlrpc/user-info.php +++ /dev/null @@ -1,152 +0,0 @@ -. -*/ - -include_once __DIR__ . '/../database/database.php'; - -include_once __DIR__ . '/../objects/account.php'; -include_once __DIR__ . '/../objects/password.php'; -include_once __DIR__ . '/../objects/alias.php'; -include_once __DIR__ . '/../objects/user-info.php'; - -include_once __DIR__ . '/../misc/utilities.php'; - -include_once __DIR__ . '/results_values.php'; - -// args = [username, ha1, [domain], [algo]] -function xmlrpc_get_email_account($method, $args) { - $username = $args[0]; - $ha1 = $args[1]; - $domain = get_domain($args[2]); - $algo = get_algo($args[3]); - - $database = new Database(); - $db = $database->getConnection(); - - $account = new Account($db); - $account->username = $username; - $account->domain = $domain; - - if (!$account->getOne()) { - return ACCOUNT_NOT_FOUND; - } - - $password = new Password($db); - $password->account_id = $account->id; - $password->algorithm = $algo; - - if (!$password->getOne()) { - return PASSWORD_NOT_FOUND; - } - - if (!password_match($ha1, $password->password)) { - return PASSWORD_DOESNT_MATCH; - } - - $userinfo = new UserInfo($db); - $userinfo->account_id = $account->id; - - if (!$userinfo->getOne()) { - return USERINFO_NOT_FOUND; - } - - $result = array( - "id" => $account->id, - "username" => $account->username, - "domain" => $account->domain, - "email" => $account->email, - "alias" => $account->alias, - "activated" => $account->activated, - "firstname" => $userinfo->firstname, - "lastname" => $userinfo->lastname, - "gender" => $userinfo->gender, - "subscribe" => $userinfo->subscribe - ); - - return $result; -} - -// args = [tel, ha1, [domain], [algo]] -function xmlrpc_get_phone_account($method, $args) { - $phone = $args[0]; - $ha1 = $args[1]; - $domain = get_domain($args[2]); - $algo = get_algo($args[3]); - - $database = new Database(); - $db = $database->getConnection(); - - $alias = new Alias($db); - $alias->alias = $phone; - $alias->domain = $domain; - - $account = new Account($db); - - if (!$alias->getOne()) { - $account->username = $phone; - $account->domain = $domain; - } else { - $account->id = $alias->account_id; - } - - if (!$account->getOne()) { - return ACCOUNT_NOT_FOUND; - } - - $password = new Password($db); - $password->account_id = $account->id; - $password->algorithm = $algo; - - if (!$password->getOne()) { - return PASSWORD_NOT_FOUND; - } - - if (!password_match($ha1, $password->password)) { - return PASSWORD_DOESNT_MATCH; - } - - $userinfo = new UserInfo($db); - $userinfo->account_id = $account->id; - - if (!$userinfo->getOne()) { - return USERINFO_NOT_FOUND; - } - - $result = array( - "id" => $account->id, - "username" => $account->username, - "domain" => $account->domain, - "email" => $account->email, - "alias" => $account->alias, - "activated" => $account->activated, - "firstname" => $userinfo->firstname, - "lastname" => $userinfo->lastname, - "gender" => $userinfo->gender, - "subscribe" => $userinfo->subscribe - ); - - return $result; -} - -function xmlrpc_user_info_register_methods($server) { - xmlrpc_server_register_method($server, 'get_email_account', 'xmlrpc_get_email_account'); // args = [username, ha1, [domain], [algo]] - xmlrpc_server_register_method($server, 'get_phone_account', 'xmlrpc_get_phone_account'); // args = [tel, ha1, [domain], [algo]] -} - -?> \ No newline at end of file diff --git a/src/xmlrpc/user_info.php b/src/xmlrpc/user_info.php index c70ad92..ff54e7e 100644 --- a/src/xmlrpc/user_info.php +++ b/src/xmlrpc/user_info.php @@ -172,6 +172,8 @@ function xmlrpc_get_account_by_confirmation_key($method, $args) { "gender" => $user_info->gender, "subscribe" => $user_info->subscribe ); + + return $result; } function xmlrpc_user_info_register_methods($server) {