Files
newfreeplanet_OLD/src/components/CSignIn/CSignIn.ts

149 lines
3.3 KiB
TypeScript
Raw Normal View History

2021-09-16 21:08:02 +02:00
import { defineComponent, PropType, ref } from 'vue'
import { useI18n } from '@src/boot/i18n'
import { useUserStore } from '@store/UserStore'
import { useGlobalStore } from '@store/globalStore'
import { useQuasar } from 'quasar'
2021-09-04 15:05:34 +02:00
import { validationMixin } from 'vuelidate'
import { Logo } from '../logo'
import { static_data } from '../../db/static_data'
2021-09-16 21:08:02 +02:00
import { tools } from '@store/Modules/tools'
import { ISigninOptions } from 'model'
import { serv_constants } from '@store/Modules/serv_constants'
import { useRouter } from 'vue-router'
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
// import { useFormChild } from 'quasar'
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
export default defineComponent({
2021-09-04 15:05:34 +02:00
name: 'CSignIn',
2021-09-16 21:08:02 +02:00
components: { Logo },
props: {
showregbutt: {
type: Boolean,
required: true,
},
},
setup(props, { emit }) {
const $q = useQuasar()
const { t } = useI18n()
const userStore = useUserStore()
const $router = useRouter()
const globalStore = useGlobalStore()
const refUsername = ref(<any>null)
const refPassword = ref(null)
const loading = ref(false)
const myForm = ref(null)
const iswaitingforRes = ref(false)
const signin = ref(<ISigninOptions>{
username: process.env.TEST_USERNAME || '',
password: process.env.TEST_PASSWORD || '',
})
function onReset() {
signin.value.username = ''
signin.value.password = ''
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
function created() {
onReset()
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
if (userStore.resStatus === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
emit('showNotif', 'fetch.error_doppiologin')
}
2021-09-04 15:05:34 +02:00
}
2021-09-16 21:08:02 +02:00
function getlinkforgetpwd() {
return '/requestresetpwd'
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
function isError() {
if (refUsername.value) {
// @ts-ignore
return refUsername.value.hasError
2021-09-04 15:05:34 +02:00
}
}
2021-09-16 21:08:02 +02:00
function onSubmit() {
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
if (refUsername.value) {
refUsername.value.validate()
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
// console.log('submit LOGIN')
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
signin.value.username = tools.removespaces(signin.value.username)
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
// $v.signin.$touch()
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
if (isError()) {
emit('showNotif', 'reg.err.errore_generico')
return
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
emit('loginInCorso')
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
// disable Button Login:
iswaitingforRes.value = true
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
if (process.env.DEBUG) {
// console.log('signin', signin)
}
2021-09-04 15:05:34 +02:00
2021-09-16 21:08:02 +02:00
userStore.signin($router, signin.value)
.then((riscode: number) => {
console.log('signin FINITO CALL: riscode=', riscode)
if (riscode === tools.OK) {
// router.push('/signin')
}
return riscode
})
.then((riscode: number) => {
if (process.env.DEBUG) {
// console.log(' riscode(1) =', riscode)
}
return riscode
})
.then((riscode: number) => {
if (riscode === tools.OK) {
// console.log(' -> eseguo emit(loginOk)')
emit('loginOk')
globalStore.createPushSubscription()
2021-09-16 21:08:02 +02:00
} else {
emit('checkErrors', riscode)
}
iswaitingforRes.value = false
})
.catch((err: any) => {
// console.log('ERROR SIGNIN = ' + error)
emit('checkErrors', err)
})
// console.log(' END submit')
2021-09-04 15:05:34 +02:00
}
2021-09-16 21:08:02 +02:00
created()
return {
static_data,
refUsername,
onReset,
onSubmit,
signin,
getlinkforgetpwd,
myForm,
}
},
})