diff --git a/src/objects/account.php b/src/objects/account.php index 21418b3..15d9c0a 100644 --- a/src/objects/account.php +++ b/src/objects/account.php @@ -236,6 +236,9 @@ class Account { } else if (!empty($this->email)) { $query = $query . " WHERE ac.email = ?"; $this->email = htmlspecialchars(strip_tags($this->email)); + } else if (!empty($this->confirmation_key)) { + $query = $query . " WHERE ac.confirmation_key = ?"; + $this->confirmation_key = htmlspecialchars(strip_tags($this->confirmation_key)); } else { return false; } @@ -253,6 +256,8 @@ class Account { } } else if (!empty($this->email)) { $stmt->bindParam(1, $this->email); + } else if (!empty($this->confirmation_key)) { + $stmt->bindParam(1, $this->confirmation_key); } Logger::getInstance()->debug("GetOne " . (string)$this); diff --git a/src/objects/user-info.php b/src/objects/user_info.php similarity index 100% rename from src/objects/user-info.php rename to src/objects/user_info.php diff --git a/src/tools/create_tables.php b/src/tools/create_tables.php index bd7a41c..a161ffc 100644 --- a/src/tools/create_tables.php +++ b/src/tools/create_tables.php @@ -26,7 +26,7 @@ include_once __DIR__ . '/../objects/alias.php'; include_once __DIR__ . '/../objects/device.php'; include_once __DIR__ . '/../objects/password.php'; include_once __DIR__ . '/../objects/sms.php'; -include_once __DIR__ . '/../objects/user-info.php'; +include_once __DIR__ . '/../objects/user_info.php'; $database = new Database(); $db = $database->getConnection(); diff --git a/src/tools/drop_tables.php b/src/tools/drop_tables.php index cd3c649..f4b2f6c 100644 --- a/src/tools/drop_tables.php +++ b/src/tools/drop_tables.php @@ -26,7 +26,7 @@ include_once __DIR__ . '/../objects/alias.php'; include_once __DIR__ . '/../objects/device.php'; include_once __DIR__ . '/../objects/password.php'; include_once __DIR__ . '/../objects/sms.php'; -include_once __DIR__ . '/../objects/user-info.php'; +include_once __DIR__ . '/../objects/user_info.php'; $database = new Database(); $db = $database->getConnection(); diff --git a/src/tools/migrate_accounts.php b/src/tools/migrate_accounts.php index b4f442f..4c6928d 100644 --- a/src/tools/migrate_accounts.php +++ b/src/tools/migrate_accounts.php @@ -26,7 +26,7 @@ include_once __DIR__ . '/../objects/alias.php'; include_once __DIR__ . '/../objects/device.php'; include_once __DIR__ . '/../objects/password.php'; include_once __DIR__ . '/../objects/sms.php'; -include_once __DIR__ . '/../objects/user-info.php'; +include_once __DIR__ . '/../objects/user_info.php'; include_once __DIR__ . '/../misc/utilities.php'; $database = new Database(); @@ -101,7 +101,7 @@ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $user_info->gender = $gender; $user_info->subscribe = $subscribe; if (!$user_info->create()) { - Logger::getInstance()->error("Failed to create user-info !"); + Logger::getInstance()->error("Failed to create user_info !"); } $pwd = new Password($db); diff --git a/src/xmlrpc/user_info.php b/src/xmlrpc/user_info.php new file mode 100644 index 0000000..c70ad92 --- /dev/null +++ b/src/xmlrpc/user_info.php @@ -0,0 +1,183 @@ +. +*/ + +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]); + + Logger::getInstance()->message("[XMLRPC] xmlrpc_get_email_account(" . $username . ")"); + + $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; + } + + $user_info = new UserInfo($db); + $user_info->account_id = $account->id; + + $result = array( + "id" => $account->id, + "username" => $account->username, + "domain" => $account->domain, + "email" => $account->email, + "alias" => $account->alias, + "activated" => $account->activated, + "firstname" => $user_info->firstname, + "lastname" => $user_info->lastname, + "gender" => $user_info->gender, + "subscribe" => $user_info->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]); + + Logger::getInstance()->message("[XMLRPC] xmlrpc_get_phone_account(" . $phone . ")"); + + $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; + } + + $user_info = new UserInfo($db); + $user_info->account_id = $account->id; + + $result = array( + "id" => $account->id, + "username" => $account->username, + "domain" => $account->domain, + "email" => $account->email, + "alias" => $account->alias, + "activated" => $account->activated, + "firstname" => $user_info->firstname, + "lastname" => $user_info->lastname, + "gender" => $user_info->gender, + "subscribe" => $user_info->subscribe + ); + + return $result; +} + +// args = [confirmation_key, [algo]] +function xmlrpc_get_account_by_confirmation_key($method, $args) { + $confirmation_key = $args[0]; + $algo = get_algo($args[1]); + + Logger::getInstance()->message("[XMLRPC] xmlrpc_get_account_by_confirmation_key(" . $confirmation_key . ")"); + + $database = new Database(); + $db = $database->getConnection(); + + $account = new Account($db); + $account->confirmation_key = $confirmation_key; + + if (!$account->getOne()) { + return ACCOUNT_NOT_FOUND; + } + + $user_info = new UserInfo($db); + $user_info->account_id = $account->id; + + $result = array( + "id" => $account->id, + "username" => $account->username, + "domain" => $account->domain, + "email" => $account->email, + "alias" => $account->alias, + "activated" => $account->activated, + "firstname" => $user_info->firstname, + "lastname" => $user_info->lastname, + "gender" => $user_info->gender, + "subscribe" => $user_info->subscribe + ); +} + +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]] + xmlrpc_server_register_method($server, 'get_account_by_confirmation_key', 'xmlrpc_get_account_by_confirmation_key'); // args = [confirmation_key, [algo]] +} + +?> \ No newline at end of file diff --git a/src/xmlrpc/xmlrpc.php b/src/xmlrpc/xmlrpc.php index 113be56..0105c24 100644 --- a/src/xmlrpc/xmlrpc.php +++ b/src/xmlrpc/xmlrpc.php @@ -19,12 +19,14 @@ */ include_once __DIR__ . '/../database/database.php'; + include_once __DIR__ . '/../misc/utilities.php'; + include_once __DIR__ . '/authentication.php'; include_once __DIR__ . '/accounts.php'; include_once __DIR__ . '/aliases.php'; include_once __DIR__ . '/devices.php'; -include_once __DIR__ . '/user-info.php'; +include_once __DIR__ . '/user_info.php'; include_once __DIR__ . '/compatibility.php'; $request = file_get_contents("php://input");