2025-08-04 16:33:07 +03:30
|
|
|
<!-- ❗Errors in the form are set on line 60 -->
|
|
|
|
|
<script setup>
|
|
|
|
|
import { VForm } from 'vuetify/components/VForm'
|
|
|
|
|
import AuthProvider from '@/views/pages/authentication/AuthProvider.vue'
|
|
|
|
|
import { useGenerateImageVariant } from '@core/composable/useGenerateImageVariant'
|
|
|
|
|
import authV2LoginIllustrationBorderedDark from '@images/pages/auth-v2-login-illustration-bordered-dark.png'
|
|
|
|
|
import authV2LoginIllustrationBorderedLight from '@images/pages/auth-v2-login-illustration-bordered-light.png'
|
|
|
|
|
import authV2LoginIllustrationDark from '@images/pages/auth-v2-login-illustration-dark.png'
|
|
|
|
|
import authV2LoginIllustrationLight from '@images/pages/auth-v2-login-illustration-light.png'
|
|
|
|
|
import authV2MaskDark from '@images/pages/misc-mask-dark.png'
|
|
|
|
|
import authV2MaskLight from '@images/pages/misc-mask-light.png'
|
|
|
|
|
import { VNodeRenderer } from '@layouts/components/VNodeRenderer'
|
|
|
|
|
import { themeConfig } from '@themeConfig'
|
|
|
|
|
|
|
|
|
|
const authThemeImg = useGenerateImageVariant(authV2LoginIllustrationLight, authV2LoginIllustrationDark, authV2LoginIllustrationBorderedLight, authV2LoginIllustrationBorderedDark, true)
|
|
|
|
|
const authThemeMask = useGenerateImageVariant(authV2MaskLight, authV2MaskDark)
|
|
|
|
|
|
|
|
|
|
definePage({
|
|
|
|
|
meta: {
|
|
|
|
|
layout: 'blank',
|
|
|
|
|
unauthenticatedOnly: true,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const isPasswordVisible = ref(false)
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const ability = useAbility()
|
|
|
|
|
|
|
|
|
|
const errors = ref({
|
|
|
|
|
email: undefined,
|
|
|
|
|
password: undefined,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const refVForm = ref()
|
|
|
|
|
|
|
|
|
|
const credentials = ref({
|
|
|
|
|
email: 'admin@demo.com',
|
|
|
|
|
password: 'admin',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const rememberMe = ref(false)
|
|
|
|
|
|
2025-08-25 12:19:58 +03:30
|
|
|
const loginDirect = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const fakeUserData = {
|
|
|
|
|
id: 1,
|
|
|
|
|
fullName: 'Admin User',
|
|
|
|
|
username: 'admin',
|
|
|
|
|
email: 'admin@demo.com',
|
|
|
|
|
role: 'admin'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fakeAbilityRules = [
|
|
|
|
|
{
|
|
|
|
|
action: 'manage',
|
|
|
|
|
subject: 'all'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const fakeAccessToken = 'fake-access-token-for-development'
|
|
|
|
|
|
|
|
|
|
useCookie('userAbilityRules').value = fakeAbilityRules
|
|
|
|
|
ability.update(fakeAbilityRules)
|
|
|
|
|
useCookie('userData').value = fakeUserData
|
|
|
|
|
useCookie('accessToken').value = fakeAccessToken
|
|
|
|
|
|
|
|
|
|
await nextTick(() => {
|
|
|
|
|
router.replace(route.query.to ? String(route.query.to) : '/')
|
|
|
|
|
})
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const loginAlwaysSuccess = async () => {
|
|
|
|
|
try {
|
|
|
|
|
/*
|
|
|
|
|
const res = await $api('/auth/login', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: {
|
|
|
|
|
email: credentials.value.email,
|
|
|
|
|
password: credentials.value.password,
|
|
|
|
|
},
|
|
|
|
|
onResponseError({ response }) {
|
|
|
|
|
// errors رو ignore میکنیم
|
|
|
|
|
console.log('Auth error ignored:', response._data.errors)
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const userData = {
|
|
|
|
|
id: 1,
|
|
|
|
|
fullName: 'Demo User',
|
|
|
|
|
username: 'demo',
|
|
|
|
|
email: credentials.value.email,
|
|
|
|
|
role: 'admin'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const userAbilityRules = [
|
|
|
|
|
{
|
|
|
|
|
action: 'manage',
|
|
|
|
|
subject: 'all'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const accessToken = 'demo-access-token'
|
|
|
|
|
|
|
|
|
|
useCookie('userAbilityRules').value = userAbilityRules
|
|
|
|
|
ability.update(userAbilityRules)
|
|
|
|
|
useCookie('userData').value = userData
|
|
|
|
|
useCookie('accessToken').value = accessToken
|
|
|
|
|
|
|
|
|
|
await nextTick(() => {
|
|
|
|
|
router.replace(route.query.to ? String(route.query.to) : '/')
|
|
|
|
|
})
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err)
|
|
|
|
|
loginDirect()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 16:33:07 +03:30
|
|
|
const login = async () => {
|
2025-08-25 12:19:58 +03:30
|
|
|
if (process.env.NODE_ENV === 'development' || import.meta.env.DEV) {
|
|
|
|
|
return loginDirect()
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 16:33:07 +03:30
|
|
|
try {
|
|
|
|
|
const res = await $api('/auth/login', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: {
|
|
|
|
|
email: credentials.value.email,
|
|
|
|
|
password: credentials.value.password,
|
|
|
|
|
},
|
|
|
|
|
onResponseError({ response }) {
|
|
|
|
|
errors.value = response._data.errors
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const { accessToken, userData, userAbilityRules } = res
|
|
|
|
|
|
|
|
|
|
useCookie('userAbilityRules').value = userAbilityRules
|
|
|
|
|
ability.update(userAbilityRules)
|
|
|
|
|
useCookie('userData').value = userData
|
|
|
|
|
useCookie('accessToken').value = accessToken
|
|
|
|
|
await nextTick(() => {
|
|
|
|
|
router.replace(route.query.to ? String(route.query.to) : '/')
|
|
|
|
|
})
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onSubmit = () => {
|
2025-08-25 12:19:58 +03:30
|
|
|
login()
|
|
|
|
|
|
|
|
|
|
|
2025-08-04 16:33:07 +03:30
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<RouterLink to="/">
|
|
|
|
|
<div class="auth-logo d-flex align-center gap-x-3">
|
|
|
|
|
<VNodeRenderer :nodes="themeConfig.app.logo" />
|
|
|
|
|
<h1 class="auth-title">
|
|
|
|
|
{{ themeConfig.app.title }}
|
|
|
|
|
</h1>
|
|
|
|
|
</div>
|
|
|
|
|
</RouterLink>
|
|
|
|
|
|
2025-08-25 12:19:58 +03:30
|
|
|
<VRow no-gutters class="auth-wrapper bg-surface">
|
|
|
|
|
<VCol md="8" class="d-none d-md-flex">
|
2025-08-04 16:33:07 +03:30
|
|
|
<div class="position-relative bg-background w-100 me-0">
|
|
|
|
|
<div
|
|
|
|
|
class="d-flex align-center justify-center w-100 h-100"
|
2025-08-25 12:19:58 +03:30
|
|
|
style="padding-inline: 6.25rem"
|
2025-08-04 16:33:07 +03:30
|
|
|
>
|
|
|
|
|
<VImg
|
|
|
|
|
max-width="613"
|
|
|
|
|
:src="authThemeImg"
|
|
|
|
|
class="auth-illustration mt-16 mb-2"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<img
|
|
|
|
|
class="auth-footer-mask"
|
|
|
|
|
:src="authThemeMask"
|
|
|
|
|
alt="auth-footer-mask"
|
|
|
|
|
height="280"
|
|
|
|
|
width="100"
|
2025-08-25 12:19:58 +03:30
|
|
|
/>
|
2025-08-04 16:33:07 +03:30
|
|
|
</div>
|
|
|
|
|
</VCol>
|
|
|
|
|
|
|
|
|
|
<VCol
|
|
|
|
|
cols="12"
|
|
|
|
|
md="4"
|
|
|
|
|
class="auth-card-v2 d-flex align-center justify-center"
|
|
|
|
|
>
|
2025-08-25 12:19:58 +03:30
|
|
|
<VCard flat :max-width="500" class="mt-12 mt-sm-0 pa-4">
|
2025-08-04 16:33:07 +03:30
|
|
|
<VCardText>
|
|
|
|
|
<h4 class="text-h4 mb-1">
|
2025-08-25 12:19:58 +03:30
|
|
|
Welcome to
|
|
|
|
|
<span class="text-capitalize"> {{ themeConfig.app.title }} </span>!
|
|
|
|
|
|
2025-08-04 16:33:07 +03:30
|
|
|
</h4>
|
|
|
|
|
<p class="mb-0">
|
|
|
|
|
Please sign-in to your account and start the adventure
|
|
|
|
|
</p>
|
|
|
|
|
</VCardText>
|
|
|
|
|
<VCardText>
|
2025-08-25 12:19:58 +03:30
|
|
|
<VForm ref="refVForm" @submit.prevent="onSubmit">
|
2025-08-04 16:33:07 +03:30
|
|
|
<VRow>
|
|
|
|
|
<!-- email -->
|
|
|
|
|
<VCol cols="12">
|
|
|
|
|
<AppTextField
|
|
|
|
|
v-model="credentials.email"
|
|
|
|
|
label="Email"
|
|
|
|
|
placeholder="johndoe@email.com"
|
|
|
|
|
type="email"
|
|
|
|
|
autofocus
|
|
|
|
|
:rules="[requiredValidator, emailValidator]"
|
|
|
|
|
:error-messages="errors.email"
|
|
|
|
|
/>
|
|
|
|
|
</VCol>
|
|
|
|
|
|
|
|
|
|
<!-- password -->
|
|
|
|
|
<VCol cols="12">
|
|
|
|
|
<AppTextField
|
|
|
|
|
v-model="credentials.password"
|
|
|
|
|
label="Password"
|
|
|
|
|
placeholder="············"
|
|
|
|
|
:rules="[requiredValidator]"
|
|
|
|
|
:type="isPasswordVisible ? 'text' : 'password'"
|
|
|
|
|
autocomplete="password"
|
|
|
|
|
:error-messages="errors.password"
|
2025-08-25 12:19:58 +03:30
|
|
|
:append-inner-icon="
|
|
|
|
|
isPasswordVisible ? 'tabler-eye-off' : 'tabler-eye'
|
|
|
|
|
"
|
2025-08-04 16:33:07 +03:30
|
|
|
@click:append-inner="isPasswordVisible = !isPasswordVisible"
|
|
|
|
|
/>
|
|
|
|
|
|
2025-08-25 12:19:58 +03:30
|
|
|
<div
|
|
|
|
|
class="d-flex align-center flex-wrap justify-space-between my-6"
|
|
|
|
|
>
|
|
|
|
|
<VCheckbox v-model="rememberMe" label="Remember me" />
|
2025-08-04 16:33:07 +03:30
|
|
|
<RouterLink
|
|
|
|
|
class="text-primary ms-2 mb-1"
|
|
|
|
|
:to="{ name: 'forgot-password' }"
|
|
|
|
|
>
|
|
|
|
|
Forgot Password?
|
|
|
|
|
</RouterLink>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-08-25 12:19:58 +03:30
|
|
|
<VBtn block type="submit"> Login </VBtn>
|
2025-08-04 16:33:07 +03:30
|
|
|
</VCol>
|
|
|
|
|
|
|
|
|
|
<!-- create account -->
|
2025-08-25 12:19:58 +03:30
|
|
|
<VCol cols="12" class="text-center">
|
2025-08-04 16:33:07 +03:30
|
|
|
<span>New on our platform?</span>
|
|
|
|
|
<RouterLink
|
|
|
|
|
class="text-primary ms-1"
|
|
|
|
|
:to="{ name: 'register' }"
|
|
|
|
|
>
|
|
|
|
|
Create an account
|
|
|
|
|
</RouterLink>
|
|
|
|
|
</VCol>
|
2025-08-25 12:19:58 +03:30
|
|
|
<VCol cols="12" class="d-flex align-center">
|
2025-08-04 16:33:07 +03:30
|
|
|
<VDivider />
|
|
|
|
|
<span class="mx-4">or</span>
|
|
|
|
|
<VDivider />
|
|
|
|
|
</VCol>
|
|
|
|
|
|
|
|
|
|
<!-- auth providers -->
|
2025-08-25 12:19:58 +03:30
|
|
|
<VCol cols="12" class="text-center">
|
2025-08-04 16:33:07 +03:30
|
|
|
<AuthProvider />
|
|
|
|
|
</VCol>
|
|
|
|
|
</VRow>
|
|
|
|
|
</VForm>
|
|
|
|
|
</VCardText>
|
|
|
|
|
</VCard>
|
|
|
|
|
</VCol>
|
|
|
|
|
</VRow>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
@use "@core-scss/template/pages/page-auth";
|
|
|
|
|
</style>
|