2021-08-14 19:43:19 +02:00
|
|
|
<template>
|
2022-02-26 14:04:48 +01:00
|
|
|
<div
|
|
|
|
id="user-auth-form"
|
|
|
|
:class="`${
|
|
|
|
['reset', 'reset-request'].includes(action) ? action : 'user-form'
|
|
|
|
}`"
|
|
|
|
>
|
2021-08-14 19:43:19 +02:00
|
|
|
<div id="user-form">
|
2021-08-15 17:42:11 +02:00
|
|
|
<div
|
|
|
|
class="form-box"
|
|
|
|
:class="{
|
|
|
|
disabled: registration_disabled,
|
|
|
|
}"
|
|
|
|
>
|
2021-10-02 16:16:58 +02:00
|
|
|
<AlertMessage
|
|
|
|
message="user.REGISTER_DISABLED"
|
|
|
|
v-if="registration_disabled"
|
|
|
|
/>
|
2022-04-23 19:30:54 +02:00
|
|
|
<AlertMessage
|
|
|
|
message="admin.EMAIL_SENDING_DISABLED"
|
|
|
|
v-if="sendingEmailDisabled"
|
|
|
|
/>
|
2022-03-20 10:37:47 +01:00
|
|
|
<div
|
|
|
|
class="info-box success-message"
|
|
|
|
v-if="isSuccess || isRegistrationSuccess"
|
|
|
|
>
|
|
|
|
{{
|
|
|
|
$t(
|
|
|
|
`user.PROFILE.SUCCESSFUL_${
|
2022-04-23 19:30:54 +02:00
|
|
|
isRegistrationSuccess
|
|
|
|
? `REGISTRATION${
|
|
|
|
appConfig.is_email_sending_enabled ? '_WITH_EMAIL' : ''
|
|
|
|
}`
|
|
|
|
: 'UPDATE'
|
2022-03-20 10:37:47 +01:00
|
|
|
}`
|
|
|
|
)
|
|
|
|
}}
|
2022-03-12 08:59:22 +01:00
|
|
|
</div>
|
2021-11-11 08:29:12 +01:00
|
|
|
<form
|
|
|
|
:class="{ errors: formErrors }"
|
|
|
|
@submit.prevent="onSubmit(action)"
|
|
|
|
>
|
2021-08-14 19:43:19 +02:00
|
|
|
<div class="form-items">
|
|
|
|
<input
|
|
|
|
v-if="action === 'register'"
|
|
|
|
id="username"
|
2021-08-15 17:42:11 +02:00
|
|
|
:disabled="registration_disabled"
|
2021-08-14 19:43:19 +02:00
|
|
|
required
|
2022-02-13 12:08:24 +01:00
|
|
|
pattern="[a-zA-Z0-9_]+"
|
|
|
|
minlength="3"
|
2022-03-13 08:38:45 +01:00
|
|
|
maxlength="30"
|
2021-11-11 08:29:12 +01:00
|
|
|
@invalid="invalidateForm"
|
2021-08-14 19:43:19 +02:00
|
|
|
v-model="formData.username"
|
2021-10-20 17:38:25 +02:00
|
|
|
:placeholder="$t('user.USERNAME')"
|
2021-08-14 19:43:19 +02:00
|
|
|
/>
|
2022-02-26 18:13:20 +01:00
|
|
|
<div v-if="action === 'register'" class="form-info">
|
|
|
|
<i class="fa fa-info-circle" aria-hidden="true" />
|
|
|
|
{{ $t('user.USERNAME_INFO') }}
|
|
|
|
</div>
|
2021-08-14 19:43:19 +02:00
|
|
|
<input
|
2021-10-20 17:38:25 +02:00
|
|
|
v-if="action !== 'reset'"
|
2021-08-14 19:43:19 +02:00
|
|
|
id="email"
|
2022-04-23 19:30:54 +02:00
|
|
|
:disabled="registration_disabled || sendingEmailDisabled"
|
2021-08-14 19:43:19 +02:00
|
|
|
required
|
2021-11-11 08:29:12 +01:00
|
|
|
@invalid="invalidateForm"
|
2021-08-14 19:43:19 +02:00
|
|
|
type="email"
|
|
|
|
v-model="formData.email"
|
2022-02-26 18:13:20 +01:00
|
|
|
:placeholder="$t('user.EMAIL')"
|
2021-08-14 19:43:19 +02:00
|
|
|
/>
|
2022-02-26 18:13:20 +01:00
|
|
|
<div
|
2022-03-20 12:15:23 +01:00
|
|
|
v-if="
|
|
|
|
[
|
|
|
|
'reset-request',
|
|
|
|
'register',
|
|
|
|
'account-confirmation-resend',
|
|
|
|
].includes(action)
|
|
|
|
"
|
2022-02-26 18:13:20 +01:00
|
|
|
class="form-info"
|
|
|
|
>
|
|
|
|
<i class="fa fa-info-circle" aria-hidden="true" />
|
|
|
|
{{ $t('user.EMAIL_INFO') }}
|
|
|
|
</div>
|
2022-02-23 18:08:45 +01:00
|
|
|
<PasswordInput
|
2022-03-20 12:15:23 +01:00
|
|
|
v-if="
|
|
|
|
!['account-confirmation-resend', 'reset-request'].includes(
|
|
|
|
action
|
|
|
|
)
|
|
|
|
"
|
2021-08-15 17:42:11 +02:00
|
|
|
:disabled="registration_disabled"
|
2022-02-23 18:08:45 +01:00
|
|
|
:required="true"
|
2021-10-20 17:38:25 +02:00
|
|
|
:placeholder="
|
|
|
|
action === 'reset'
|
|
|
|
? $t('user.ENTER_PASSWORD')
|
|
|
|
: $t('user.PASSWORD')
|
|
|
|
"
|
2022-02-26 13:40:13 +01:00
|
|
|
:password="formData.password"
|
2022-02-26 21:20:11 +01:00
|
|
|
:checkStrength="['reset', 'register'].includes(action)"
|
2022-02-23 18:08:45 +01:00
|
|
|
@updatePassword="updatePassword"
|
|
|
|
@passwordError="invalidateForm"
|
2021-08-14 19:43:19 +02:00
|
|
|
/>
|
2023-02-26 18:25:25 +01:00
|
|
|
<label
|
|
|
|
v-if="action === 'register'"
|
|
|
|
for="accepted_policy"
|
|
|
|
class="accepted_policy"
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
id="accepted_policy"
|
|
|
|
:disabled="registration_disabled"
|
|
|
|
required
|
|
|
|
@invalid="invalidateForm"
|
|
|
|
v-model="formData.accepted_policy"
|
|
|
|
/>
|
|
|
|
<span>
|
|
|
|
<i18n-t keypath="user.READ_AND_ACCEPT_PRIVACY_POLICY">
|
2023-03-01 21:16:51 +01:00
|
|
|
<router-link to="/privacy-policy" target="_blank">
|
2023-02-26 18:25:25 +01:00
|
|
|
{{ $t('privacy_policy.TITLE') }}
|
|
|
|
</router-link>
|
|
|
|
</i18n-t>
|
|
|
|
</span>
|
|
|
|
</label>
|
2021-08-14 19:43:19 +02:00
|
|
|
</div>
|
2022-04-23 19:30:54 +02:00
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
:disabled="registration_disabled || sendingEmailDisabled"
|
|
|
|
>
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t(buttonText) }}
|
2021-08-15 17:42:11 +02:00
|
|
|
</button>
|
2021-08-14 19:43:19 +02:00
|
|
|
</form>
|
2021-10-20 17:38:25 +02:00
|
|
|
<div v-if="action === 'login'">
|
2021-11-06 18:24:53 +01:00
|
|
|
<router-link class="links" to="/register">
|
|
|
|
{{ $t('user.REGISTER') }}
|
|
|
|
</router-link>
|
2022-04-23 19:30:54 +02:00
|
|
|
<span v-if="appConfig.is_email_sending_enabled">-</span>
|
|
|
|
<router-link
|
|
|
|
v-if="appConfig.is_email_sending_enabled"
|
|
|
|
class="links"
|
|
|
|
to="/password-reset/request"
|
|
|
|
>
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t('user.PASSWORD_FORGOTTEN') }}
|
|
|
|
</router-link>
|
|
|
|
</div>
|
2021-11-06 22:33:33 +01:00
|
|
|
<div v-if="action === 'register'">
|
2021-11-06 18:24:53 +01:00
|
|
|
<span class="account">{{ $t('user.ALREADY_HAVE_ACCOUNT') }}</span>
|
|
|
|
<router-link class="links" to="/login">
|
|
|
|
{{ $t('user.LOGIN') }}
|
|
|
|
</router-link>
|
|
|
|
</div>
|
2022-04-23 19:30:54 +02:00
|
|
|
<div
|
|
|
|
v-if="
|
|
|
|
['login', 'register'].includes(action) &&
|
|
|
|
appConfig.is_email_sending_enabled
|
|
|
|
"
|
|
|
|
>
|
2022-03-20 12:15:23 +01:00
|
|
|
<router-link class="links" to="/account-confirmation/resend">
|
|
|
|
{{ $t('user.ACCOUNT_CONFIRMATION_NOT_RECEIVED') }}
|
|
|
|
</router-link>
|
|
|
|
</div>
|
2021-08-15 10:50:39 +02:00
|
|
|
<ErrorMessage :message="errorMessages" v-if="errorMessages" />
|
2021-08-14 19:43:19 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
<script setup lang="ts">
|
|
|
|
import {
|
|
|
|
ComputedRef,
|
|
|
|
computed,
|
2022-09-19 14:00:49 +02:00
|
|
|
onUnmounted,
|
2021-11-10 21:19:27 +01:00
|
|
|
reactive,
|
2021-11-11 08:29:12 +01:00
|
|
|
ref,
|
2021-11-10 21:19:27 +01:00
|
|
|
toRefs,
|
|
|
|
watch,
|
|
|
|
withDefaults,
|
|
|
|
} from 'vue'
|
2021-08-15 11:18:26 +02:00
|
|
|
import { useRoute } from 'vue-router'
|
2021-08-14 19:43:19 +02:00
|
|
|
|
2022-02-23 18:08:45 +01:00
|
|
|
import PasswordInput from '@/components/Common/PasswordInput.vue'
|
2021-11-03 10:41:53 +01:00
|
|
|
import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants'
|
2021-10-24 20:13:28 +02:00
|
|
|
import { TAppConfig } from '@/types/application'
|
2021-08-21 18:36:44 +02:00
|
|
|
import { ILoginRegisterFormData } from '@/types/user'
|
2021-08-14 19:43:19 +02:00
|
|
|
import { useStore } from '@/use/useStore'
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
interface Props {
|
|
|
|
action: string
|
|
|
|
token?: string
|
|
|
|
}
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
token: '',
|
|
|
|
})
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
const store = useStore()
|
|
|
|
|
|
|
|
const { action } = toRefs(props)
|
|
|
|
const formData: ILoginRegisterFormData = reactive({
|
|
|
|
username: '',
|
|
|
|
email: '',
|
|
|
|
password: '',
|
2023-02-26 18:25:25 +01:00
|
|
|
accepted_policy: false
|
2021-08-14 19:43:19 +02:00
|
|
|
})
|
2021-11-10 21:19:27 +01:00
|
|
|
const buttonText: ComputedRef<string> = computed(() =>
|
|
|
|
getButtonText(props.action)
|
|
|
|
)
|
|
|
|
const errorMessages: ComputedRef<string | string[] | null> = computed(
|
|
|
|
() => store.getters[ROOT_STORE.GETTERS.ERROR_MESSAGES]
|
|
|
|
)
|
2022-03-20 10:37:47 +01:00
|
|
|
const isRegistrationSuccess: ComputedRef<boolean> = computed(
|
|
|
|
() => store.getters[AUTH_USER_STORE.GETTERS.IS_REGISTRATION_SUCCESS]
|
|
|
|
)
|
2022-03-12 08:59:22 +01:00
|
|
|
const isSuccess: ComputedRef<boolean> = computed(
|
|
|
|
() => store.getters[AUTH_USER_STORE.GETTERS.IS_SUCCESS]
|
|
|
|
)
|
2021-11-10 21:19:27 +01:00
|
|
|
const appConfig: ComputedRef<TAppConfig> = computed(
|
|
|
|
() => store.getters[ROOT_STORE.GETTERS.APP_CONFIG]
|
|
|
|
)
|
2022-07-03 13:35:57 +02:00
|
|
|
const language: ComputedRef<string> = computed(
|
|
|
|
() => store.getters[ROOT_STORE.GETTERS.LANGUAGE]
|
|
|
|
)
|
2021-11-10 21:19:27 +01:00
|
|
|
const registration_disabled: ComputedRef<boolean> = computed(
|
|
|
|
() =>
|
|
|
|
props.action === 'register' && !appConfig.value.is_registration_enabled
|
|
|
|
)
|
2022-04-23 19:30:54 +02:00
|
|
|
const sendingEmailDisabled: ComputedRef<boolean> = computed(
|
|
|
|
() =>
|
|
|
|
['reset-request', 'account-confirmation-resend'].includes(props.action) &&
|
|
|
|
!appConfig.value.is_email_sending_enabled
|
|
|
|
)
|
2021-11-11 08:29:12 +01:00
|
|
|
const formErrors = ref(false)
|
2021-11-10 21:19:27 +01:00
|
|
|
|
|
|
|
function getButtonText(action: string): string {
|
|
|
|
switch (action) {
|
|
|
|
case 'reset-request':
|
|
|
|
case 'reset':
|
|
|
|
return 'buttons.SUBMIT'
|
|
|
|
default:
|
|
|
|
return `buttons.${props.action.toUpperCase()}`
|
|
|
|
}
|
|
|
|
}
|
2021-11-11 08:29:12 +01:00
|
|
|
function invalidateForm() {
|
|
|
|
formErrors.value = true
|
|
|
|
}
|
2022-02-23 18:08:45 +01:00
|
|
|
function updatePassword(password: string) {
|
|
|
|
formData.password = password
|
|
|
|
}
|
2021-11-10 21:19:27 +01:00
|
|
|
function onSubmit(actionType: string) {
|
|
|
|
switch (actionType) {
|
|
|
|
case 'reset':
|
|
|
|
if (!props.token) {
|
|
|
|
return store.commit(
|
|
|
|
ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES,
|
|
|
|
'user.INVALID_TOKEN'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return store.dispatch(AUTH_USER_STORE.ACTIONS.RESET_USER_PASSWORD, {
|
|
|
|
password: formData.password,
|
|
|
|
token: props.token,
|
|
|
|
})
|
|
|
|
case 'reset-request':
|
|
|
|
return store.dispatch(
|
|
|
|
AUTH_USER_STORE.ACTIONS.SEND_PASSWORD_RESET_REQUEST,
|
|
|
|
{
|
|
|
|
email: formData.email,
|
|
|
|
}
|
|
|
|
)
|
2022-03-20 12:15:23 +01:00
|
|
|
case 'account-confirmation-resend':
|
|
|
|
return store.dispatch(
|
|
|
|
AUTH_USER_STORE.ACTIONS.RESEND_ACCOUNT_CONFIRMATION_EMAIL,
|
|
|
|
{
|
|
|
|
email: formData.email,
|
|
|
|
}
|
|
|
|
)
|
2021-11-10 21:19:27 +01:00
|
|
|
default:
|
2022-07-03 13:35:57 +02:00
|
|
|
formData['language'] = language.value
|
2021-11-10 21:19:27 +01:00
|
|
|
store.dispatch(AUTH_USER_STORE.ACTIONS.LOGIN_OR_REGISTER, {
|
|
|
|
actionType,
|
|
|
|
formData,
|
|
|
|
redirectUrl: route.query.from,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function resetFormData() {
|
|
|
|
formData.username = ''
|
|
|
|
formData.email = ''
|
|
|
|
formData.password = ''
|
2023-02-26 18:25:25 +01:00
|
|
|
formData.accepted_policy = false
|
2021-11-10 21:19:27 +01:00
|
|
|
}
|
|
|
|
|
2022-09-19 14:00:49 +02:00
|
|
|
onUnmounted(() => store.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES))
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
watch(
|
|
|
|
() => route.path,
|
|
|
|
async () => {
|
|
|
|
store.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
2022-03-12 08:59:22 +01:00
|
|
|
store.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_IS_SUCCESS, false)
|
2022-03-20 10:37:47 +01:00
|
|
|
store.commit(
|
|
|
|
AUTH_USER_STORE.MUTATIONS.UPDATE_IS_REGISTRATION_SUCCESS,
|
|
|
|
false
|
|
|
|
)
|
2021-11-11 08:29:12 +01:00
|
|
|
formErrors.value = false
|
2021-11-10 21:19:27 +01:00
|
|
|
resetFormData()
|
|
|
|
}
|
|
|
|
)
|
2021-08-14 19:43:19 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2021-11-29 11:23:21 +01:00
|
|
|
@import '~@/scss/colors.scss';
|
|
|
|
@import '~@/scss/vars.scss';
|
2021-08-14 19:43:19 +02:00
|
|
|
|
2021-10-20 17:38:25 +02:00
|
|
|
#user-auth-form {
|
2021-08-14 19:43:19 +02:00
|
|
|
display: flex;
|
|
|
|
|
|
|
|
#user-form {
|
|
|
|
width: 60%;
|
|
|
|
|
2021-11-06 18:24:53 +01:00
|
|
|
.account {
|
2021-10-20 17:38:25 +02:00
|
|
|
font-size: 0.9em;
|
|
|
|
padding-left: $default-padding;
|
|
|
|
}
|
2021-11-06 18:24:53 +01:00
|
|
|
.links {
|
|
|
|
font-size: 0.9em;
|
|
|
|
font-style: italic;
|
|
|
|
padding: 0 $default-padding;
|
|
|
|
}
|
2021-08-14 19:43:19 +02:00
|
|
|
button {
|
|
|
|
margin: $default-margin;
|
2021-09-27 15:50:04 +02:00
|
|
|
border: solid 1px var(--app-color);
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
border-color: var(--disabled-color);
|
|
|
|
}
|
2021-08-14 19:43:19 +02:00
|
|
|
}
|
2022-03-12 08:59:22 +01:00
|
|
|
.success-message {
|
|
|
|
margin: $default-margin;
|
|
|
|
}
|
2023-02-26 18:25:25 +01:00
|
|
|
.accepted_policy {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
font-size: .85em;
|
|
|
|
font-weight: normal;
|
|
|
|
}
|
2021-08-14 19:43:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (max-width: $medium-limit) {
|
2021-08-15 10:50:39 +02:00
|
|
|
margin-bottom: 50px;
|
2021-10-02 16:16:58 +02:00
|
|
|
#user-form {
|
|
|
|
width: 100%;
|
|
|
|
}
|
2021-08-14 19:43:19 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-26 14:04:48 +01:00
|
|
|
|
|
|
|
.user-form {
|
|
|
|
margin-top: 200px;
|
|
|
|
@media screen and (max-width: $small-limit) {
|
|
|
|
margin-top: $default-margin;
|
|
|
|
}
|
|
|
|
}
|
2021-08-14 19:43:19 +02:00
|
|
|
</style>
|