fix everything
This commit is contained in:
parent
57031ff64b
commit
71ee91340f
@ -7,7 +7,6 @@ from web.models import CustomUser
|
|||||||
|
|
||||||
|
|
||||||
class YandexAuthView(BaseView):
|
class YandexAuthView(BaseView):
|
||||||
required_login = False
|
|
||||||
endpoint = "yandex_auth"
|
endpoint = "yandex_auth"
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
@ -19,26 +18,26 @@ class YandexAuthView(BaseView):
|
|||||||
'code': code
|
'code': code
|
||||||
})
|
})
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise Exception("Cant access, json: " + str(response.json()))
|
print("Cant access, json: " + str(response.json()))
|
||||||
return '/welcome'
|
return '/welcome'
|
||||||
access_token = response.json().get('access_token')
|
access_token = response.json().get('access_token')
|
||||||
if access_token is None:
|
if access_token is None:
|
||||||
raise Exception('no access token')
|
print('no access token')
|
||||||
return '/welcome'
|
return '/welcome'
|
||||||
info_response = get('https://login.yandex.ru/info', headers={
|
info_response = get('https://login.yandex.ru/info', headers={
|
||||||
'Authorization': f'OAuth {access_token}'
|
'Authorization': f'OAuth {access_token}'
|
||||||
})
|
})
|
||||||
if info_response.status_code != 200:
|
if info_response.status_code != 200:
|
||||||
raise Exception("Cant access, json: " + str(response.json()))
|
print("Cant access, json: " + str(response.json()))
|
||||||
return '/welcome'
|
return '/welcome'
|
||||||
data = info_response.json()
|
data = info_response.json()
|
||||||
yandex_id = data['id']
|
yandex_id = data['id']
|
||||||
if self.request.user.is_authenticated:
|
if self.request.user.is_authenticated:
|
||||||
raise Exception('Got yandex_id %s writing to db' + str(yandex_id) + " " + type(yandex_id))
|
print('Got yandex_id %s writing to db' + str(yandex_id) + " " + type(yandex_id))
|
||||||
self.request.user.yandex_id = yandex_id
|
self.request.user.yandex_id = yandex_id
|
||||||
self.request.user.save()
|
self.request.user.save()
|
||||||
else:
|
else:
|
||||||
raise Exception('Got yandex_id %s logging in' + str(yandex_id) + " " + type(yandex_id))
|
print('Got yandex_id %s logging in' + str(yandex_id) + " " + type(yandex_id))
|
||||||
user = CustomUser.objects.filter(yandex_id=yandex_id).first()
|
user = CustomUser.objects.filter(yandex_id=yandex_id).first()
|
||||||
if user is not None:
|
if user is not None:
|
||||||
login(self.request, user)
|
login(self.request, user)
|
||||||
|
Loading…
Reference in New Issue
Block a user