- Ticket (task) —
Description text.
—
<script async src="https://telegram.org/js/telegram-widget.js?2" | |
data-telegram-login="samplebot" | |
data-size="large" | |
data-auth-url="" | |
data-request-access="write"> | |
</script> |
from django.conf import settings | |
from django_telegram_login.widgets.constants import ( | |
SMALL, | |
MEDIUM, | |
LARGE, | |
DISABLE_USER_PHOTO, | |
) | |
from django_telegram_login.widgets.generator import ( | |
create_callback_login_widget, |
<script async src="https://telegram.org/js/telegram-widget.js?3" | |
data-telegram-login="HabrahabrTelegramLoginBot" | |
data-size="medium" | |
data-radius="10" | |
data-auth-url="https://kqmxkdqitb.localtunnel.me" | |
data-onauth="onTelegramAuth(user)" | |
data-request-access="write"> | |
</script> |
def create_redirect_login_widget( | |
redirect_url, bot_name, size=SMALL, user_photo=True, access_write=True | |
): | |
""" | |
Create a redirect widget, that allows to handle an user data as get request params. | |
""" | |
script_initital = \ | |
'<script async src="https://telegram.org/js/telegram-widget.js?2" ' | |
bot = 'data-telegram-login="{}" '.format(bot_name) | |
size = 'data-size="{}" '.format(size) |
def callback(request): | |
telegram_login_widget = create_callback_login_widget(bot_name, size=SMALL) | |
context = {'telegram_login_widget': telegram_login_widget} | |
return render(request, 'telegram_auth/callback.html', context) |
It is a template to render a callback Telegram widget! | |
<!-- {{ telegram_login_widget|safe }} --> | |
{% autoescape off %}{{ telegram_login_widget }}{% endautoescape %} | |
<script type="text/javascript"> | |
function onTelegramAuth(user) { | |
alert('Logged in as ' + user.first_name + ' ' + user.last_name + '!'); | |
} | |
</script> |
from django_telegram_login.authentication import verify_telegram_authentication | |
from django_telegram_login.errors import ( | |
NotTelegramDataError, | |
TelegramDataIsOutdatedError, | |
) | |
def index(request): | |
# Initially, the index page may have no get params in URL |
It is a template to render a redirect Telegram widget! | |
<!-- {{ telegram_login_widget|safe }} --> | |
{% autoescape off %}{{ telegram_login_widget }}{% endautoescape %} |
from django.conf import settings | |
from django.http import HttpResponse | |
from django.shortcuts import render | |
from django_telegram_login.widgets.constants import ( | |
SMALL, | |
MEDIUM, | |
LARGE, | |
DISABLE_USER_PHOTO, | |
) |