Skip to content

Instantly share code, notes, and snippets.

View dmytrostriletskyi's full-sized avatar

Dmytro Striletskyi dmytrostriletskyi

View GitHub Profile
@dmytrostriletskyi
dmytrostriletskyi / telegram-widget-embed-code.html
Last active February 14, 2018 21:13
The example of the Telegram widget embed code
<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>
@dmytrostriletskyi
dmytrostriletskyi / django-telegram-login-widgets-generation.py
Created February 14, 2018 21:18
The widget generation using django-telegram-login
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,
@dmytrostriletskyi
dmytrostriletskyi / redirect-widget-embed-code.html
Last active February 14, 2018 23:00
An example of the redirect widget embed code
<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>
@dmytrostriletskyi
dmytrostriletskyi / create-redirect-login-widget.py
Last active February 14, 2018 22:46
How redirect generator create widget
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)
@dmytrostriletskyi
dmytrostriletskyi / callback-view.py
Created February 14, 2018 22:14
An example of using generated widget with view's context
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)
@dmytrostriletskyi
dmytrostriletskyi / telegram-login-callback-widget-html.html
Last active February 14, 2018 22:48
The widget is going to be rendered from view's 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>
@dmytrostriletskyi
dmytrostriletskyi / redirect-view-verify-received-data.py
Last active February 15, 2018 13:54
An example of the verification the received data from Telegram
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 %}
@dmytrostriletskyi
dmytrostriletskyi / all-needed-views.py
Last active February 22, 2018 19:15
All the Telegram login via django_telegram_login package logic
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,
)

Jira references

  • Ticket (task) —

Description

Description text.

picture_name

Implemented