From 74e79c5618a01eeda8388e47319687ce9485792c Mon Sep 17 00:00:00 2001 From: axolotle Date: Sun, 24 Sep 2023 18:19:31 +0200 Subject: [PATCH] domain: add recovery password in DomainForm --- app/src/i18n/locales/en.json | 12 +++-- app/src/views/PostInstall.vue | 15 ++++-- app/src/views/_partials/DomainForm.vue | 67 +++++++++++++++++++++----- app/src/views/domain/DomainAdd.vue | 6 +-- 4 files changed, 75 insertions(+), 25 deletions(-) diff --git a/app/src/i18n/locales/en.json b/app/src/i18n/locales/en.json index 9a4af8a7..f4af5bd1 100644 --- a/app/src/i18n/locales/en.json +++ b/app/src/i18n/locales/en.json @@ -242,6 +242,14 @@ "disabled": "Disabled", "dns": "DNS", "domain": { + "add": { + "from_registrar": "I want to add a domain I own", + "from_registrar_desc": "Depending on your registrar, you'll have different ways of setting up the DNS configuration. YunoHost's diagnosis will guide you about what DNS records to configure", + "from_yunohost": "I want to add or register a YunoHost's free service domain", + "from_yunohost_desc": "YunoHost domain service will automatically handle the DNS configuration for you.", + "dyn_dns_password": "Domain recovery password", + "dyn_dns_password_desc": "This password will allow you to later recover control of the domain if you reinstall your system. If you already registered this domain, use your password here to reclaim it." + }, "cert": { "types": { "letsencrypt": "Let's Encrypt", @@ -289,11 +297,7 @@ } }, "domain_add": "Add domain", - "domain_add_dns_doc": "… and I have set my DNS correctly.", - "domain_add_dyndns_doc": "… and I want a dynamic DNS service.", "domain_add_dyndns_forbidden": "You have already subscribed to a DynDNS domain, you can ask to remove your current DynDNS domain on the forum in the dedicated thread.", - "domain_add_panel_with_domain": "I already have a domain name…", - "domain_add_panel_without_domain": "I don't have a domain name…", "domain_default_desc": "The default domain is the connection domain where users log in.", "domain_default_longdesc": "This is your default domain.", "domain_delete_forbidden_desc": "You cannot remove '{domain}' since it's the default domain, you need to choose another domain (or add a new one) and set it as the default domain to be able to remove this one.", diff --git a/app/src/views/PostInstall.vue b/app/src/views/PostInstall.vue index 97366aa9..7b71c827 100644 --- a/app/src/views/PostInstall.vue +++ b/app/src/views/PostInstall.vue @@ -86,6 +86,7 @@ import { validationMixin } from 'vuelidate' import api from '@/api' import { DomainForm } from '@/views/_partials' import Login from '@/views/Login.vue' +import { formatFormData } from '@/helpers/yunohostArguments' import { alphalownum_, required, minLength, name, sameAs } from '@/helpers/validators' export default { @@ -103,6 +104,7 @@ export default { step: 'start', serverError: '', domain: undefined, + dyndns_recovery_password: '', user: { username: '', fullname: '', @@ -142,8 +144,9 @@ export default { this.step = step }, - setDomain ({ domain }) { + setDomain ({ domain, dyndns_recovery_password }) { this.domain = domain + this.dyndns_recovery_password = dyndns_recovery_password this.goToStep('user') }, @@ -155,13 +158,15 @@ export default { this.performPostInstall() }, - performPostInstall (force = false) { - const data = { + async performPostInstall (force = false) { + const data = await formatFormData({ domain: this.domain, + dyndns_recovery_password: this.dyndns_recovery_password, username: this.user.username, fullname: this.user.fullname, - password: this.user.password - } + password: this.user.password, + }) + // FIXME does the api will throw an error for bad passwords ? api.post( 'postinstall' + (force ? '?force_diskspace' : ''), diff --git a/app/src/views/_partials/DomainForm.vue b/app/src/views/_partials/DomainForm.vue index e084b7e3..ec9677bd 100644 --- a/app/src/views/_partials/DomainForm.vue +++ b/app/src/views/_partials/DomainForm.vue @@ -14,11 +14,11 @@ :aria-expanded="domainIsVisible ? 'true' : 'false'" aria-controls="collapse-domain" > - {{ $t('domain_add_panel_with_domain') }} + {{ $t('domain.add.from_registrar') }} - + - {{ $t('domain_add_panel_without_domain') }} + {{ $t('domain.add.from_yunohost') }} - {{ $t('domain_add_dyndns_doc') }} + {{ $t('domain.add.from_yunohost_desc') }} + + + +
@@ -54,8 +66,8 @@ import { mapGetters } from 'vuex' import { validationMixin } from 'vuelidate' import AdressInputSelect from '@/components/AdressInputSelect.vue' -import { formatFormDataValue } from '@/helpers/yunohostArguments' -import { required, domain, dynDomain } from '@/helpers/validators' +import { formatFormData } from '@/helpers/yunohostArguments' +import { required, domain, dynDomain, minLength, sameAs } from '@/helpers/validators' export default { name: 'DomainForm', @@ -72,7 +84,9 @@ export default { form: { domain: '', - dynDomain: { localPart: '', separator: '.', domain: 'nohost.me' } + dynDomain: { localPart: '', separator: '.', domain: 'nohost.me' }, + dynDomainPassword: '', + dynDomainPasswordConfirmation: '' }, fields: { @@ -92,6 +106,25 @@ export default { type: 'domain', choices: ['nohost.me', 'noho.st', 'ynh.fr'] } + }, + + dynDomainPassword: { + label: this.$i18n.t('domain.add.dyn_dns_password'), + description: this.$i18n.t('domain.add.dyn_dns_password_desc'), + props: { + id: 'dyn-dns-password', + placeholder: '••••••••', + type: 'password' + } + }, + + dynDomainPasswordConfirmation: { + label: this.$i18n.t('password_confirmation'), + props: { + id: 'dyn-dns-password-confirmation', + placeholder: '••••••••', + type: 'password' + } } } } @@ -120,18 +153,26 @@ export default { validations () { return { selected: { required }, - form: { - domain: this.selected === 'domain' ? { required, domain } : {}, - dynDomain: { localPart: this.selected === 'dynDomain' ? { required, dynDomain } : {} } - } + form: this.selected === 'domain' + ? { domain: { required, domain } } + : { + dynDomain: { localPart: { required, dynDomain } }, + dynDomainPassword: { passwordLenght: minLength(8) }, + dynDomainPasswordConfirmation: { passwordMatch: sameAs('dynDomainPassword') } + } } }, methods: { async onSubmit () { const domainType = this.selected - const domain = await formatFormDataValue(this.form[domainType]) - this.$emit('submit', { domain, domainType }) + const form = await formatFormData({ + domain: this.form[domainType], + dyndns_recovery_password: domainType === 'dynDomain' + ? this.form.dynDomainPassword + : '' + }) + this.$emit('submit', form) } }, diff --git a/app/src/views/domain/DomainAdd.vue b/app/src/views/domain/DomainAdd.vue index 6b9cfee1..799addcd 100644 --- a/app/src/views/domain/DomainAdd.vue +++ b/app/src/views/domain/DomainAdd.vue @@ -24,11 +24,11 @@ export default { }, methods: { - onSubmit ({ domain, domainType }) { - const uri = 'domains' + (domainType === 'dynDomain' ? '?dyndns' : '') + onSubmit (data) { api.post( - { uri, storeKey: 'domains' }, { domain }, { key: 'domains.add', name: domain } + 'domains', data, { key: 'domains.add', name: data.domain } ).then(() => { + this.$store.dispatch('RESET_CACHE_DATA', ['domains']) this.$router.push({ name: 'domain-list' }) }).catch(err => { if (err.name !== 'APIBadRequestError') throw err