Files
salvato.newfreeplanet/src/components/CSignUp/CSignUp.ts

208 lines
5.1 KiB
TypeScript
Raw Normal View History

2021-09-16 21:08:02 +02:00
import { tools } from '@store/Modules/tools'
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
import { ISignupOptions } from 'model'
2021-09-04 15:05:34 +02:00
import { Logo } from '../../components/logo'
// import 'vue-country-code/dist/vue-country-code.css'
import { CTitleBanner } from '../CTitleBanner'
2021-09-16 21:08:02 +02:00
import { computed, defineComponent, reactive, ref } from 'vue'
import { CSignIn } from '@/components/CSignIn'
import { useQuasar } from 'quasar'
import { useI18n } from '@/boot/i18n'
import { DefaultProfile, useUserStore } from '@store/UserStore'
import useValidate from '@vuelidate/core'
import useVuelidate from '@vuelidate/core'
2021-09-19 02:59:24 +02:00
import { email, minLength, required, sameAs } from '@vuelidate/validators'
// import { ValidationRuleset } from 'vuelidate'
import { complexity, registeredemail, registereduser } from '../../validation'
2021-09-16 21:08:02 +02:00
2021-09-19 02:59:24 +02:00
import 'vue3-tel-input/dist/vue3-tel-input.css'
2021-09-04 15:05:34 +02:00
// import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
2021-09-16 21:08:02 +02:00
export default defineComponent({
2021-09-04 15:05:34 +02:00
name: 'CSignUp',
2021-09-16 21:08:02 +02:00
components: { Logo, CTitleBanner },
props: {
showadultcheck: {
type: Boolean,
required: false,
default: false,
},
showcell: {
type: Boolean,
required: false,
default: false,
},
shownationality: {
type: Boolean,
required: false,
default: false,
},
},
setup(props, { emit }) {
const $q = useQuasar()
const { t } = useI18n()
const userStore = useUserStore()
const countryname = ref('')
const iamadult = ref(false)
const duplicate_email = ref(false)
const duplicate_username = ref(false)
const signup = reactive(<ISignupOptions> {
email: process.env.TEST_EMAIL || '',
username: process.env.TEST_USERNAME || '',
name: process.env.TEST_NAME || '',
surname: process.env.TEST_SURNAME || '',
password: process.env.TEST_PASSWORD || '',
repeatPassword: process.env.TEST_PASSWORD || '',
terms: !process.env.PROD,
profile: DefaultProfile,
aportador_solidario: '',
})
2021-09-19 02:59:24 +02:00
const validations: any = computed(() => {
return {
repeatPassword: {
required,
repeatPassword: sameAs(signup.password),
},
password: {
required,
minLength: minLength(8),
complexity,
},
username: {
required,
minLength: minLength(6),
registereduser,
},
name: {
required,
},
surname: {
required,
},
email: {
email,
registeredemail,
required,
},
terms: {
required,
},
}
})
2021-09-16 21:08:02 +02:00
// @ts-ignore
const v$ = useVuelidate(validations, signup)
function allowSubmit() {
let error = v$.value.$error || v$.value.$invalid
if (props.showadultcheck)
error = error || !iamadult.value
if (props.showcell) {
if (signup.profile)
error = error || signup.profile.cell!.length <= 6
else
error = true
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
return !error
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
function env() {
return process.env
2021-09-04 15:05:34 +02:00
}
2021-09-16 21:08:02 +02:00
function changeemail() {
signup.email = tools.removespaces(signup.email!)
signup.email = signup.email.toLowerCase()
emit('update:value', signup.email)
2021-09-04 15:05:34 +02:00
}
2021-09-16 21:08:02 +02:00
function changeusername(value: string) {
signup.username = tools.removespaces(signup.username)
emit('update:value', signup.username)
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
function submitOk() {
v$.value.$touch()
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
signup.email = tools.removespaces(signup.email!)
signup.email = signup.email.toLowerCase()
signup.username = tools.removespaces(signup.username)
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
duplicate_email.value = false
duplicate_username.value = false
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
if (!signup.terms) {
tools.showNotif($q, t('reg.err.terms'))
return
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
/*if (v$.signup.$error) {
tools.showNotif($q, t('reg.err.errore_generico'))
return
} */
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
signup.name = tools.CapitalizeAllWords(signup.name)
signup.surname = tools.CapitalizeAllWords(signup.surname)
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
$q.loading.show({ message: t('reg.incorso') })
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
console.log(signup)
return userStore.signup(tools.clone(signup))
.then((ris: any) => {
if (tools.SignUpcheckErrors($q, ris.code, ris.msg))
$q.loading.hide()
}).catch((error: string) => {
console.log('ERROR = ' + error)
$q.loading.hide()
})
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
function intcode_change(coderec: any) {
// console.log('intcode', coderec)
if (signup.profile) {
signup.profile.intcode_cell = '+' + coderec.dialCode
signup.profile.iso2_cell = coderec.iso2
}
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
function selectcountry({ name, iso2, dialCode }: { name: string, iso2: string, dialCode: string }) {
// console.log(name, iso2, dialCode)
signup.profile.nationality = iso2
countryname.value = name
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
function inputUsername(value: string) {
signup.username = value.trim()
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
return {
changeemail,
changeusername,
submitOk,
inputUsername,
selectcountry,
intcode_change,
tools,
countryname,
signup,
iamadult,
v$,
allowSubmit,
}
},
})