2022-04-15 14:24:30 +00:00
|
|
|
|
<template>
|
2022-04-21 22:51:48 +00:00
|
|
|
|
<form data-testid="update-profile-form" @submit.prevent="update">
|
2024-03-30 16:49:25 +00:00
|
|
|
|
<AlertBox v-if="currentUser.sso_provider">
|
2024-03-31 17:19:03 +00:00
|
|
|
|
<template v-if="currentUser.sso_provider === 'Reverse Proxy'">
|
|
|
|
|
You’re authenticated by a reverse proxy.
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
2024-04-01 10:02:22 +00:00
|
|
|
|
You’re logging in via single sign-on provided by <strong>{{ currentUser.sso_provider }}</strong>.
|
2024-03-31 17:19:03 +00:00
|
|
|
|
</template>
|
2024-03-30 16:49:25 +00:00
|
|
|
|
You can still update your name and avatar here.
|
|
|
|
|
</AlertBox>
|
2024-04-04 22:20:42 +00:00
|
|
|
|
|
|
|
|
|
<div class="flex flex-col gap-3 md:flex-row md:gap-8 w-full md:w-[640px]">
|
|
|
|
|
<div class="flex-1 space-y-5">
|
|
|
|
|
<FormRow v-if="!currentUser.sso_provider">
|
|
|
|
|
<template #label>Current Password</template>
|
|
|
|
|
<TextInput
|
|
|
|
|
v-model="profile.current_password"
|
|
|
|
|
v-koel-focus
|
2024-04-23 21:01:27 +00:00
|
|
|
|
data-testid="currentPassword"
|
2024-04-04 22:20:42 +00:00
|
|
|
|
name="current_password"
|
|
|
|
|
placeholder="Required to update your profile"
|
|
|
|
|
required
|
|
|
|
|
type="password"
|
|
|
|
|
/>
|
|
|
|
|
</FormRow>
|
|
|
|
|
|
|
|
|
|
<FormRow>
|
|
|
|
|
<template #label>Name</template>
|
|
|
|
|
<TextInput v-model="profile.name" data-testid="name" name="name" />
|
|
|
|
|
</FormRow>
|
|
|
|
|
|
|
|
|
|
<FormRow>
|
|
|
|
|
<template #label>Email Address</template>
|
|
|
|
|
<TextInput
|
|
|
|
|
id="inputProfileEmail"
|
|
|
|
|
v-model="profile.email"
|
|
|
|
|
:readonly="currentUser.sso_provider"
|
|
|
|
|
data-testid="email"
|
|
|
|
|
name="email"
|
|
|
|
|
required
|
|
|
|
|
type="email"
|
|
|
|
|
/>
|
|
|
|
|
</FormRow>
|
|
|
|
|
|
|
|
|
|
<FormRow v-if="!currentUser.sso_provider">
|
|
|
|
|
<template #label>New Password</template>
|
|
|
|
|
<PasswordField
|
|
|
|
|
v-model="profile.new_password"
|
|
|
|
|
autocomplete="new-password"
|
|
|
|
|
data-testid="newPassword"
|
|
|
|
|
minlength="10"
|
|
|
|
|
placeholder="Leave empty to keep current password"
|
|
|
|
|
/>
|
|
|
|
|
<template #help>Min. 10 characters. Should be a mix of characters, numbers, and symbols.</template>
|
|
|
|
|
</FormRow>
|
2024-03-19 22:48:12 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<div>
|
|
|
|
|
<EditableProfileAvatar :profile="profile" />
|
|
|
|
|
</div>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<footer class="mt-8">
|
2022-04-21 22:51:48 +00:00
|
|
|
|
<Btn class="btn-submit" type="submit">Save</Btn>
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<span v-if="isDemo" class="text-[.95rem] opacity-70 ml-2">
|
2022-04-15 14:24:30 +00:00
|
|
|
|
Changes will not be saved in the demo version.
|
|
|
|
|
</span>
|
2024-04-04 22:20:42 +00:00
|
|
|
|
</footer>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</form>
|
|
|
|
|
</template>
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
<script lang="ts" setup>
|
2022-07-07 18:05:46 +00:00
|
|
|
|
import { onMounted, ref } from 'vue'
|
2024-01-18 11:13:05 +00:00
|
|
|
|
import { authService, UpdateCurrentProfileData } from '@/services'
|
2024-04-23 21:01:27 +00:00
|
|
|
|
import { useAuthorization, useErrorHandler, useMessageToaster } from '@/composables'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
|
import Btn from '@/components/ui/form/Btn.vue'
|
|
|
|
|
import PasswordField from '@/components/ui/form/PasswordField.vue'
|
2024-03-19 22:48:12 +00:00
|
|
|
|
import EditableProfileAvatar from '@/components/profile-preferences/EditableProfileAvatar.vue'
|
2024-03-30 16:49:25 +00:00
|
|
|
|
import AlertBox from '@/components/ui/AlertBox.vue'
|
2024-04-04 22:20:42 +00:00
|
|
|
|
import TextInput from '@/components/ui/form/TextInput.vue'
|
|
|
|
|
import FormRow from '@/components/ui/form/FormRow.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-11-18 17:45:38 +00:00
|
|
|
|
const { toastSuccess } = useMessageToaster()
|
2024-04-23 11:24:29 +00:00
|
|
|
|
const { currentUser } = useAuthorization()
|
2024-03-19 22:48:12 +00:00
|
|
|
|
const profile = ref<UpdateCurrentProfileData>({} as UpdateCurrentProfileData)
|
2024-02-28 04:37:27 +00:00
|
|
|
|
const isDemo = window.IS_DEMO
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
onMounted(() => {
|
|
|
|
|
profile.value = {
|
2024-03-30 16:49:25 +00:00
|
|
|
|
name: currentUser.value.name,
|
|
|
|
|
email: currentUser.value.email,
|
|
|
|
|
avatar: currentUser.value.avatar,
|
2022-04-15 17:00:08 +00:00
|
|
|
|
current_password: null
|
2022-04-15 14:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
|
|
|
|
const update = async () => {
|
|
|
|
|
if (!profile.value) {
|
|
|
|
|
throw Error()
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 04:37:27 +00:00
|
|
|
|
if (isDemo) {
|
2022-11-18 17:45:38 +00:00
|
|
|
|
toastSuccess('Profile updated.')
|
2022-04-29 20:15:10 +00:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
try {
|
2024-01-18 11:13:05 +00:00
|
|
|
|
await authService.updateProfile(Object.assign({}, profile.value))
|
2022-04-15 17:00:08 +00:00
|
|
|
|
profile.value.current_password = null
|
|
|
|
|
delete profile.value.new_password
|
2022-11-18 17:45:38 +00:00
|
|
|
|
toastSuccess('Profile updated.')
|
2024-04-23 11:24:29 +00:00
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
useErrorHandler('dialog').handleHttpError(error)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</script>
|