Преглед изворни кода

feat: register auth blueprint and update datetime handling in AuthService

Manuel пре 11 месеци
родитељ
комит
d265474c71
2 измењених фајлова са 8 додато и 6 уклоњено
  1. 2 0
      routes/__init__.py
  2. 6 6
      services/auth_service.py

+ 2 - 0
routes/__init__.py

@@ -5,6 +5,7 @@ Contains all route blueprints organized by functionality.
 
 from .admin_routes import admin_bp
 from .api_routes import api_bp
+from .auth_routes import auth_bp
 from .logs_routes import logs_bp
 from .main_routes import main_bp
 from .reports_routes import reports_bp
@@ -14,6 +15,7 @@ from .stats_routes import stats_bp
 def register_routes(app):
     """Register all blueprints with the Flask application."""
     app.register_blueprint(main_bp)
+    app.register_blueprint(auth_bp)
     app.register_blueprint(logs_bp)
     app.register_blueprint(reports_bp)
     app.register_blueprint(admin_bp, url_prefix="/admin")

+ 6 - 6
services/auth_service.py

@@ -7,7 +7,7 @@ Follows security best practices for token-based authentication.
 import hmac
 import os
 import secrets
-from datetime import UTC, datetime, timedelta
+from datetime import datetime, timedelta, timezone
 from functools import wraps
 
 import bcrypt
@@ -82,7 +82,7 @@ class AuthService:
         Check if the user is rate limited.
         Returns tuple of (is_allowed, remaining_attempts).
         """
-        now = datetime.now(UTC)
+        now = datetime.now(timezone.utc)
 
         if identifier in cls._login_attempts:
             attempts, lockout_until = cls._login_attempts[identifier]
@@ -105,7 +105,7 @@ class AuthService:
     @classmethod
     def record_failed_attempt(cls, identifier: str) -> None:
         """Record a failed login attempt."""
-        now = datetime.now(UTC)
+        now = datetime.now(timezone.utc)
 
         if identifier in cls._login_attempts:
             attempts, _ = cls._login_attempts[identifier]
@@ -151,14 +151,14 @@ class AuthService:
 
             if password_match:
                 # Update last login
-                user.last_login = datetime.now(UTC)
+                user.last_login = datetime.now(timezone.utc)
                 session.commit()
 
                 return {
                     "id": user.id,
                     "username": user.username,
                     "role": user.role,
-                    "authenticated_at": datetime.now(UTC).isoformat(),
+                    "authenticated_at": datetime.now(timezone.utc).isoformat(),
                 }
 
             return None
@@ -175,7 +175,7 @@ class AuthService:
         Generate a JWT token for authenticated user.
         Includes security claims like expiration and issued-at times.
         """
-        now = datetime.now(UTC)
+        now = datetime.now(timezone.utc)
 
         payload = {
             # Standard JWT claims