MadelineProtoDocs/docs/complete_phone_login.md

35 lines
1.5 KiB
Markdown
Raw Normal View History

2018-04-01 13:19:25 +02:00
---
title: complete_phone_login
description: complete_phone_login parameters, return type and example
---
## Method: complete\_phone\_login
### Parameters:
| Name | Type |
|----------|---------------|
|code| A string with the phone code|
### Return type: [auth.Authorization](API_docs/types/auth_Authorization.md) or [account.Password](http://docs.madelineproto.xyz/API_docs/types/account_Password.html) or `['_' => 'account.needSignup']`
You must then use [complete_2FA_login](complete_2FA_login.md) or [complete_signup](complete_signup.md) to login or signup, or simply start using `$MadelineProto` if the result is a `auth.Authorization` object.
2019-06-01 18:08:28 +02:00
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
2018-04-01 13:19:25 +02:00
```php
2019-06-01 18:08:28 +02:00
yield $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
2018-04-01 13:19:25 +02:00
if ($authorization['_'] === 'account.noPassword') {
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
}
if ($authorization['_'] === 'account.password') {
2019-06-01 18:08:28 +02:00
$authorization = yield $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
2018-04-01 13:19:25 +02:00
}
if ($authorization['_'] === 'account.needSignup') {
2019-06-01 18:08:28 +02:00
$authorization = yield $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
2018-04-01 13:19:25 +02:00
}
```