hit
- Dominant language
- JavaScript
- Stars
- 11
- Forks
- 38
- PR merge metrics
- No merged PRs in 30d
Description
import hashlib
from fastapi import Header, Depends
# ... (código anterior)
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
username = Column(String, unique=True)
password_hash = Column(String)
Base.metadata.create_all(engine)
# Utilitário para Senha
def hash_password(password: str):
return hashlib.sha256(password.encode()).hexdigest()
# Dependência de Segurança
def get_current_user(auth_token: str = Header(None)):
if not auth_token:
raise HTTPException(status_code=401, detail="Token ausente")
session = Session()
user = session.query(User).filter_by(username=auth_token).first() # Simplificado para o exemplo
if not user:
raise HTTPException(status_code=401, detail="Usuário inválido")
return user
@app.post("/auth/register")
def register(username: str, password: str):
session = Session()
new_user = User(username=username, password_hash=hash_password(password))
session.add(new_user)
session.commit()
return {"status": "Usuário criado"}
@app.post("/auth/login")
def login(username: str, password: str):
session = Session()
user = session.query(User).filter_by(username=username, password_hash=hash_password(password)).first()
if not user:
raise HTTPException(status_code=401, detail="Credenciais incorretas")
return {"token": user.username} # Em produção, use um JWT real
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue mentions the /auth/register and /auth/login entry points, but no file, test, requested change, or acceptance criteria. First clarify the intended authentication work and review the surrounding application before implementation; completion cannot be defined from the current issue text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, authentication, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 10/100