fix fields login

This commit is contained in:
Paolo Arena
2019-03-13 13:40:17 +01:00
parent 67748ce94f
commit 9376b397d7
21 changed files with 207 additions and 203 deletions

View File

@@ -1,12 +1,11 @@
import { GlobalStore, UserStore } from '@store'
import Vue from 'vue'
import { Component, Prop, Watch } from 'vue-property-decorator'
import { GlobalStore, UserStore } from '@store'
import { tools } from '../../../store/Modules/tools'
import { serv_constants } from '../../../store/Modules/serv_constants'
import { tools } from '../../../store/Modules/tools'
import { ISigninOptions, IUserState } from 'model'
import { validations, TSignin } from './signin-validate'
import { TSignin, validations } from './signin-validate'
import { validationMixin } from 'vuelidate'
@@ -18,31 +17,29 @@ import globalroutines from '../../../globalroutines/index'
// import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
@Component({
mixins: [validationMixin],
validations: validations,
validations,
components: { Logo }
})
export default class Signin extends Vue {
public $v
public $q
loading: boolean
$t: any
public loading: boolean
public $t: any
public iswaitingforRes: boolean = false
public signin: ISigninOptions = {
username: process.env.TEST_USERNAME || '',
password: process.env.TEST_PASSWORD
password: process.env.TEST_PASSWORD || ''
}
created() {
public created() {
this.$v.$reset()
if (UserStore.state.resStatus === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
this.showNotif(this.$t('fetch.error_doppiologin'))
tools.showNotif(this.$q, this.$t('fetch.error_doppiologin'))
}
// this.$myconfig.socialLogin.facebook = true
@@ -53,9 +50,6 @@ export default class Signin extends Vue {
return process.env
}
showNotif(msg: any) {
this.$q.notify(msg)
}
public getlinkforgetpwd() {
return '/requestresetpwd'
@@ -63,47 +57,47 @@ export default class Signin extends Vue {
public errorMsg(cosa: string, item: any) {
try {
if (!item.$error) return ''
if (item.$params.email && !item.email) return this.$t('reg.err.email')
if (!item.$error) { return '' }
if (item.$params.email && !item.email) { return this.$t('reg.err.email') }
if (!item.required) return this.$t('reg.err.required')
if (!item.minLength) return this.$t('reg.err.atleast') + ` ${item.$params.minLength.min} ` + this.$t('reg.err.char')
if (!item.maxLength) return this.$t('reg.err.notmore') + ` ${item.$params.maxLength.max} ` + this.$t('reg.err.char')
if (!item.required) { return this.$t('reg.err.required') }
if (!item.minLength) { return this.$t('reg.err.atleast') + ` ${item.$params.minLength.min} ` + this.$t('reg.err.char') }
if (!item.maxLength) { return this.$t('reg.err.notmore') + ` ${item.$params.maxLength.max} ` + this.$t('reg.err.char') }
return ''
} catch (error) {
// console.log("ERR : " + error);
}
}
checkErrors(riscode) {
public checkErrors(riscode) {
// console.log('checkErrors: ', riscode)
try {
if (riscode === tools.OK) {
this.showNotif({ type: 'positive', message: this.$t('login.completato') })
tools.showNotif(this.$q, this.$t('login.completato'), { color: 'positive', icon: 'check'})
this.$router.push('/')
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {
// Wait N seconds to avoid calling many times...
return new Promise(function (resolve, reject) {
setTimeout(function () {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('anything')
}, 3000)
}).then(() => {
setTimeout( () => {
this.$q.loading.hide()
}, 200)
this.showNotif(this.$t('login.errato'))
tools.showNotif(this.$q, this.$t('login.errato'))
this.iswaitingforRes = false
this.$router.push('/signin')
})
} else if (riscode === tools.ERR_SERVERFETCH) {
this.showNotif(this.$t('fetch.errore_server'))
tools.showNotif(this.$q, this.$t('fetch.errore_server'))
} else if (riscode === tools.ERR_GENERICO) {
let msg = this.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode)
this.showNotif(msg)
const msg = this.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode)
tools.showNotif(this.$q, msg)
} else {
this.showNotif('Errore num ' + riscode)
tools.showNotif(this.$q, 'Errore num ' + riscode)
}
if (riscode !== serv_constants.RIS_CODE_LOGIN_ERR) {
@@ -118,44 +112,46 @@ export default class Signin extends Vue {
}
}
redirect(response) {
public redirect(response) {
this.loading = false
window.location.href = response.data.redirect
}
error(error) {
public error(error) {
this.loading = false
this.$errorHandler(this, error)
}
facebook() {
public facebook() {
this.loading = true
this.$axios.get('/backend/loginFacebook')
.then(response => this.redirect(response))
.catch(error => this.error(error))
.then((response) => this.redirect(response))
.catch((error) => this.error(error))
}
google() {
public google() {
}
submit() {
public submit() {
this.$v.signin.$touch()
if (this.$v.signin.$error) {
this.showNotif(this.$t('reg.err.errore_generico'))
tools.showNotif(this.$q, this.$t('reg.err.errore_generico'))
return
}
let msg = this.$t('login.incorso')
if (process.env.DEBUG)
if (process.env.DEBUG) {
msg += ' ' + process.env.MONGODB_HOST
}
this.$q.loading.show({ message: msg})
// disable Button Login:
this.iswaitingforRes = true
if (process.env.DEBUG)
if (process.env.DEBUG) {
console.log('this.signin', this.signin)
}
UserStore.actions.signin(this.signin)
.then((riscode) => {
@@ -165,10 +161,12 @@ export default class Signin extends Vue {
}
return riscode
}).then((riscode) => {
if (UserStore.state.lang !== '')
this.$i18n.locale = UserStore.state.lang // Set Lang
else
UserStore.mutations.setlang(this.$i18n.locale) // Set Lang
if (UserStore.state.lang !== '') {
this.$i18n.locale = UserStore.state.lang
} // Set Lang
else {
UserStore.mutations.setlang(this.$i18n.locale)
} // Set Lang
// console.log('LANG ORA=', UserStore.state.lang)
@@ -178,10 +176,10 @@ export default class Signin extends Vue {
.then((riscode) => {
if (riscode === tools.OK) {
GlobalStore.actions.createPushSubscription()
.then(rissub => {
.then((rissub) => {
})
.catch(e => {
.catch((e) => {
console.log('ERROR Subscription = ' + e)
})
}
@@ -189,7 +187,7 @@ export default class Signin extends Vue {
this.checkErrors(riscode)
})
.catch(error => {
.catch((error) => {
console.log('ERROR SIGNIN = ' + error)
this.checkErrors(error)