refactor: clean up code by adding missing commas and improving import order

This commit is contained in:
JSC
2025-07-02 10:46:53 +02:00
parent 171dbb9b63
commit 703212656f
20 changed files with 87 additions and 496 deletions

View File

@@ -31,7 +31,7 @@ def callback(provider):
# If successful, redirect to frontend dashboard with cookies
if auth_response.status_code == 200:
redirect_response = make_response(
redirect("http://localhost:3000/dashboard")
redirect("http://localhost:3000/dashboard"),
)
# Copy all cookies from the auth response
@@ -39,9 +39,8 @@ def callback(provider):
redirect_response.headers.add("Set-Cookie", cookie)
return redirect_response
else:
# If there was an error, redirect to login with error
return redirect("http://localhost:3000/login?error=oauth_failed")
# If there was an error, redirect to login with error
return redirect("http://localhost:3000/login?error=oauth_failed")
except Exception as e:
error_msg = str(e).replace(" ", "_").replace('"', "")
@@ -129,7 +128,7 @@ def refresh():
def link_provider(provider):
"""Link a new OAuth provider to current user account."""
redirect_uri = url_for(
"auth.link_callback", provider=provider, _external=True
"auth.link_callback", provider=provider, _external=True,
)
return auth_service.redirect_to_login(provider, redirect_uri)
@@ -168,19 +167,19 @@ def link_callback(provider):
if not provider_data.get("id"):
return {
"error": "Failed to get user information from provider"
"error": "Failed to get user information from provider",
}, 400
# Check if this provider is already linked to another user
from app.models.user_oauth import UserOAuth
existing_provider = UserOAuth.find_by_provider_and_id(
provider, provider_data["id"]
provider, provider_data["id"],
)
if existing_provider and existing_provider.user_id != user.id:
return {
"error": "This provider account is already linked to another user"
"error": "This provider account is already linked to another user",
}, 409
# Link the provider to current user
@@ -210,7 +209,6 @@ def unlink_provider(provider):
from app.database import db
from app.models.user import User
from app.models.user_oauth import UserOAuth
user = User.query.get(current_user_id)
if not user:
@@ -224,7 +222,7 @@ def unlink_provider(provider):
oauth_provider = user.get_provider(provider)
if not oauth_provider:
return {
"error": f"Provider '{provider}' not linked to this account"
"error": f"Provider '{provider}' not linked to this account",
}, 404
db.session.delete(oauth_provider)
@@ -279,6 +277,7 @@ def me():
def update_profile():
"""Update current user profile information."""
from flask import request
from app.database import db
from app.models.user import User
@@ -323,7 +322,7 @@ def update_profile():
return {"message": "Profile updated successfully", "user": updated_user}
except Exception as e:
db.session.rollback()
return {"error": f"Failed to update profile: {str(e)}"}, 500
return {"error": f"Failed to update profile: {e!s}"}, 500
@bp.route("/password", methods=["PUT"])
@@ -331,9 +330,10 @@ def update_profile():
def change_password():
"""Change or set user password."""
from flask import request
from werkzeug.security import check_password_hash
from app.database import db
from app.models.user import User
from werkzeug.security import check_password_hash
data = request.get_json()
if not data:
@@ -365,7 +365,7 @@ def change_password():
# User has a password AND logged in via password, require current password for verification
if not current_password:
return {
"error": "Current password is required to change password"
"error": "Current password is required to change password",
}, 400
if not check_password_hash(user.password_hash, current_password):
@@ -380,4 +380,4 @@ def change_password():
return {"message": "Password updated successfully"}
except Exception as e:
db.session.rollback()
return {"error": f"Failed to update password: {str(e)}"}, 500
return {"error": f"Failed to update password: {e!s}"}, 500