diff --git a/src/xmlrpc/results_values.php b/src/xmlrpc/results_values.php index 17cddd2..4519859 100644 --- a/src/xmlrpc/results_values.php +++ b/src/xmlrpc/results_values.php @@ -41,6 +41,7 @@ define ("EMAIL_TAKEN", "ERROR_EMAIL_ALREADY_IN_USE"); define ("ALIAS_NOT_FOUND", "ERROR_ALIAS_DOESNT_EXIST"); define ("ACCOUNT_NOT_FOUND", "ERROR_ACCOUNT_DOESNT_EXIST"); define ("PASSWORD_NOT_FOUND", "ERROR_PASSWORD_NOT_FOUND"); +define ("USERINFO_NOT_FOUND", "ERROR_USERINFO_NOT_FOUND"); /* Equality check failure */ diff --git a/src/xmlrpc/user-info.php b/src/xmlrpc/user-info.php new file mode 100644 index 0000000..6dcec49 --- /dev/null +++ b/src/xmlrpc/user-info.php @@ -0,0 +1,152 @@ +. +*/ + +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/xmlrpc.php b/src/xmlrpc/xmlrpc.php index 3639672..113be56 100644 --- a/src/xmlrpc/xmlrpc.php +++ b/src/xmlrpc/xmlrpc.php @@ -24,6 +24,7 @@ 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__ . '/compatibility.php'; $request = file_get_contents("php://input"); @@ -95,6 +96,7 @@ xmlrpc_devices_register_methods($server); if (USE_IN_APP_PURCHASES) { xmlrpc_inapp_register_methods($server); } +xmlrpc_user_info_register_methods($server); xmlrpc_compatibility_register_methods($server); if ($request) {