Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ __pycache__/
.coverage
coverage.xml
htmlcov/

# VSCode
.vscode/

# Environment variables
.env
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
- "--rcfile=pyproject.toml"
- "--disable=E0401"
- "--fail-under=8.0"
26 changes: 14 additions & 12 deletions webapi/auth/auth_service.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from fastapi import HTTPException, Depends
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from typing import Optional
from sqlmodel import Session, select
from models.user import User
from db.db_connection import get_session
import re
from datetime import datetime, timedelta
from typing import Optional

import jwt
from fastapi import Depends, HTTPException
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from passlib.hash import sha256_crypt
import re
from dotenv import load_dotenv
from sqlmodel import Session, select

from core import config
from db.db_connection import get_session
from dotenv import load_dotenv
from models.user import User

load_dotenv()

Expand Down Expand Up @@ -43,6 +45,7 @@ def crear_jwt(data: dict):
token = jwt.encode(payload, SECRET_KEY, algorithm="HS256")
return token


# Validar un token con prefijo "Bearer" (compatibilidad legado)
def validar_jwt(token: str):
try:
Expand All @@ -60,7 +63,7 @@ def validar_jwt(token: str):
return None
except jwt.InvalidTokenError:
return None
except Exception:
except Exception: # pylint: disable=broad-exception-caught
return None


Expand All @@ -75,7 +78,7 @@ def validar_jwt_raw(token: str):
return None
except jwt.InvalidTokenError:
return None
except Exception:
except Exception: # pylint: disable=broad-exception-caught
return None


Expand All @@ -90,5 +93,4 @@ def get_current_user(
data = validar_jwt_raw(credentials.credentials)
if not data:
raise HTTPException(status_code=401, detail="Unauthorized token")
return data

return data
12 changes: 6 additions & 6 deletions webapi/db/redis_connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from redis import Redis

from core import config

"""
docker run -d \
--name redis-server \
-p 6379:6379 \
redis/redis-stack:latest
"""
# docker run -d \
# --name redis-server \
# -p 6379:6379 \
# redis/redis-stack:latest


def get_redis():
redis = Redis(
Expand Down
5 changes: 3 additions & 2 deletions webapi/models/prompts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional
from sqlmodel import SQLModel, Field, Relationship
import models

from sqlmodel import Field, Relationship, SQLModel



class Prompts(SQLModel, table=True):
Expand Down
7 changes: 3 additions & 4 deletions webapi/models/user.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from typing import Optional, List

from pydantic import EmailStr
from sqlmodel import SQLModel, Field, Relationship
from sqlalchemy import BIGINT
import models
from sqlmodel import Field, Relationship, SQLModel


class User(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
username: str = Field(max_length=50, index=True, nullable=False)
name: str = Field(max_length=100, index=True, nullable=False)
last_name: str = Field(max_length=100, index=True, nullable=False)
#phone: Optional[int] = Field(default=12, sa_type=BIGINT, index=True, unique=True) # Check why numbers lengh like 10 digits is not working
phone: Optional[int] = Field(default=None, sa_type=BIGINT, index=True, unique=True)
email: EmailStr = Field(max_length=100, nullable=False)
hashed_password: str = Field(max_length=255) # Longer for bcrypt hashes

prompts: List["Prompts"] = Relationship(
sa_relationship_kwargs={"lazy": "selectin"},
sa_relationship_kwargs={"lazy": "selectin"},
back_populates="user"
)