From f3ad0acbfe1101aa4ad16bf60f374777bb286c52 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 30 Mar 2019 00:48:03 +0000 Subject: [PATCH] Make web login async --- index.php | 2 +- src/danog/MadelineProto/Wrappers/Start.php | 38 +++++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/index.php b/index.php index bd2f1b6c..30708c1e 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,7 @@ require 'vendor/autoload.php'; -$MadelineProto = new \danog\MadelineProto\API('session.madeline'); +$MadelineProto = new \danog\MadelineProto\API('sessionf.madeline'); $me = $MadelineProto->start(); $me = $MadelineProto->get_self(); diff --git a/src/danog/MadelineProto/Wrappers/Start.php b/src/danog/MadelineProto/Wrappers/Start.php index 02e76a89..5313ea2b 100644 --- a/src/danog/MadelineProto/Wrappers/Start.php +++ b/src/danog/MadelineProto/Wrappers/Start.php @@ -24,10 +24,10 @@ namespace danog\MadelineProto\Wrappers; */ trait Start { - public function start() + public function start_async() { if ($this->authorized === self::LOGGED_IN) { - return $this->get_self(); + return yield $this->get_self_async(); } if (php_sapi_name() === 'cli') { if (!function_exists('readline')) { @@ -44,44 +44,44 @@ trait Start $readline = 'readline'; } if (strpos($readline('Do you want to login as user or bot (u/b)? '), 'b') !== false) { - $this->bot_login($readline('Enter your bot token: ')); + yield $this->bot_login_async($readline('Enter your bot token: ')); } else { - $this->phone_login($readline('Enter your phone number: ')); - $authorization = $this->complete_phone_login($readline('Enter the phone code: ')); + yield $this->phone_login_async($readline('Enter your phone number: ')); + $authorization = yield $this->complete_phone_login_async($readline('Enter the phone code: ')); if ($authorization['_'] === 'account.password') { - $authorization = $this->complete_2fa_login($readline('Please enter your password (hint '.$authorization['hint'].'): ')); + $authorization = yield $this->complete_2fa_login_async($readline('Please enter your password (hint '.$authorization['hint'].'): ')); } if ($authorization['_'] === 'account.needSignup') { - $authorization = $this->complete_signup($readline('Please enter your first name: '), $readline('Please enter your last name (can be empty): ')); + $authorization = yield $this->complete_signup_async($readline('Please enter your first name: '), $readline('Please enter your last name (can be empty): ')); } } $this->serialize(); - return $this->get_self(); + return yield $this->get_self_async(); } else { if ($this->authorized === self::NOT_LOGGED_IN) { if (isset($_POST['phone_number'])) { - $this->web_phone_login(); + yield $this->web_phone_login(); } elseif (isset($_POST['token'])) { - $this->web_bot_login(); + yield $this->web_bot_login(); } else { $this->web_echo(); } } elseif ($this->authorized === self::WAITING_CODE) { if (isset($_POST['phone_code'])) { - $this->web_complete_phone_login(); + yield $this->web_complete_phone_login(); } else { $this->web_echo("You didn't provide a phone code!"); } } elseif ($this->authorized === self::WAITING_PASSWORD) { if (isset($_POST['password'])) { - $this->web_complete_2fa_login(); + yield $this->web_complete_2fa_login(); } else { $this->web_echo("You didn't provide the password!"); } } elseif ($this->authorized === self::WAITING_SIGNUP) { if (isset($_POST['first_name'])) { - $this->web_complete_signup(); + yield $this->web_complete_signup(); } else { $this->web_echo("You didn't provide the first name!"); } @@ -89,7 +89,7 @@ trait Start if ($this->authorized === self::LOGGED_IN) { $this->serialize(); - return $this->get_self(); + return yield $this->get_self_async(); } exit; } @@ -98,7 +98,7 @@ trait Start public function web_phone_login() { try { - $this->phone_login($_POST['phone_number']); + yield $this->phone_login_async($_POST['phone_number']); $this->web_echo(); } catch (\danog\MadelineProto\RPCErrorException $e) { $this->web_echo('ERROR: '.$e->getMessage().'. Try again.'); @@ -110,7 +110,7 @@ trait Start public function web_complete_phone_login() { try { - $this->complete_phone_login($_POST['phone_code']); + yield $this->complete_phone_login_async($_POST['phone_code']); $this->web_echo(); } catch (\danog\MadelineProto\RPCErrorException $e) { $this->web_echo('ERROR: '.$e->getMessage().'. Try again.'); @@ -122,7 +122,7 @@ trait Start public function web_complete_2fa_login() { try { - $this->complete_2fa_login($_POST['password']); + yield $this->complete_2fa_login_async($_POST['password']); $this->web_echo(); } catch (\danog\MadelineProto\RPCErrorException $e) { $this->web_echo('ERROR: '.$e->getMessage().'. Try again.'); @@ -134,7 +134,7 @@ trait Start public function web_complete_signup() { try { - $this->complete_signup($_POST['first_name'], isset($_POST['last_name']) ? $_POST['last_name'] : ''); + yield $this->complete_signup_async($_POST['first_name'], isset($_POST['last_name']) ? $_POST['last_name'] : ''); $this->web_echo(); } catch (\danog\MadelineProto\RPCErrorException $e) { $this->web_echo('ERROR: '.$e->getMessage().'. Try again.'); @@ -146,7 +146,7 @@ trait Start public function web_bot_login() { try { - $this->bot_login($_POST['token']); + yield $this->bot_login_async($_POST['token']); $this->web_echo(); } catch (\danog\MadelineProto\RPCErrorException $e) { $this->web_echo('ERROR: '.$e->getMessage().'. Try again.');