Fix password updating

This commit is contained in:
april
2024-01-09 14:41:21 -06:00
parent 955a3e38f3
commit f78be2cf86
2 changed files with 10 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
import logging
from fastapi import APIRouter, HTTPException, Depends
from fastapi import APIRouter, HTTPException, Depends, Request
from pydantic import ValidationError
from app.deps import get_current_user, admin_required
@@ -111,7 +111,8 @@ async def update_profile(body: UserUpdateSchema,
@router.put('/me/password', summary="Update the password of the currently logged-in user", status_code=200)
async def update_password(body: PasswordUpdateSchema, user: UserDisplaySchema = Depends(get_current_user)):
async def update_password(body: PasswordUpdateSchema,
user: UserDisplaySchema = Depends(get_current_user)):
"""
Update the password of the currently logged-in user. Requires password confirmation

View File

@@ -1,7 +1,7 @@
from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field, validator, field_validator
from pydantic import BaseModel, Field, field_validator
def validate_username(value: str):
@@ -56,12 +56,12 @@ class UserCreateSchema(UserBaseSchema):
@field_validator("username")
@classmethod
def _valid_username(cls, value):
validate_username(value)
return validate_username(value)
@field_validator("password")
@classmethod
def _valid_password(cls, value):
validate_password(value)
return validate_password(value)
class UserUpdateSchema(BaseModel):
@@ -71,7 +71,7 @@ class UserUpdateSchema(BaseModel):
@field_validator("username")
@classmethod
def _valid_username(cls, value):
validate_username(value)
return validate_username(value)
class UserDisplaySchema(UserBaseSchema):
@@ -84,13 +84,13 @@ class UserSystemSchema(UserDisplaySchema):
class PasswordUpdateSchema(BaseModel):
current_password: str
new_password: str
current_password: str = ...
new_password: str = ...
@field_validator("new_password")
@classmethod
def _valid_password(cls, value):
validate_password(value)
return validate_password(value)
class TokenSchema(BaseModel):