Client - display if registration is disabled

This commit is contained in:
Sam 2021-08-15 17:42:11 +02:00
parent 9fc70fcf23
commit cd20e3c167
6 changed files with 88 additions and 3 deletions

View File

@ -0,0 +1,36 @@
<template>
<div class="alert-message">
<div v-html="t(message)" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { useI18n } from 'vue-i18n'
export default defineComponent({
name: 'AlertMessage',
props: {
message: String,
},
setup() {
const { t } = useI18n()
return {
t,
}
},
})
</script>
<style scoped lang="scss">
@import '~@/scss/base';
.alert-message {
background: var(--alert-background-color);
color: var(--alert-color);
border-radius: 4px;
margin: $default-margin;
padding: $default-padding;
}
</style>

View File

@ -1,18 +1,25 @@
<template> <template>
<div id="login-or-register-form"> <div id="login-or-register-form">
<div id="user-form"> <div id="user-form">
<div class="form-box"> <div
class="form-box"
:class="{
disabled: registration_disabled,
}"
>
<form @submit.prevent="onSubmit(action)"> <form @submit.prevent="onSubmit(action)">
<div class="form-items"> <div class="form-items">
<input <input
v-if="action === 'register'" v-if="action === 'register'"
id="username" id="username"
:disabled="registration_disabled"
required required
v-model="formData.username" v-model="formData.username"
:placeholder="t('user.USERNAME')" :placeholder="t('user.USERNAME')"
/> />
<input <input
id="email" id="email"
:disabled="registration_disabled"
required required
type="email" type="email"
v-model="formData.email" v-model="formData.email"
@ -20,6 +27,7 @@
/> />
<input <input
id="password" id="password"
:disabled="registration_disabled"
required required
type="password" type="password"
v-model="formData.password" v-model="formData.password"
@ -28,15 +36,22 @@
<input <input
v-if="action === 'register'" v-if="action === 'register'"
id="confirm-password" id="confirm-password"
:disabled="registration_disabled"
type="password" type="password"
required required
v-model="formData.password_conf" v-model="formData.password_conf"
:placeholder="t('user.PASSWORD-CONFIRM')" :placeholder="t('user.PASSWORD-CONFIRM')"
/> />
</div> </div>
<button type="submit">{{ t(buttonText) }}</button> <button type="submit" :disabled="registration_disabled">
{{ t(buttonText) }}
</button>
</form> </form>
<ErrorMessage :message="errorMessages" v-if="errorMessages" /> <ErrorMessage :message="errorMessages" v-if="errorMessages" />
<AlertMessage
message="user.REGISTER_DISABLED"
v-if="registration_disabled"
/>
</div> </div>
</div> </div>
</div> </div>
@ -49,12 +64,16 @@
import { IFormData } from '@/interfaces' import { IFormData } from '@/interfaces'
import { ROOT_STORE, USER_STORE } from '@/store/constants' import { ROOT_STORE, USER_STORE } from '@/store/constants'
import { IAppConfig } from '@/store/modules/root/interfaces'
import { useStore } from '@/use/useStore' import { useStore } from '@/use/useStore'
import AlertMessage from '@/components/Common/AlertMessage.vue'
import ErrorMessage from '@/components/Common/ErrorMessage.vue' import ErrorMessage from '@/components/Common/ErrorMessage.vue'
import router from '@/router'
export default defineComponent({ export default defineComponent({
name: 'LoginOrRegisterForm', name: 'LoginOrRegisterForm',
components: { components: {
AlertMessage,
ErrorMessage, ErrorMessage,
}, },
props: { props: {
@ -80,6 +99,14 @@
const errorMessages: ComputedRef<string | string[] | null> = computed( const errorMessages: ComputedRef<string | string[] | null> = computed(
() => store.getters[ROOT_STORE.GETTERS.ERROR_MESSAGES] () => store.getters[ROOT_STORE.GETTERS.ERROR_MESSAGES]
) )
const appConfig: ComputedRef<IAppConfig> = computed(
() => store.getters[ROOT_STORE.GETTERS.APP_CONFIG]
)
const registration_disabled: ComputedRef<boolean> = computed(
() =>
props.action === 'register' &&
!appConfig.value.is_registration_enabled
)
function onSubmit(actionType: string) { function onSubmit(actionType: string) {
return store.dispatch(USER_STORE.ACTIONS.LOGIN_OR_REGISTER, { return store.dispatch(USER_STORE.ACTIONS.LOGIN_OR_REGISTER, {
@ -102,10 +129,13 @@
) )
return { return {
t, t,
appConfig,
buttonText, buttonText,
errorMessages, errorMessages,
formData, formData,
onSubmit, onSubmit,
registration_disabled,
router,
} }
}, },
}) })

View File

@ -6,5 +6,6 @@
"PASSWORD": "Password", "PASSWORD": "Password",
"PASSWORD-CONFIRM": "Confirm Password", "PASSWORD-CONFIRM": "Confirm Password",
"REGISTER": "Register", "REGISTER": "Register",
"REGISTER_DISABLED": "Sorry, registration is disabled.",
"USERNAME": "Username" "USERNAME": "Username"
} }

View File

@ -7,5 +7,6 @@
"PASSWORD": "Mot de passe", "PASSWORD": "Mot de passe",
"PASSWORD-CONFIRM": "Confirmation du mot de passe", "PASSWORD-CONFIRM": "Confirmation du mot de passe",
"REGISTER": "S'inscrire", "REGISTER": "S'inscrire",
"REGISTER_DISABLED": "Désolé, les inscriptions sont désactivées.",
"USERNAME": "Nom d'utilisateur" "USERNAME": "Nom d'utilisateur"
} }

View File

@ -26,6 +26,11 @@ a {
input { input {
border-radius: 0; border-radius: 0;
border: solid 1px var(--input-border-color); border: solid 1px var(--input-border-color);
&:disabled {
border-color: var(--disabled-color);
}
} }
label { label {
@ -45,10 +50,16 @@ button {
color: #FFFFFF; color: #FFFFFF;
} }
&:active { &:enabled:active {
box-shadow: 2px 0 2px var(--app-shadow-color); box-shadow: 2px 0 2px var(--app-shadow-color);
transform: translateY(2px); transform: translateY(2px);
} }
&:disabled {
background: var(--disabled-background-color);
border-color: var(--disabled-color);
color: var(--disabled-color);
}
} }
.container { .container {

View File

@ -16,7 +16,13 @@
--footer-border-color: #ebeef3; --footer-border-color: #ebeef3;
--footer-color: #8b8c8c; --footer-color: #8b8c8c;
--alert-background-color: #c8cdd3;
--alert-color: #3f3f3f;
--error-background-color: #ffd2d2; --error-background-color: #ffd2d2;
--error-color: #db1924; --error-color: #db1924;
--disabled-background-color: #e0e0e0;
--disabled-color: #a3a3a3;
} }