Skip to content

Commit

Permalink
update auth
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 c8ef455 commit 55c3fb6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tools/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ def authenticate_user(username, password):

def authenticate_vk_user(vk_id, screen_name, first_name, last_name, profile_picture, email):
user = User.query.filter_by(vk_id=vk_id).first()

if not user:
current_app.logger.debug(f"Creating a new VK user with ID: {vk_id}")
user = User(username=screen_name, vk_id=vk_id, first_name=first_name, last_name=last_name,
profile_picture=profile_picture, email=email, provider='vk')
db.session.add(user)
db.session.commit()

try:
db.session.commit() # Фиксируем транзакцию
current_app.logger.debug(f"New VK user created and committed to the database with ID: {user.id}")
except Exception as e:
current_app.logger.error(f"Failed to commit new VK user to the database. Error: {e}")
db.session.rollback() # Откатываем транзакцию в случае ошибки
return False

session['loggedin'] = True
session['id'] = user.id
session['username'] = user.username
Expand Down

0 comments on commit 55c3fb6

Please sign in to comment.