Fix login blocked by registration password validation
Split UserCreate into UserCreate (with min_length constraints) and UserLogin (no constraints) so existing short passwords can still log in. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,11 @@ class UserCreate(BaseModel):
|
||||
password: str = Field(min_length=8)
|
||||
|
||||
|
||||
class UserLogin(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
|
||||
|
||||
class Token(BaseModel):
|
||||
access_token: str
|
||||
token_type: str
|
||||
@@ -37,7 +42,7 @@ def register(user_in: UserCreate, db: Session = Depends(get_db)):
|
||||
|
||||
|
||||
@router.post("/login", response_model=Token)
|
||||
def login(user_in: UserCreate, db: Session = Depends(get_db)):
|
||||
def login(user_in: UserLogin, db: Session = Depends(get_db)):
|
||||
user = db.query(models.User).filter(models.User.username == user_in.username).first()
|
||||
if not user or not verify_password(user_in.password, user.password):
|
||||
raise HTTPException(status_code=401, detail="Invalid credentials")
|
||||
|
||||
Reference in New Issue
Block a user