Skip to content

Commit

Permalink
debuggg
Browse files Browse the repository at this point in the history
Signed-off-by: viste <[email protected]>
  • Loading branch information
Viste committed Aug 20, 2024
1 parent 3ad4c88 commit 1ce3fff
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions core/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,30 @@ def login_vk():
def authorize_vk():
try:
token = vk.authorize_access_token()
if not token:
flash('Failed to retrieve token from VK', 'danger')
return redirect(url_for('login'))

print(f'Token: {token}')

access_token = token.get('access_token')
if not access_token:
flash('Failed to retrieve access token from VK', 'danger')
flash('Access token is missing in the VK response', 'danger')
return redirect(url_for('login'))

print(f'Token received: {token}')

resp = vk.get(
'https://api.vk.com/method/users.get',
token={'access_token': access_token, 'v': '5.131'},
params={
'access_token': access_token,
'v': '5.131',
'fields': 'id,first_name,last_name,screen_name,photo_100,email'
}
)

print(f'Response from VK: {resp.json()}')

profile = resp.json().get('response', [])[0]
if profile is None:
if not profile:
flash('Failed to retrieve user profile from VK', 'danger')
return redirect(url_for('login'))

Expand All @@ -170,17 +177,17 @@ def authorize_vk():
profile_picture = profile.get('photo_100', '')
email = token.get('email')

# Авторизуем пользователя в системе
authenticate_vk_user(vk_id, screen_name, first_name, last_name, profile_picture, email)

flash(f'Successfully logged in as {screen_name}', 'success')
return redirect(url_for('index'))

except Exception as e:
print(f'Error during VK authorization: {e}') # Логирование ошибки
print(f'Error during VK authorization: {e}')
flash('Authorization failed. Please try again.', 'danger')
return redirect(url_for('login'))


@app.route('/logout')
@login_required
def logout():
Expand Down

0 comments on commit 1ce3fff

Please sign in to comment.