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