refac
This commit is contained in:
@@ -189,6 +189,32 @@ async def update_profile(
|
|||||||
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
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
|
# Update Password
|
||||||
############################
|
############################
|
||||||
|
|||||||
@@ -423,6 +423,19 @@ export const updateUserProfile = async (token: string, profile: object) => {
|
|||||||
return res;
|
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) => {
|
export const updateUserPassword = async (token: string, password: string, newPassword: string) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,12 @@
|
|||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
|
|
||||||
import { getBackendConfig } from '$lib/apis';
|
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_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
||||||
import { WEBUI_NAME, config, user, socket } from '$lib/stores';
|
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 Spinner from '$lib/components/common/Spinner.svelte';
|
||||||
import OnBoarding from '$lib/components/OnBoarding.svelte';
|
import OnBoarding from '$lib/components/OnBoarding.svelte';
|
||||||
@@ -47,6 +47,12 @@
|
|||||||
await user.set(sessionUser);
|
await user.set(sessionUser);
|
||||||
await config.set(await getBackendConfig());
|
await config.set(await getBackendConfig());
|
||||||
|
|
||||||
|
// Update user timezone
|
||||||
|
const timezone = getUserTimezone();
|
||||||
|
if (sessionUser.token && timezone) {
|
||||||
|
updateUserTimezone(sessionUser.token, timezone);
|
||||||
|
}
|
||||||
|
|
||||||
if (!redirectPath) {
|
if (!redirectPath) {
|
||||||
redirectPath = $page.url.searchParams.get('redirect') || '/';
|
redirectPath = $page.url.searchParams.get('redirect') || '/';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user