This commit is contained in:
Timothy Jaeryang Baek
2026-01-09 18:51:38 +04:00
parent 10838b3654
commit 401c1949a0
3 changed files with 47 additions and 2 deletions

View File

@@ -189,6 +189,32 @@ async def update_profile(
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
############################
# Update Timezone
############################
class UpdateTimezoneForm(BaseModel):
timezone: str
@router.post("/update/timezone")
async def update_timezone(
form_data: UpdateTimezoneForm,
session_user=Depends(get_current_user),
db: Session = Depends(get_session),
):
if session_user:
Users.update_user_by_id(
session_user.id,
{"timezone": form_data.timezone},
db=db,
)
return {"status": True}
else:
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
############################
# Update Password
############################

View File

@@ -423,6 +423,19 @@ export const updateUserProfile = async (token: string, profile: object) => {
return res;
};
export const updateUserTimezone = async (token: string, timezone: string) => {
await fetch(`${WEBUI_API_BASE_URL}/auths/update/timezone`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(token && { authorization: `Bearer ${token}` })
},
body: JSON.stringify({ timezone })
}).catch((err) => {
console.error('Failed to update timezone:', err);
});
};
export const updateUserPassword = async (token: string, password: string, newPassword: string) => {
let error = null;

View File

@@ -9,12 +9,12 @@
import { page } from '$app/stores';
import { getBackendConfig } from '$lib/apis';
import { ldapUserSignIn, getSessionUser, userSignIn, userSignUp } from '$lib/apis/auths';
import { ldapUserSignIn, getSessionUser, userSignIn, userSignUp, updateUserTimezone } from '$lib/apis/auths';
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
import { WEBUI_NAME, config, user, socket } from '$lib/stores';
import { generateInitialsImage, canvasPixelTest } from '$lib/utils';
import { generateInitialsImage, canvasPixelTest, getUserTimezone } from '$lib/utils';
import Spinner from '$lib/components/common/Spinner.svelte';
import OnBoarding from '$lib/components/OnBoarding.svelte';
@@ -47,6 +47,12 @@
await user.set(sessionUser);
await config.set(await getBackendConfig());
// Update user timezone
const timezone = getUserTimezone();
if (sessionUser.token && timezone) {
updateUserTimezone(sessionUser.token, timezone);
}
if (!redirectPath) {
redirectPath = $page.url.searchParams.get('redirect') || '/';
}