feat: add ability to change password
This commit is contained in:
18
security.py
18
security.py
@@ -256,22 +256,28 @@ async def set_first_password(req: FirstPassword):
|
||||
raise credentials_exception
|
||||
|
||||
|
||||
class ChangedPassword(BaseModel):
|
||||
current_password: str
|
||||
new_password: str
|
||||
|
||||
|
||||
async def change_password(
|
||||
current_password: str,
|
||||
new_password: str,
|
||||
request: ChangedPassword,
|
||||
user: Annotated[Player, Depends(get_current_active_user)],
|
||||
):
|
||||
if (
|
||||
new_password
|
||||
request.new_password
|
||||
and user.hashed_password
|
||||
and verify_password(current_password, user.hashed_password)
|
||||
and verify_password(request.current_password, user.hashed_password)
|
||||
):
|
||||
with Session(engine) as session:
|
||||
user.hashed_password = get_password_hash(new_password)
|
||||
user.hashed_password = get_password_hash(request.new_password)
|
||||
session.add(user)
|
||||
session.commit()
|
||||
return PlainTextResponse(
|
||||
"Password changed successfully", status_code=status.HTTP_200_OK
|
||||
"Password changed successfully",
|
||||
status_code=status.HTTP_200_OK,
|
||||
media_type="text/plain",
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
|
||||
Reference in New Issue
Block a user