auth
This commit is contained in:
parent
816a6abe53
commit
125eaf7f58
@ -19,7 +19,7 @@
|
||||
</form>
|
||||
</div>
|
||||
или войти с помощью<br><br>
|
||||
<a href="#"><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>
|
||||
</div>
|
||||
</center>
|
||||
|
@ -1,11 +1,12 @@
|
||||
from django.contrib.auth import login
|
||||
from requests import get
|
||||
|
||||
from BaseLib.BaseView import BaseView
|
||||
from Platform import settings
|
||||
from web.models import CustomUser
|
||||
|
||||
|
||||
class VKAuthView(BaseView):
|
||||
required_login = True
|
||||
endpoint = "vk_auth"
|
||||
view_file = "vk_auth.html"
|
||||
fields_except = ('user_id',)
|
||||
@ -26,6 +27,12 @@ class VKAuthView(BaseView):
|
||||
if resp.status_code != 200:
|
||||
return "/profile"
|
||||
data = resp.json()['response'][0]
|
||||
self.request.user.vk_id = data['id']
|
||||
self.request.user.save()
|
||||
if self.request.user.is_authenticated:
|
||||
self.request.user.vk_id = data['id']
|
||||
self.request.user.save()
|
||||
else:
|
||||
user = CustomUser.objects.filter(vk_id=data['id']).first()
|
||||
if user is None:
|
||||
return '/welcome'
|
||||
login(self.request, user)
|
||||
return "/profile"
|
||||
|
Loading…
Reference in New Issue
Block a user