from app.authentication.backend.application.signin_hub import SignInHub from pydantic import BaseModel from fastapi import APIRouter from infra.token.token_manager import TokenManager from fastapi import APIRouter, Depends from fastapi.encoders import jsonable_encoder from fastapi.responses import JSONResponse from fastapi import Depends, HTTPException from starlette.status import HTTP_401_UNAUTHORIZED router = APIRouter() token_manager = TokenManager() # 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, current_user: dict = Depends(token_manager.get_current_user), ): user_id = current_user.get("id") if not user_id: raise HTTPException( status_code=HTTP_401_UNAUTHORIZED, detail="Could not validate credentials" ) if item.password != item.password2: return JSONResponse( content=jsonable_encoder( {"error": "password and password2 are not the same"} ) ) else: result = await SignInHub().update_user_password(user_id, item.password) return JSONResponse(content=jsonable_encoder(result))