This commit is contained in:
Administrator 2023-09-23 19:10:06 +03:00
parent 59aa298db6
commit 53b9f9d840
7 changed files with 53 additions and 5 deletions

View File

@ -1 +1,3 @@
from web.models import *
from web.models import *
from configs.models import *
from experiments.models import *

View File

@ -145,3 +145,5 @@ MINIO_HOST = os.getenv("MINIO_HOST", "localhost") + ":9000"
MINIO_ACCESS_KEY = os.getenv("MINIO_ACCESS_KEY", "serviceminioadmin")
MINIO_SECRET_KEY = os.getenv("MINIO_SECRET_KEY", "minioadmin")
MINIO_BUCKET_NAME = 'platform'
VK_SERVICE_TOKEN = os.getenv("VK_SERVICE_TOKEN", None)

View File

@ -51,8 +51,8 @@
</td>
<td><div style="width: 20px;"></div></td>
<td>
<a href="https://oauth.vk.com/authorize?client_id=8123759&redirect_uri=http://dev.sprinthub.ru/vk_add&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>
{% if account.vk_user_id %}
<a href="https://oauth.vk.com/authorize?client_id=51755815&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>
{% if account.vk_id %}
<div style="margin-top: -15px; margin-left: 30px;"><i style="color: green;" class="fa fa-check-circle"></i></div>
{% endif %}
</td>

11
templates/vk_auth.html Normal file
View File

@ -0,0 +1,11 @@
{% extends 'layouts/base.html' %}
{% block onload %}onLoad();{% endblock %}
{% block javascripts %}
<script>
function onLoad() {
window.location.href = window.location.href.replace('#', '?');
}
</script>
{% endblock %}

View File

@ -10,5 +10,6 @@ urlpatterns = [
path(*ProfileView.as_path()),
path(*ProfilePhoto.as_path()),
path(*LogoutView.as_path()),
path(*PingView.as_path())
path(*PingView.as_path()),
path(*VKAuthView.as_path())
]

View File

@ -4,4 +4,5 @@ from .select_project import SelectProject
from .profile import ProfileView
from .profile_photo import ProfilePhoto
from .logout import LogoutView
from .ping import PingView
from .ping import PingView
from .vk_auth import VKAuthView

31
web/views/vk_auth.py Normal file
View File

@ -0,0 +1,31 @@
from requests import get
from BaseLib.BaseView import BaseView
from Platform import settings
class VKAuthView(BaseView):
required_login = True
endpoint = "vk_auth"
view_file = "vk_auth.html"
fields_except = ('user_id',)
def get(self):
access_token = self.request.GET.get('access_token')
if access_token is None:
if self.request.GET.get("error") == "access_denied":
return "/profile"
return
token = settings.VK_SERVICE_TOKEN
resp = get(f'https://api.vk.com/method/secure.checkToken?token={access_token}&access_token={token}&v=5.131').json()
print(resp)
if 'response' in resp and 'success' in resp['response'] and resp['response']['success'] == 1:
user_id = resp['response']['user_id']
resp = get(f'https://api.vk.com/method/users.get?access_token={token}&user_ids={user_id}&v=5.131',
headers={"accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7"})
if resp.status_code != 200:
return "/profile"
data = resp.json()['response'][0]
self.request.user.vk_id = data['id']
self.request.user.save()
return "/profile"