1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 18:51:13 +01:00

Final fixes

This commit is contained in:
Daniil Gentili 2023-06-18 21:36:59 +02:00
parent bd8602c57d
commit 0016c68a7c
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 31 additions and 12 deletions

View File

@ -156,6 +156,7 @@ final class Lang
'signupWeb' => 'Registrazione',
'go' => 'Vai',
'loginChoosePromptWeb' => 'Vuoi effettuare il login come utente o come bot?',
'loginWebQr' => 'Puoi anche effettuare il login automaticamente scansionando il seguente codice QR:',
'loginOptionBot' => 'Bot',
'loginOptionUser' => 'Utente',
'loginBotTokenWeb' => 'Token del bot',
@ -175,6 +176,7 @@ final class Lang
[
'go' => 'Go',
'loginChoosePromptWeb' => 'Do you want to login as a user or as a bot?',
'loginWebQr' => 'You can also login automatically by scanning the following QR code:',
'loginOptionBot' => 'Bot',
'loginOptionUser' => 'User',
'apiChooseManualAutoTip' => 'Note that you can also provide the API ID/hash directly in the code using the settings: %s',

View File

@ -123,7 +123,7 @@ trait Start
if (isset($_POST['password'])) {
$this->webComplete2faLogin();
} else {
$this->webEcho(Lang::$current_lang['loginNoPass']);
$this->webEcho(Lang::$current_lang['loginUserPassWeb']);
}
} elseif ($this->getAuthorization() === MTProto::WAITING_SIGNUP) {
if (isset($_POST['first_name'])) {

View File

@ -54,13 +54,14 @@ trait Templates
$token = \htmlentities(Lang::$current_lang['loginBotTokenWeb']);
$form = "<input type='text' name='token' placeholder='$token' required/>";
}
} elseif (isset($_GET['waitQrCodeOrLogin'])) {
} elseif (isset($_GET['waitQrCodeOrLogin']) || isset($_GET['getQrCode'])) {
header('Content-type: application/json');
try {
/** @var ?LoginQrCode */
$qr = $this->qrLogin()?->waitForLoginOrQrCodeExpiration(new TimeoutCancellation(
5.0
));
$qr = $this->qrLogin();
if (isset($_GET['waitQrCodeOrLogin'])) {
$qr = $qr?->waitForLoginOrQrCodeExpiration(new TimeoutCancellation(5.0));
}
} catch (CancelledException) {
/** @var ?LoginQrCode */
$qr = $this->qrLogin();
@ -81,13 +82,29 @@ trait Templates
$title = Lang::$current_lang['loginChoosePromptWeb'];
$optionBot = \htmlentities(Lang::$current_lang['loginOptionBot']);
$optionUser = \htmlentities(Lang::$current_lang['loginOptionUser']);
$trailer = '<div id="qr-code"></div><script>
var x = new XMLHttpRequest();
x.onload = function() {
document.getElementById("demo").innerHTML = this.responseText;
}
x.open("GET", "?waitQrCodeOrLogin", true);
x.send();
$trailer = '
<div id="qr-code-container" style="display: none">
<p>'.htmlentities(Lang::$current_lang['loginWebQr']).'</p>
<div id="qr-code"></div>
</div>
<script>
function longPollQr(query) {
var x = new XMLHttpRequest();
x.onload = function() {
var res = JSON.parse(this.responseText);
if (res.logged_in) {
location.reload();
} else {
document.getElementById("qr-code-container").style = "";
document.getElementById("qr-code").innerHTML = res.svg;
longPollQr("waitQrCodeOrLogin");
}
};
x.open("GET", "'.(\explode('?', $_SERVER['REQUEST_URI'], 2)[0] ?? '').'?"+query, true);
x.send();
}
longPollQr("getQrCode");
</script>';
$form = "<select name='type'><option value='phone'>$optionUser</option><option value='bot'>$optionBot</option></select>";
}