diff --git a/backend/apps/web/models/auths.py b/backend/apps/web/models/auths.py index 2124e6208..367db3ff7 100644 --- a/backend/apps/web/models/auths.py +++ b/backend/apps/web/models/auths.py @@ -67,6 +67,11 @@ class ProfileImageUrlForm(BaseModel): profile_image_url: str +class UpdateProfileForm(BaseModel): + profile_image_url: str + name: str + + class UpdatePasswordForm(BaseModel): password: str new_password: str diff --git a/backend/apps/web/routers/auths.py b/backend/apps/web/routers/auths.py index 6a2f3895f..f45c67ac2 100644 --- a/backend/apps/web/routers/auths.py +++ b/backend/apps/web/routers/auths.py @@ -11,7 +11,7 @@ import uuid from apps.web.models.auths import ( SigninForm, SignupForm, - ProfileImageUrlForm, + UpdateProfileForm, UpdatePasswordForm, UserResponse, SigninResponse, @@ -42,17 +42,18 @@ async def get_session_user(user=Depends(get_current_user)): ############################ -# Update Profile Image Url +# Update Profile ############################ @router.post("/update/profile", response_model=UserResponse) -async def update_profile_image_url( - form_data: ProfileImageUrlForm, session_user=Depends(get_current_user) +async def update_profile( + form_data: UpdateProfileForm, session_user=Depends(get_current_user) ): if session_user: - user = Users.update_user_profile_image_url_by_id( - session_user.id, form_data.profile_image_url + user = Users.update_user_by_id( + session_user.id, + {"profile_image_url": form_data.profile_image_url, "name": form_data.name}, ) if user: return user diff --git a/src/lib/apis/auths/index.ts b/src/lib/apis/auths/index.ts index 8734a5885..5f16f83f5 100644 --- a/src/lib/apis/auths/index.ts +++ b/src/lib/apis/auths/index.ts @@ -89,6 +89,37 @@ export const userSignUp = async (name: string, email: string, password: string) return res; }; +export const updateUserProfile = async (token: string, name: string, profileImageUrl: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/auths/update/profile`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) + }, + body: JSON.stringify({ + name: name, + profile_image_url: profileImageUrl + }) + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .catch((err) => { + console.log(err); + error = err.detail; + return null; + }); + + if (error) { + throw error; + } + + return res; +}; + export const updateUserPassword = async (token: string, password: string, newPassword: string) => { let error = null; diff --git a/src/lib/components/chat/Settings/Account.svelte b/src/lib/components/chat/Settings/Account.svelte new file mode 100644 index 000000000..e9196a1f2 --- /dev/null +++ b/src/lib/components/chat/Settings/Account.svelte @@ -0,0 +1,168 @@ + + +