Files
myprojplanet_vite/src/views/requestresetpwd/requestresetpwd.ts

121 lines
3.0 KiB
TypeScript
Raw Normal View History

2021-09-16 21:08:02 +02:00
import { serv_constants } from '@store/Modules/serv_constants'
2025-03-01 14:14:43 +01:00
import { tools } from '@tools'
2021-09-16 21:08:02 +02:00
import { Logo } from '../../components/logo'
import { CTitleBanner } from '../../components/CTitleBanner'
import { defineComponent, reactive, ref, watch } from 'vue'
2025-03-01 14:14:43 +01:00
import { useI18n } from 'vue-i18n'
2021-09-16 21:08:02 +02:00
import { useUserStore } from '@store/UserStore'
import { useGlobalStore } from '@store/globalStore'
import { useQuasar } from 'quasar'
2021-09-17 17:30:01 +02:00
import useVuelidate from '@vuelidate/core'
import { validations } from '@src/views/requestresetpwd/request-resetpwd-validate'
import { useRouter } from 'vue-router'
2021-09-16 21:08:02 +02:00
export default defineComponent({
name: 'RequestResetPwd',
components: { Logo, CTitleBanner },
setup(props, { emit }) {
const $q = useQuasar()
const { t } = useI18n()
const userStore = useUserStore()
const globalStore = useGlobalStore()
const $router = useRouter()
2021-09-16 21:08:02 +02:00
const emailsent = ref(false)
2021-09-17 17:30:01 +02:00
const form = reactive({
2021-09-16 21:08:02 +02:00
email: '',
2022-12-11 02:57:45 +01:00
tokenforgot: '',
tokenforgot_code: ''
2021-09-16 21:08:02 +02:00
})
2021-09-17 17:30:01 +02:00
// @ts-ignore
const v$ = useVuelidate(validations, form)
const emailRef = ref(null)
watch(() => form.tokenforgot_code, (to: any, from: any) => {
checkCode()
})
2021-09-16 21:08:02 +02:00
function emailinviata() {
return emailsent.value
}
function submit() {
2021-09-17 17:30:01 +02:00
console.log('submit')
2021-09-16 21:08:02 +02:00
// v$.form.touch()
/*if (v$.form.$error) {
tools.showNotif($q, t('reg.err.errore_generico'))
return
}*/
2021-09-17 17:30:01 +02:00
// @ts-ignore
emailRef.value!.validate()
// @ts-ignore
if (emailRef.value!.hasError) {
// form has error
tools.showNotif($q, t('reg.err.errore_generico'))
return
}
2021-09-16 21:08:02 +02:00
$q.loading.show({ message: t('reset.incorso') })
2021-09-17 17:30:01 +02:00
form.tokenforgot = ''
2021-09-16 21:08:02 +02:00
2021-09-17 17:30:01 +02:00
userStore.requestpwd(form)
2021-09-16 21:08:02 +02:00
.then((ris: any) => {
if (ris.code === serv_constants.RIS_CODE_OK)
emailsent.value = true
else if (ris.code === serv_constants.RIS_CODE_EMAIL_NOT_EXIST)
tools.showNegativeNotif($q, t('reg.err.email_not_exist'))
$q.loading.hide()
2021-09-19 02:59:24 +02:00
}).catch((err: any) => {
console.log('ERROR = ' + err.error)
$q.loading.hide()
})
2021-09-16 21:08:02 +02:00
}
function checkCode() {
const mycode = form.tokenforgot_code.trim()
if (mycode.length === 6) {
$q.loading.show({ message: t('reset.incorso') })
// Check if code is correct
userStore.requestpwd(form)
.then((ris: any) => {
if (ris.code === serv_constants.RIS_CODE_OK) {
if (ris.link)
$router.replace(ris.link)
} else {
tools.showNegativeNotif($q, t('reg.err.code_resetpwd_error'))
}
form.tokenforgot_code = ''
$q.loading.hide()
}).catch((err: any) => {
console.log('ERROR = ' + err.error)
$q.loading.hide()
})
}
}
2021-09-16 21:08:02 +02:00
return {
emailinviata,
submit,
form,
2021-09-17 17:30:01 +02:00
emailRef,
2021-09-16 21:08:02 +02:00
v$,
2021-09-17 17:30:01 +02:00
tools,
checkCode,
2021-09-16 21:08:02 +02:00
}
}
})