mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-04-28 19:50:34 +00:00
update
This commit is contained in:
parent
c8a0a21ef2
commit
3f21c2b2c2
83 changed files with 6355 additions and 0 deletions
24
server/app/controller/user/user_password_controller.py
Normal file
24
server/app/controller/user/user_password_controller.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from fastapi import APIRouter, Depends
|
||||
from sqlmodel import Session
|
||||
|
||||
from app.component import code
|
||||
from app.component.auth import Auth, auth_must
|
||||
from app.component.database import session
|
||||
from app.component.encrypt import password_hash, password_verify
|
||||
from app.exception.exception import UserException
|
||||
from app.model.user.user import UpdatePassword, UserOut
|
||||
from fastapi_babel import _
|
||||
|
||||
router = APIRouter(tags=["User"])
|
||||
|
||||
|
||||
@router.put("/user/update-password", name="update password", response_model=UserOut)
|
||||
def update_password(data: UpdatePassword, auth: Auth = Depends(auth_must), session: Session = Depends(session)):
|
||||
model = auth.user
|
||||
if not password_verify(data.password, model.password):
|
||||
raise UserException(code.error, _("Password is incorrect"))
|
||||
if data.new_password != data.re_new_password:
|
||||
raise UserException(code.error, _("The two passwords do not match"))
|
||||
model.password = password_hash(data.new_password)
|
||||
model.save(session)
|
||||
return model
|
||||
Loading…
Add table
Add a link
Reference in a new issue