Added account creation wizard.

This commit is contained in:
Antoine Nguyen
2021-04-15 18:45:48 +02:00
parent 043763af9a
commit 8e48ed1bd4
18 changed files with 813 additions and 109 deletions
+6
View File
@@ -5,5 +5,11 @@ const resource = 'accounts'
export default {
getAll ({ domain, role }) {
return repository.get(`/${resource}/`, { params: { domain, role } })
},
validate (data) {
return repository.post(`${resource}/validate/`, data)
},
create (data) {
return repository.post(`${resource}/`, data)
}
}
@@ -0,0 +1,61 @@
<template>
<validation-observer ref="observer">
<validation-provider
vid="alias"
v-slot="{ errors }"
>
<email-field
ref="aliasField"
v-model="currentAlias"
:placeholder="'Start typing a name here...'|translate"
@domain-selected="addAlias"
:hint="'Alias(es) of this mailbox. To create a catchall alias, just enter the domain name (@domain.tld).'|translate"
persistent-hint
:error-messages="errors"
/>
</validation-provider>
<v-chip
v-for="(alias, index) in account.aliases"
:key="index"
class="mr-2 mt-2"
close
@click:close="account.aliases.splice(index, 1)"
>
{{ alias }}
</v-chip>
</validation-observer>
</template>
<script>
import accounts from '@/api/accounts'
import EmailField from '@/components/tools/EmailField'
export default {
props: ['account'],
components: {
EmailField
},
data () {
return {
currentAlias: ''
}
},
methods: {
async addAlias () {
try {
await accounts.validate({ aliases: [this.currentAlias] })
this.account.aliases.push(this.currentAlias)
this.$refs.aliasField.reset()
} catch (error) {
let errorMsg = null
if (error.response.data.aliases) {
errorMsg = error.response.data.aliases
} else if (error.response.data.non_field_errors) {
errorMsg = error.response.data.non_field_errors
}
this.$refs.observer.setErrors({ alias: errorMsg })
}
}
}
}
</script>
@@ -7,11 +7,19 @@
max-width="190"
/>
<v-stepper-step :complete="step > 1" step="1">
<translate>General</translate>
<translate>Role</translate>
</v-stepper-step>
<v-stepper-step :complete="step > 2" step="2">
<translate>Mail</translate>
<translate>Identification</translate>
</v-stepper-step>
<v-stepper-step :complete="step > 3" step="3">
<translate>Mailbox</translate>
</v-stepper-step>
<v-stepper-step :complete="step > 4" step="4">
<translate>Aliases</translate>
</v-stepper-step>
<v-stepper-step step="5">
<translate>Summary</translate>
</v-stepper-step>
<v-btn icon @click="close">
<v-icon color="primary" x-large>mdi-close</v-icon>
@@ -21,10 +29,10 @@
<v-stepper-content step="1" class="flex-grow-0">
<div class="mb-6 text-h5">
<translate class="grey--text text--darken-1">New account</translate> /
<translate>General</translate>
<translate>Role</translate>
</div>
<account-general-form ref="form_1" :account="account" />
<div class="d-flex justify-end">
<account-role-form ref="form_1" :account="account" />
<div class="d-flex justify-end mt-4">
<v-btn
color="primary"
@click="goToNextStep(1, 2)"
@@ -34,6 +42,79 @@
</v-btn>
</div>
</v-stepper-content>
<v-stepper-content step="2" class="flex-grow-0">
<div class="mb-6 text-h5">
<translate class="grey--text text--darken-1">New account</translate> /
<translate>Identification</translate>
</div>
<account-general-form v-if="step >= 2" ref="form_2" :account="account" />
<div class="d-flex justify-end">
<v-btn @click="step = 1" class="mr-10" text>
<translate>Back</translate>
</v-btn>
<v-btn
color="primary"
@click="goToNextStep(2, 3)"
large
>
<translate>Next</translate>
</v-btn>
</div>
</v-stepper-content>
<v-stepper-content step="3" class="flex-grow-0">
<div class="mb-6 text-h5">
<translate class="grey--text text--darken-1">New account</translate> /
<translate>Mailbox</translate>
</div>
<account-mailbox-form ref="form_3" :account="account" />
<div class="d-flex justify-end">
<v-btn @click="step = 2" class="mr-10" text>
<translate>Back</translate>
</v-btn>
<v-btn
color="primary"
@click="goToNextStep(3, 4)"
large
>
<translate>Next</translate>
</v-btn>
</div>
</v-stepper-content>
<v-stepper-content step="4" class="flex-grow-0">
<div class="mb-6 text-h5">
<translate class="grey--text text--darken-1">New account</translate> /
<translate>Aliases</translate>
</div>
<account-alias-form v-if="step >= 4" ref="form_4" :account="account" />
<div class="d-flex justify-end">
<v-btn @click="step = 3" class="mr-10" text>
<translate>Back</translate>
</v-btn>
<v-btn
color="primary"
@click="goToNextStep(4, 5)"
large
>
<translate>Next</translate>
</v-btn>
</div>
</v-stepper-content>
<v-stepper-content step="5" class="flex-grow-0">
<div class="text-center text-h3"><translate>Summary</translate></div>
<creation-summary
:sections="summarySections"
@modify-step="val => step = val"
/>
<div class="d-flex justify-center mt-8">
<v-btn
color="primary"
@click="submit"
large
>
<translate>Confirm and create</translate>
</v-btn>
</div>
</v-stepper-content>
</v-stepper-items>
</v-stepper>
<confirm-dialog ref="confirm" />
@@ -41,21 +122,98 @@
</template>
<script>
import { bus } from '@/main'
import accounts from '@/api/accounts'
import AccountAliasForm from './AccountAliasForm'
import AccountGeneralForm from './AccountGeneralForm'
import AccountMailboxForm from './AccountMailboxForm'
import AccountRoleForm from './AccountRoleForm'
import ConfirmDialog from '@/components/layout/ConfirmDialog'
import CreationSummary from '@/components/tools/CreationSummary'
export default {
components: {
AccountAliasForm,
AccountGeneralForm,
ConfirmDialog
AccountMailboxForm,
AccountRoleForm,
ConfirmDialog,
CreationSummary
},
computed: {
summarySections () {
const result = [
{
title: this.$gettext('Role'),
items: [
{ key: this.$gettext('Role'), value: this.account.role }
]
},
{
title: this.$gettext('Identification'),
items: [
{ key: this.$gettext('Username'), value: this.account.username },
{ key: this.$gettext('First name'), value: this.account.first_name },
{ key: this.$gettext('Last name'), value: this.account.last_name },
{
key: this.$gettext('Random password'),
value: this.account.random_password,
type: 'yesno'
},
{
key: this.$gettext('Enabled'),
value: this.account.is_active,
type: 'yesno'
}
]
},
{
title: this.$gettext('Mailbox'),
items: [
{ key: this.$gettext('Email'), value: this.account.mailbox.full_address },
{
key: this.$gettext('Quota'),
value: (this.account.mailbox.use_domain_quota)
? this.$gettext('Domain default value')
: this.account.mailbox.quota
},
{
key: this.$gettext('Message sending limit'),
value: this.account.mailbox.message_limit
}
]
},
{
title: this.$gettext('Aliases'),
items: [
{
key: this.$gettext('Aliases'),
value: this.account.aliases,
type: 'list'
}
]
}
]
return result
}
},
data () {
return {
account: {},
account: this.getInitialForm(),
step: 1
}
},
methods: {
getInitialForm () {
return {
aliases: [],
is_active: true,
role: 'SimpleUsers',
mailbox: {
use_domain_quota: true
}
}
},
async close (withConfirm) {
if (withConfirm) {
const confirm = await this.$refs.confirm.open(
@@ -69,6 +227,7 @@ export default {
return
}
}
this.account = this.getInitialForm()
this.$emit('close')
this.step = 1
},
@@ -77,8 +236,24 @@ export default {
if (!valid) {
return
}
try {
await accounts.validate(this.account)
} catch (error) {
this.$refs[`form_${current}`].$refs.observer.setErrors(error.response.data)
return
}
this.step = next
},
submit () {
accounts.create(this.account).then(resp => {
bus.$emit('notification', { msg: this.$gettext('Account created') })
this.$emit('created')
this.close()
})
}
},
mounted () {
this.$store.dispatch('identities/fetchDomains')
}
}
</script>
@@ -3,37 +3,25 @@
<validation-provider
v-slot="{ errors }"
rules="required"
vid="username"
>
<choice-field v-model="account.role"
:label="'Role' | translate"
:choices="accountRoles"
:error-messages="errors"
/>
</validation-provider>
<validation-provider
v-slot="{ errors }"
rules="required"
>
<v-text-field
<email-field
v-model="account.username"
:label="'Username' | translate"
:error-messages="errors"
outlined
class="mt-4"
dense
/>
</validation-provider>
<v-text-field
v-model="account.first_name"
:label="'First name' | translate"
outlined
dense
/>
<v-text-field
v-model="account.last_name"
:label="'Last name' | translate"
outlined
dense
/>
<v-switch
v-model="account.random_password"
@@ -51,7 +39,6 @@
:error-messages="errors"
outlined
type="password"
dense
/>
</validation-provider>
<validation-provider
@@ -65,7 +52,6 @@
:error-messages="errors"
outlined
type="password"
dense
/>
</validation-provider>
<v-switch
@@ -77,34 +63,20 @@
</template>
<script>
import ChoiceField from '@/components/tools/ChoiceField'
import EmailField from '@/components/tools/EmailField'
export default {
components: {
ChoiceField
EmailField
},
props: ['account'],
data () {
return {
accountRoles: [
{
label: this.$gettext('Domain administrator'),
value: 'DomainAdmins'
},
{
label: this.$gettext('Reseller'),
value: 'Resellers'
},
{
label: this.$gettext('Simple user'),
value: 'SimpleUsers'
},
{
label: this.$gettext('Super administrator'),
value: 'SuperAdmins'
}
]
}
},
methods: {
},
mounted () {
}
}
</script>
@@ -0,0 +1,88 @@
<template>
<validation-observer ref="observer">
<validation-provider
v-slot="{ errors }"
rules="required"
>
<v-text-field
v-model="account.mailbox.full_address"
:label="'Email' | translate"
:error-messages="errors"
:disabled="account.role === 'SimpleUsers'"
outlined
/>
</validation-provider>
<div class="d-flex">
<v-text-field
v-model="account.mailbox.quota"
:label="'Quota' | translate"
:hint="'Quota for this mailbox, can be expressed in KB, MB (default) or GB. Define a custom value or use domain\'s default one. Leave empty to define an unlimited value (not allowed for domain administrators).' | translate"
persistent-hint
class="mr-4 quota"
:disabled="account.mailbox.use_domain_quota"
outlined
/>
<v-switch
v-model="account.mailbox.use_domain_quota"
:label="useDomainQuotaLabel"
/>
</div>
<v-text-field
v-model="account.mailbox.message_limit"
:label="'Message sending limit' | translate"
:hint="'Number of messages this mailbox can send per day. Leave empty for no limit.' | translate"
persistent-hint
outlined
/>
</validation-observer>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
props: ['account'],
computed: {
...mapGetters({
getDomainByName: 'identities/getDomainByName'
}),
domainQuota () {
const email = this.account.mailbox.full_address
if (email && email.indexOf('@') !== -1) {
const domain = this.getDomainByName(email.split('@')[1])
if (domain) {
return parseInt(domain.default_mailbox_quota)
}
}
return undefined
},
useDomainQuotaLabel () {
let result = this.$gettext('Use domain default value')
if (this.domainQuota !== undefined) {
if (this.domainQuota === 0) {
result += ` (${this.$gettext('unlimited')})`
} else {
result += ` (${this.domainQuota} MB)`
}
}
return result
}
},
watch: {
account: {
handler (val) {
if (val.role === 'SimpleUsers') {
this.$set(val.mailbox, 'full_address', val.username)
}
},
deep: true
}
}
}
</script>
<style lang="scss" scoped>
.quota {
max-width: 50%;
}
</style>
@@ -0,0 +1,48 @@
<template>
<validation-observer ref="observer">
<validation-provider
v-slot="{ errors }"
rules="required"
>
<choice-field v-model="account.role"
:label="'Role' | translate"
:choices="accountRoles"
:error-messages="errors"
:choices-per-line="2"
/>
</validation-provider>
</validation-observer>
</template>
<script>
import ChoiceField from '@/components/tools/ChoiceField'
export default {
components: {
ChoiceField
},
props: ['account'],
data () {
return {
accountRoles: [
{
label: this.$gettext('Domain administrator'),
value: 'DomainAdmins'
},
{
label: this.$gettext('Reseller'),
value: 'Resellers'
},
{
label: this.$gettext('Simple user'),
value: 'SimpleUsers'
},
{
label: this.$gettext('Super administrator'),
value: 'SuperAdmins'
}
]
}
}
}
</script>
@@ -76,10 +76,15 @@ export default {
selected: []
}
},
methods: {
fetchIdentities () {
identities.getAll().then(resp => {
this.identities = resp.data
})
}
},
mounted () {
identities.getAll().then(resp => {
this.identities = resp.data
})
this.fetchIdentities()
}
}
</script>
+28 -9
View File
@@ -1,14 +1,15 @@
<template>
<div>
<div class="text-subtitle-1 grey--text text--darken-1 mb-4" :class="{ 'label--disabled': disabled }">
<translate>{{ label }}</translate>
<label class="v-label">{{ label }}</label>
</div>
<div class="d-flex">
<div v-for="(choice, index) in choices"
:key="index"
class="choice rounded pa-10 mr-4 text-center"
<div class="d-flex" v-for="(lineChoices, index1) in formatedChoices" :key="index1">
<div v-for="(choice, index2) in lineChoices"
:key="index2"
class="choice rounded pa-10 mr-4 text-center flex-grow-0 mb-4"
:class="{ 'choice--disabled': disabled, 'choice--selected': !disabled && currentChoice === choice.value }"
@click="selectChoice(choice.value)">
@click="selectChoice(choice.value)"
>
<v-icon v-if="choice.icon" class="d-block mb-2" :color="iconColor(choice.value)" x-large>{{ choice.icon }}</v-icon>
<translate class="grey--text text--darken-1">{{ choice.label }}</translate>
</div>
@@ -25,14 +26,28 @@ export default {
disabled: {
type: Boolean,
default: false
}
},
choicesPerLine: Number
},
data () {
return {
currentChoice: null
currentChoice: null,
formatedChoices: []
}
},
methods: {
formatChoices () {
if (this.choicesPerLine) {
let sliceIndex = 0
while (sliceIndex < this.choices.length) {
const result = this.choices.slice(sliceIndex, sliceIndex + this.choicesPerLine)
this.formatedChoices.push(result)
sliceIndex += this.choicesPerLine
}
} else {
this.formatedChoices.push(this.choices)
}
},
iconColor (value) {
return (!this.disabled && value === this.currentChoice) ? 'primary' : ''
},
@@ -44,6 +59,9 @@ export default {
this.$emit('input', value)
}
},
mounted () {
this.formatChoices()
},
watch: {
value: {
handler (val) {
@@ -57,7 +75,8 @@ export default {
<style lang="scss" scoped>
.choice {
width: 200px;
// width: 200px;
flex-basis: 200px;
background-color: #F2F5F7;
border: 1px solid #DBDDDF;
cursor: pointer;
@@ -0,0 +1,45 @@
<template>
<div>
<div v-for="(section, index) in sections" :key="index">
<div class="subtitle mt-4 d-flex">
<span class="text-h6">{{ section.title }}</span>
<a href="#" class="edit-link ml-auto" @click="$emit('modify-step', index + 1)"><translate>Modify</translate></a>
</div>
<v-row v-for="(item, itemIndex) in section.items"
:key="itemIndex"
dense
>
<template v-if="item.value !== undefined">
<v-col><span class="grey--text">{{ item.key }}</span></v-col>
<v-col class="text-right" v-if="item.type === 'yesno'">{{ item.value|yesno }}</v-col>
<v-col class="text-right" v-else-if="item.type === 'list'">
{{ displayList(item.value) }}
</v-col>
<v-col class="text-right" v-else>{{ item.value }}</v-col>
</template>
</v-row>
</div>
</div>
</template>
<script>
export default {
props: ['sections'],
methods: {
displayList (value) {
return (value.length) ? value.join(', ') : this.$gettext('Empty')
}
}
}
</script>
<style scoped lang="scss">
.subtitle {
color: #000;
border-bottom: 1px solid #DBDDDF;
}
.edit-link {
text-decoration: none;
}
</style>
@@ -0,0 +1,161 @@
<template>
<div>
<v-text-field
ref="input"
v-model="input"
outlined
v-bind="$attrs"
v-on="$listeners"
@input="update"
@keydown="onKeyDown"
/>
<div class="menu"
v-if="showMenu"
:style="`width: ${width}px;`"
>
<v-list class="list">
<v-list-item
v-for="(domain, index) in filteredDomains"
:key="index"
@click="selectDomain(domain)"
:class="selectionIndex === index ? 'selected' : ''"
>
<v-list-item-title>{{ domain.name }}</v-list-item-title>
</v-list-item>
</v-list>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
props: ['value'],
computed: {
...mapGetters({
domains: 'identities/domains'
}),
filteredDomains () {
return this.domains.filter(domain => domain.name.startsWith(this.domainSearch))
}
},
data () {
return {
domainSearch: '',
input: this.value,
selectionIndex: 0,
showMenu: false,
width: 500
}
},
methods: {
onKeyDown (e) {
const keyCode = e.keyCode
if (keyCode === 40 || keyCode === 34) {
// on arrow down or page down
if (!this.showMenu) {
this.domainSearch = ''
this.showMenu = true
} else {
this.increaseSelectionIndex()
}
e.preventDefault()
} else if (keyCode === 38 || keyCode === 33) {
// on arrow up or page up
if (!this.showMenu) {
this.domainSearch = ''
this.showMenu = true
} else {
this.decreaseSelectionIndex()
}
e.preventDefault()
} else if (keyCode === 13 || keyCode === 9) {
// on enter or tab
if (this.filteredDomains.length > 0) {
this.selectDomain(this.filteredDomains[this.selectionIndex])
}
e.preventDefault()
} else if (keyCode === 27) {
// on escape
if (this.filteredDomains.length > 0) {
this.showMenu = false
e.preventDefault()
}
}
},
increaseSelectionIndex () {
if (this.selectionIndex >= this.filteredDomains.length - 1) {
this.selectionIndex = 0
} else {
this.selectionIndex += 1
}
},
decreaseSelectionIndex () {
if (this.selectionIndex <= 0) {
this.selectionIndex = this.filteredDomains.length - 1
} else {
this.selectionIndex -= 1
}
},
selectDomain (domain) {
this.input = this.input.split('@')[0] + '@' + domain.name
this.showMenu = false
this.$emit('input', this.input)
this.$emit('domain-selected')
},
update (value) {
if (this.input.indexOf('@') !== -1) {
this.domainSearch = this.input.split('@')[1]
this.showMenu = true
} else {
this.showMenu = false
}
this.$emit('input', this.input)
},
onResize () {
this.updateMinWidthProperty()
},
updateMinWidthProperty () {
this.width = this.$refs.input.$el.clientWidth
},
reset () {
this.input = ''
this.domainSearch = ''
}
},
mounted () {
window.addEventListener('resize', this.onResize)
this.$nextTick(() => {
this.updateMinWidthProperty()
})
}
}
</script>
<style scoped>
.menu {
display: inline-block;
position: fixed;
margin-top: -20px;
padding: 5px 0;
box-shadow: 0 1px 5px 1px rgba(0,0,0,0.3);
overflow-y: auto;
overflow-x: hidden;
contain: content;
z-index: 99;
}
.list {
width: 100%;
height: 100%;
font-size: 1.1em;
overflow-x: hidden;
padding: 0;
}
.selected {
background-color: cornsilk;
}
</style>
+3 -1
View File
@@ -3,13 +3,15 @@ import Vuex from 'vuex'
import auth from '@/store/modules/auth'
import domains from '@/store/modules/domains'
import identities from '@/store/modules/identities'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
auth,
domains
domains,
identities
},
strict: process.env.NODE_ENV !== 'production'
})
+34
View File
@@ -0,0 +1,34 @@
import domainApi from '@/api/domains'
const state = {
domains: []
}
const getters = {
domains: state => state.domains,
getDomainByName: state => name => {
return state.domains.find(domain => domain.name === name)
}
}
const mutations = {
SET_DOMAINS (state, domains) {
state.domains = domains
}
}
const actions = {
fetchDomains ({ commit }) {
domainApi.getDomains().then(resp => {
commit('SET_DOMAINS', resp.data)
})
}
}
export default {
namespaced: true,
state,
getters,
actions,
mutations
}
+6 -2
View File
@@ -26,15 +26,16 @@
</v-list>
</v-menu>
</v-toolbar>
<identity-list />
<identity-list ref="identities" />
<v-dialog
v-model="showCreationWizard"
fullscreen
scrollable
transition="dialog-bottom-transition"
persistent
>
<account-creation-form @close="closeCreationWizard" />
<account-creation-form @close="closeCreationWizard" @created="updateIdentities" />
</v-dialog>
</div>
</template>
@@ -56,6 +57,9 @@ export default {
methods: {
closeCreationWizard () {
this.showCreationWizard = false
},
updateIdentities () {
this.$refs.identities.fetchIdentities()
}
}
}