diff --git a/backend/apps/web/models/auths.py b/backend/apps/web/models/auths.py index 1bd4b4cb7..ce0873164 100644 --- a/backend/apps/web/models/auths.py +++ b/backend/apps/web/models/auths.py @@ -64,6 +64,11 @@ class SigninForm(BaseModel): password: str +class UpdatePasswordForm(BaseModel): + password: str + new_password: str + + class SignupForm(BaseModel): name: str email: str @@ -109,7 +114,24 @@ class AuthsTable: except: return None - def delete_auth_by_id(self, id: str) -> Optional[UserModel]: + def update_user_password_by_id( + self, id: str, password: str, new_password: str + ) -> bool: + try: + auth = Auth.get(Auth.id == id, Auth.active == True) + if auth: + if verify_password(password, auth.password): + query = Auth.update(password=new_password).where(Auth.id == id) + result = query.execute() + print(result) + return True + else: + return False + return True + except: + return False + + def delete_auth_by_id(self, id: str) -> bool: try: # Delete User result = Users.delete_user_by_id(id) diff --git a/backend/apps/web/routers/auths.py b/backend/apps/web/routers/auths.py index 27d6a3b6a..31b41b6d2 100644 --- a/backend/apps/web/routers/auths.py +++ b/backend/apps/web/routers/auths.py @@ -11,6 +11,7 @@ import uuid from apps.web.models.auths import ( SigninForm, SignupForm, + UpdatePasswordForm, UserResponse, SigninResponse, Auths, @@ -53,6 +54,24 @@ async def get_session_user(cred=Depends(bearer_scheme)): ) +############################ +# Update Password +############################ + + +@router.post("/update/password", response_model=bool) +async def update_password(form_data: UpdatePasswordForm, cred=Depends(bearer_scheme)): + token = cred.credentials + user = Users.get_user_by_token(token) + + if user: + hashed = get_password_hash(form_data.new_password) + return Auths.update_user_password_by_id(user.id, form_data.password, hashed) + + else: + raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED) + + ############################ # SignIn ############################ diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 05dcefd18..e5332296f 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -118,6 +118,11 @@ let authType = 'Basic'; let authContent = ''; + // Account + let currentPassword = ''; + let newPassword = ''; + let newPasswordConfirm = ''; + // About let ollamaVersion = ''; @@ -1843,6 +1848,67 @@ + {:else if selectedTab === 'account'} +
{:else if selectedTab === 'about'}