Make web login async
This commit is contained in:
parent
1f9ebfc568
commit
f3ad0acbfe
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
|
$MadelineProto = new \danog\MadelineProto\API('sessionf.madeline');
|
||||||
$me = $MadelineProto->start();
|
$me = $MadelineProto->start();
|
||||||
|
|
||||||
$me = $MadelineProto->get_self();
|
$me = $MadelineProto->get_self();
|
||||||
|
@ -24,10 +24,10 @@ namespace danog\MadelineProto\Wrappers;
|
|||||||
*/
|
*/
|
||||||
trait Start
|
trait Start
|
||||||
{
|
{
|
||||||
public function start()
|
public function start_async()
|
||||||
{
|
{
|
||||||
if ($this->authorized === self::LOGGED_IN) {
|
if ($this->authorized === self::LOGGED_IN) {
|
||||||
return $this->get_self();
|
return yield $this->get_self_async();
|
||||||
}
|
}
|
||||||
if (php_sapi_name() === 'cli') {
|
if (php_sapi_name() === 'cli') {
|
||||||
if (!function_exists('readline')) {
|
if (!function_exists('readline')) {
|
||||||
@ -44,44 +44,44 @@ trait Start
|
|||||||
$readline = 'readline';
|
$readline = 'readline';
|
||||||
}
|
}
|
||||||
if (strpos($readline('Do you want to login as user or bot (u/b)? '), 'b') !== false) {
|
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 {
|
} else {
|
||||||
$this->phone_login($readline('Enter your phone number: '));
|
yield $this->phone_login_async($readline('Enter your phone number: '));
|
||||||
$authorization = $this->complete_phone_login($readline('Enter the phone code: '));
|
$authorization = yield $this->complete_phone_login_async($readline('Enter the phone code: '));
|
||||||
if ($authorization['_'] === 'account.password') {
|
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') {
|
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();
|
$this->serialize();
|
||||||
|
|
||||||
return $this->get_self();
|
return yield $this->get_self_async();
|
||||||
} else {
|
} else {
|
||||||
if ($this->authorized === self::NOT_LOGGED_IN) {
|
if ($this->authorized === self::NOT_LOGGED_IN) {
|
||||||
if (isset($_POST['phone_number'])) {
|
if (isset($_POST['phone_number'])) {
|
||||||
$this->web_phone_login();
|
yield $this->web_phone_login();
|
||||||
} elseif (isset($_POST['token'])) {
|
} elseif (isset($_POST['token'])) {
|
||||||
$this->web_bot_login();
|
yield $this->web_bot_login();
|
||||||
} else {
|
} else {
|
||||||
$this->web_echo();
|
$this->web_echo();
|
||||||
}
|
}
|
||||||
} elseif ($this->authorized === self::WAITING_CODE) {
|
} elseif ($this->authorized === self::WAITING_CODE) {
|
||||||
if (isset($_POST['phone_code'])) {
|
if (isset($_POST['phone_code'])) {
|
||||||
$this->web_complete_phone_login();
|
yield $this->web_complete_phone_login();
|
||||||
} else {
|
} else {
|
||||||
$this->web_echo("You didn't provide a phone code!");
|
$this->web_echo("You didn't provide a phone code!");
|
||||||
}
|
}
|
||||||
} elseif ($this->authorized === self::WAITING_PASSWORD) {
|
} elseif ($this->authorized === self::WAITING_PASSWORD) {
|
||||||
if (isset($_POST['password'])) {
|
if (isset($_POST['password'])) {
|
||||||
$this->web_complete_2fa_login();
|
yield $this->web_complete_2fa_login();
|
||||||
} else {
|
} else {
|
||||||
$this->web_echo("You didn't provide the password!");
|
$this->web_echo("You didn't provide the password!");
|
||||||
}
|
}
|
||||||
} elseif ($this->authorized === self::WAITING_SIGNUP) {
|
} elseif ($this->authorized === self::WAITING_SIGNUP) {
|
||||||
if (isset($_POST['first_name'])) {
|
if (isset($_POST['first_name'])) {
|
||||||
$this->web_complete_signup();
|
yield $this->web_complete_signup();
|
||||||
} else {
|
} else {
|
||||||
$this->web_echo("You didn't provide the first name!");
|
$this->web_echo("You didn't provide the first name!");
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ trait Start
|
|||||||
if ($this->authorized === self::LOGGED_IN) {
|
if ($this->authorized === self::LOGGED_IN) {
|
||||||
$this->serialize();
|
$this->serialize();
|
||||||
|
|
||||||
return $this->get_self();
|
return yield $this->get_self_async();
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ trait Start
|
|||||||
public function web_phone_login()
|
public function web_phone_login()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->phone_login($_POST['phone_number']);
|
yield $this->phone_login_async($_POST['phone_number']);
|
||||||
$this->web_echo();
|
$this->web_echo();
|
||||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||||
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
||||||
@ -110,7 +110,7 @@ trait Start
|
|||||||
public function web_complete_phone_login()
|
public function web_complete_phone_login()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->complete_phone_login($_POST['phone_code']);
|
yield $this->complete_phone_login_async($_POST['phone_code']);
|
||||||
$this->web_echo();
|
$this->web_echo();
|
||||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||||
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
||||||
@ -122,7 +122,7 @@ trait Start
|
|||||||
public function web_complete_2fa_login()
|
public function web_complete_2fa_login()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->complete_2fa_login($_POST['password']);
|
yield $this->complete_2fa_login_async($_POST['password']);
|
||||||
$this->web_echo();
|
$this->web_echo();
|
||||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||||
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
||||||
@ -134,7 +134,7 @@ trait Start
|
|||||||
public function web_complete_signup()
|
public function web_complete_signup()
|
||||||
{
|
{
|
||||||
try {
|
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();
|
$this->web_echo();
|
||||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||||
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
||||||
@ -146,7 +146,7 @@ trait Start
|
|||||||
public function web_bot_login()
|
public function web_bot_login()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->bot_login($_POST['token']);
|
yield $this->bot_login_async($_POST['token']);
|
||||||
$this->web_echo();
|
$this->web_echo();
|
||||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||||
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
||||||
|
Loading…
Reference in New Issue
Block a user