yandex auth
This commit is contained in:
parent
125eaf7f58
commit
073e52e09e
@ -147,3 +147,4 @@ MINIO_SECRET_KEY = os.getenv("MINIO_SECRET_KEY", "minioadmin")
|
|||||||
MINIO_BUCKET_NAME = 'platform'
|
MINIO_BUCKET_NAME = 'platform'
|
||||||
|
|
||||||
VK_SERVICE_TOKEN = os.getenv("VK_SERVICE_TOKEN", None)
|
VK_SERVICE_TOKEN = os.getenv("VK_SERVICE_TOKEN", None)
|
||||||
|
YANDEX_SERVICE_TOKEN = os.getenv("YANDEX_SERVICE_TOKEN", None)
|
||||||
|
@ -56,6 +56,13 @@
|
|||||||
<div style="margin-top: -15px; margin-left: 30px;"><i style="color: green;" class="fa fa-check-circle"></i></div>
|
<div style="margin-top: -15px; margin-left: 30px;"><i style="color: green;" class="fa fa-check-circle"></i></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
<td><div style="width: 20px;"></div></td>
|
||||||
|
<td>
|
||||||
|
<a href="https://oauth.yandex.ru/authorize?response_type=code&client_id=c66de1919a9d4211b5129362020e6f27&redirect_uri=https://platform.sprinthub.ru/yandex_auth"><img style="width: 40px; height: 40px;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/Yandex_icon.svg/2048px-Yandex_icon.svg.png"></a>
|
||||||
|
{% if account.yandex_id %}
|
||||||
|
<div style="margin-top: -15px; margin-left: 30px;"><i style="color: green;" class="fa fa-check-circle"></i></div>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
или войти с помощью<br><br>
|
или войти с помощью<br><br>
|
||||||
<a href="https://oauth.vk.com/authorize?client_id=8123759&redirect_uri=https://platform.sprinthub.ru/vk_auth&display=page&response_type=token&v=5.59"><img style="width: 40px; height: 40px;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f3/VK_Compact_Logo_%282021-present%29.svg/1200px-VK_Compact_Logo_%282021-present%29.svg.png"></a>
|
<a href="https://oauth.vk.com/authorize?client_id=8123759&redirect_uri=https://platform.sprinthub.ru/vk_auth&display=page&response_type=token&v=5.59"><img style="width: 40px; height: 40px;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f3/VK_Compact_Logo_%282021-present%29.svg/1200px-VK_Compact_Logo_%282021-present%29.svg.png"></a>
|
||||||
<a href=#""><img style="width: 40px; height: 40px; margin-left: 10px;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/Yandex_icon.svg/2048px-Yandex_icon.svg.png"></a>
|
<a href="https://oauth.yandex.ru/authorize?response_type=code&client_id=c66de1919a9d4211b5129362020e6f27&redirect_uri=https://platform.sprinthub.ru/yandex_auth"><img style="width: 40px; height: 40px; margin-left: 10px;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/Yandex_icon.svg/2048px-Yandex_icon.svg.png"></a>
|
||||||
</div>
|
</div>
|
||||||
</center>
|
</center>
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,5 +11,6 @@ urlpatterns = [
|
|||||||
path(*ProfilePhoto.as_path()),
|
path(*ProfilePhoto.as_path()),
|
||||||
path(*LogoutView.as_path()),
|
path(*LogoutView.as_path()),
|
||||||
path(*PingView.as_path()),
|
path(*PingView.as_path()),
|
||||||
path(*VKAuthView.as_path())
|
path(*VKAuthView.as_path()),
|
||||||
|
path(*YandexAuthView.as_path())
|
||||||
]
|
]
|
||||||
|
@ -6,3 +6,4 @@ from .profile_photo import ProfilePhoto
|
|||||||
from .logout import LogoutView
|
from .logout import LogoutView
|
||||||
from .ping import PingView
|
from .ping import PingView
|
||||||
from .vk_auth import VKAuthView
|
from .vk_auth import VKAuthView
|
||||||
|
from .yandex_auth import YandexAuthView
|
||||||
|
43
web/views/yandex_auth.py
Normal file
43
web/views/yandex_auth.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from django.contrib.auth import login
|
||||||
|
from requests import post, get
|
||||||
|
|
||||||
|
from BaseLib.BaseView import BaseView
|
||||||
|
from Platform import settings
|
||||||
|
from web.models import CustomUser
|
||||||
|
|
||||||
|
|
||||||
|
class YandexAuthView(BaseView):
|
||||||
|
required_login = False
|
||||||
|
endpoint = "yandex_auth"
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
code = self.request.GET['code']
|
||||||
|
response = post('https://oauth.yandex.ru/token', data={
|
||||||
|
'client_id': '38f1906e99de4810bd79828f420ba885',
|
||||||
|
'client_secret': settings.YANDEX_SERVICE_TOKEN,
|
||||||
|
'grant_type': 'authorization_code',
|
||||||
|
'code': code
|
||||||
|
})
|
||||||
|
if response.status_code != 200:
|
||||||
|
print("Cant access, json: ", response.json())
|
||||||
|
return '/welcome'
|
||||||
|
access_token = response.json().get('access_token')
|
||||||
|
if access_token is None:
|
||||||
|
print('no access token')
|
||||||
|
return '/welcome'
|
||||||
|
info_response = get('https://login.yandex.ru/info', headers={
|
||||||
|
'Authorization': f'OAuth {access_token}'
|
||||||
|
})
|
||||||
|
if info_response.status_code != 200:
|
||||||
|
print("Cant access, json: ", response.json())
|
||||||
|
return '/welcome'
|
||||||
|
data = info_response.json()
|
||||||
|
yandex_id = data['id']
|
||||||
|
if self.request.user.is_authenticated:
|
||||||
|
self.request.user.yandex_id = yandex_id
|
||||||
|
self.request.user.save()
|
||||||
|
else:
|
||||||
|
user = CustomUser.objects.filter(yandex_id=yandex_id).first()
|
||||||
|
if user is not None:
|
||||||
|
login(self.request, user)
|
||||||
|
return '/profile'
|
Loading…
Reference in New Issue
Block a user