2021-08-14 19:43:19 +02:00
|
|
|
<template>
|
2021-10-20 17:38:25 +02:00
|
|
|
<div id="user-auth-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"
|
|
|
|
/>
|
2021-08-14 19:43:19 +02:00
|
|
|
<form @submit.prevent="onSubmit(action)">
|
|
|
|
<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
|
|
|
|
v-model="formData.username"
|
2021-10-20 17:38:25 +02:00
|
|
|
:placeholder="$t('user.USERNAME')"
|
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"
|
2021-08-15 17:42:11 +02:00
|
|
|
:disabled="registration_disabled"
|
2021-08-14 19:43:19 +02:00
|
|
|
required
|
|
|
|
type="email"
|
|
|
|
v-model="formData.email"
|
2021-10-20 17:38:25 +02:00
|
|
|
:placeholder="
|
|
|
|
action === 'reset-request'
|
|
|
|
? $t('user.ENTER_EMAIL')
|
|
|
|
: $t('user.EMAIL')
|
|
|
|
"
|
2021-08-14 19:43:19 +02:00
|
|
|
/>
|
|
|
|
<input
|
2021-10-20 17:38:25 +02:00
|
|
|
v-if="action !== 'reset-request'"
|
2021-08-14 19:43:19 +02:00
|
|
|
id="password"
|
2021-08-15 17:42:11 +02:00
|
|
|
:disabled="registration_disabled"
|
2021-08-14 19:43:19 +02:00
|
|
|
required
|
|
|
|
type="password"
|
|
|
|
v-model="formData.password"
|
2021-10-20 17:38:25 +02:00
|
|
|
:placeholder="
|
|
|
|
action === 'reset'
|
|
|
|
? $t('user.ENTER_PASSWORD')
|
|
|
|
: $t('user.PASSWORD')
|
|
|
|
"
|
2021-08-14 19:43:19 +02:00
|
|
|
/>
|
|
|
|
<input
|
2021-10-20 17:38:25 +02:00
|
|
|
v-if="['register', 'reset'].includes(action)"
|
2021-08-14 19:43:19 +02:00
|
|
|
id="confirm-password"
|
2021-08-15 17:42:11 +02:00
|
|
|
:disabled="registration_disabled"
|
2021-08-14 19:43:19 +02:00
|
|
|
type="password"
|
|
|
|
required
|
|
|
|
v-model="formData.password_conf"
|
2021-10-20 17:38:25 +02:00
|
|
|
:placeholder="
|
|
|
|
action === 'reset'
|
|
|
|
? $t('user.ENTER_PASSWORD_CONFIRMATION')
|
|
|
|
: $t('user.PASSWORD_CONFIRM')
|
|
|
|
"
|
2021-08-14 19:43:19 +02:00
|
|
|
/>
|
|
|
|
</div>
|
2021-08-15 17:42:11 +02:00
|
|
|
<button type="submit" :disabled="registration_disabled">
|
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>
|
|
|
|
-
|
|
|
|
<router-link class="links" to="/password-reset/request">
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t('user.PASSWORD_FORGOTTEN') }}
|
|
|
|
</router-link>
|
|
|
|
</div>
|
2021-11-06 18:24:53 +01:00
|
|
|
<div v-else>
|
|
|
|
<span class="account">{{ $t('user.ALREADY_HAVE_ACCOUNT') }}</span>
|
|
|
|
<router-link class="links" to="/login">
|
|
|
|
{{ $t('user.LOGIN') }}
|
|
|
|
</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>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-08-15 11:18:26 +02:00
|
|
|
import { ComputedRef, computed, defineComponent, reactive, watch } from 'vue'
|
|
|
|
import { useRoute } from 'vue-router'
|
2021-08-14 19:43:19 +02:00
|
|
|
|
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'
|
|
|
|
|
|
|
|
export default defineComponent({
|
2021-10-20 17:38:25 +02:00
|
|
|
name: 'UserAuthForm',
|
2021-08-14 19:43:19 +02:00
|
|
|
props: {
|
|
|
|
action: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-10-20 17:38:25 +02:00
|
|
|
token: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2021-08-14 19:43:19 +02:00
|
|
|
},
|
2021-08-15 08:33:03 +02:00
|
|
|
setup(props) {
|
2021-08-21 18:36:44 +02:00
|
|
|
const formData: ILoginRegisterFormData = reactive({
|
2021-08-14 19:43:19 +02:00
|
|
|
username: '',
|
|
|
|
email: '',
|
|
|
|
password: '',
|
|
|
|
password_conf: '',
|
|
|
|
})
|
2021-08-15 11:18:26 +02:00
|
|
|
const route = useRoute()
|
2021-08-14 19:43:19 +02:00
|
|
|
const store = useStore()
|
2021-08-15 08:33:03 +02:00
|
|
|
|
|
|
|
const buttonText: ComputedRef<string> = computed(() =>
|
2021-10-20 17:38:25 +02:00
|
|
|
getButtonText(props.action)
|
2021-08-15 08:33:03 +02:00
|
|
|
)
|
2021-08-15 10:50:39 +02:00
|
|
|
const errorMessages: ComputedRef<string | string[] | null> = computed(
|
|
|
|
() => store.getters[ROOT_STORE.GETTERS.ERROR_MESSAGES]
|
2021-08-15 08:33:03 +02:00
|
|
|
)
|
2021-10-24 20:13:28 +02:00
|
|
|
const appConfig: ComputedRef<TAppConfig> = computed(
|
2021-08-15 17:42:11 +02:00
|
|
|
() => store.getters[ROOT_STORE.GETTERS.APP_CONFIG]
|
|
|
|
)
|
|
|
|
const registration_disabled: ComputedRef<boolean> = computed(
|
|
|
|
() =>
|
|
|
|
props.action === 'register' &&
|
|
|
|
!appConfig.value.is_registration_enabled
|
|
|
|
)
|
2021-08-15 08:33:03 +02:00
|
|
|
|
2021-10-20 17:38:25 +02:00
|
|
|
function getButtonText(action: string): string {
|
|
|
|
switch (action) {
|
|
|
|
case 'reset-request':
|
|
|
|
case 'reset':
|
|
|
|
return 'buttons.SUBMIT'
|
|
|
|
default:
|
|
|
|
return `buttons.${props.action.toUpperCase()}`
|
|
|
|
}
|
|
|
|
}
|
2021-08-14 19:43:19 +02:00
|
|
|
function onSubmit(actionType: string) {
|
2021-10-20 17:38:25 +02:00
|
|
|
switch (actionType) {
|
|
|
|
case 'reset':
|
|
|
|
if (!props.token) {
|
|
|
|
return store.commit(
|
|
|
|
ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES,
|
|
|
|
'user.INVALID_TOKEN'
|
|
|
|
)
|
|
|
|
}
|
2021-11-03 10:41:53 +01:00
|
|
|
return store.dispatch(AUTH_USER_STORE.ACTIONS.RESET_USER_PASSWORD, {
|
2021-10-20 17:38:25 +02:00
|
|
|
password: formData.password,
|
|
|
|
password_conf: formData.password_conf,
|
|
|
|
token: props.token,
|
|
|
|
})
|
|
|
|
case 'reset-request':
|
|
|
|
return store.dispatch(
|
2021-11-03 10:41:53 +01:00
|
|
|
AUTH_USER_STORE.ACTIONS.SEND_PASSWORD_RESET_REQUEST,
|
2021-10-20 17:38:25 +02:00
|
|
|
{
|
|
|
|
email: formData.email,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
default:
|
2021-11-03 10:41:53 +01:00
|
|
|
store.dispatch(AUTH_USER_STORE.ACTIONS.LOGIN_OR_REGISTER, {
|
2021-10-20 17:38:25 +02:00
|
|
|
actionType,
|
|
|
|
formData,
|
2021-11-03 09:41:27 +01:00
|
|
|
redirectUrl: route.query.from,
|
2021-10-20 17:38:25 +02:00
|
|
|
})
|
|
|
|
}
|
2021-08-14 19:43:19 +02:00
|
|
|
}
|
2021-08-15 11:18:26 +02:00
|
|
|
function resetFormData() {
|
|
|
|
formData.username = ''
|
|
|
|
formData.email = ''
|
|
|
|
formData.password = ''
|
|
|
|
formData.password_conf = ''
|
|
|
|
}
|
|
|
|
watch(
|
|
|
|
() => route.path,
|
|
|
|
async () => {
|
|
|
|
store.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
|
|
|
resetFormData()
|
|
|
|
}
|
|
|
|
)
|
2021-08-14 19:43:19 +02:00
|
|
|
return {
|
2021-08-15 17:42:11 +02:00
|
|
|
appConfig,
|
2021-08-15 08:33:03 +02:00
|
|
|
buttonText,
|
2021-08-15 10:50:39 +02:00
|
|
|
errorMessages,
|
2021-08-14 19:43:19 +02:00
|
|
|
formData,
|
2021-08-15 17:42:11 +02:00
|
|
|
registration_disabled,
|
2021-10-02 16:16:58 +02:00
|
|
|
onSubmit,
|
2021-08-14 19:43:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
@import '~@/scss/base';
|
|
|
|
|
2021-10-20 17:38:25 +02:00
|
|
|
#user-auth-form {
|
2021-08-14 19:43:19 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
margin: $default-margin 0;
|
2021-08-15 09:24:10 +02:00
|
|
|
height: 100%;
|
2021-08-14 19:43:19 +02:00
|
|
|
|
|
|
|
#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-10-20 17:38:25 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (max-width: $medium-limit) {
|
|
|
|
height: auto;
|
2021-08-15 10:50:39 +02:00
|
|
|
margin-bottom: 50px;
|
2021-10-02 16:16:58 +02:00
|
|
|
|
|
|
|
#user-form {
|
|
|
|
margin-top: $default-margin;
|
|
|
|
width: 100%;
|
|
|
|
}
|
2021-08-14 19:43:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|