from backend.application.user.user_manager import UserManager from pydantic import BaseModel from fastapi import APIRouter, Security from backend.infra.authentication.auth import access_security from fastapi_jwt import JwtAuthorizationCredentials from fastapi.encoders import jsonable_encoder from fastapi.responses import JSONResponse router = APIRouter() # Web API # update_user_password # class RequestIn(BaseModel): password: str password2: str @router.post( "/update-user-password", operation_id="user_update_user_password", summary="updathe user's sign-in password", description="Update the user's sign-in password. If the password was not set yet, this will enable the user to log in using the password", response_description="signin_type:0 meaning simplified(using email) signin, \ 1 meaning standard(using FLID and passward) signin", ) async def update_user_password( item: RequestIn, credentials: JwtAuthorizationCredentials = Security(access_security), ): user_id = credentials["id"] if item.password != item.password2: return JSONResponse( content=jsonable_encoder( {"error": "password and password2 are not the same"} ) ) else: result = await UserManager().update_user_password(user_id, item.password) return JSONResponse(content=jsonable_encoder(result))