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

@@ -57,6 +57,7 @@
import { email, required } from "vuelidate/lib/validators"
import { UserStore } from "../../store/Modules";
import { IUserState } from "../../model";
import { tools } from "../../store/Modules/tools";
export default class RequestResetPwd extends Vue{
emailsent = false
form: IUserState = {
@@ -78,15 +79,11 @@
// }
// },
showNotif(msg: any) {
this.$q.notify(msg)
}
submit() {
this.$v.form.$touch()
if (this.$v.form.$error) {
this.showNotif(this.$t('reg.err.errore_generico'))
tools.showNotif(this.$q, this.$t('reg.err.errore_generico'))
return
}

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)

View File

@@ -9,51 +9,55 @@
<!--Prova URL : {{env('PROVA_PAOLO')}}-->
<form>
<div class="q-gutter-md">
<q-field
:error="$v.signin.username.$error"
:error-label="`${errorMsg('username', $v.signin.username)}`"
>
<q-input
v-model="signin.username"
rounded outlined
autocomplete="username"
@change="val => { signin.username = val }"
:before="[{icon: 'person', handler () {}}]"
@blur="$v.signin.username.$touch"
:error="$v.signin.username.$error"
:float-label="$t('reg.username_login')"></q-input>
</q-field>
:error-message="`${errorMsg('username', $v.signin.username)}`"
:label="$t('reg.username_login')">
<q-field
:error="$v.signin.password.$error"
:error-label="`${errorMsg('password', $v.signin.password)}`"
>
<template v-slot:prepend>
<q-icon name="person"/>
</template>
</q-input>
<q-input
v-model="signin.password"
type="password"
:before="[{icon: 'vpn_key', handler () {}}]"
rounded outlined
@blur="$v.signin.password.$touch"
:error="$v.signin.password.$error"
:float-label="$t('reg.password')"></q-input>
</q-field>
:error-message="`${errorMsg('password', $v.signin.password)}`"
:label="$t('reg.password')">
<template v-slot:prepend>
<q-icon name="vpn_key"/>
</template>
<div>
<a :href="getlinkforgetpwd">{{$t('reg.forgetpassword')}}</a>
</div>
</q-input>
<div>
<a :href="getlinkforgetpwd">{{$t('reg.forgetpassword')}}</a>
</div>
<br>
<br>
<q-card class="flex flex-center">
<!--<q-btn v-if="$myconfig.socialLogin.facebook" :loading="loading" class="q-mb-md q-mr-md" rounded icon="fab fa-facebook-f" size="sm" color="blue-10" text-color="white" @click="facebook" :label="$t('components.authentication.login.facebook')"/>-->
<!--
<q-btn v-if="$myconfig.socialLogin.facebook" class="q-mb-md q-mr-md" rounded icon="fab fa-facebook-f" size="sm" color="blue-10" text-color="white" @click="facebook" :label="$t('components.authentication.login.facebook')"/>
<q-btn v-if="$myconfig.socialLogin.google" class="q-mb-md q-mr-md" rounded icon="fab fa-google" size="sm" color="deep-orange-14" text-color="white" @click="google" :label="$t('components.authentication.login.google')"/>
-->
</q-card>
<q-card class="flex flex-center">
<!--<q-btn v-if="$myconfig.socialLogin.facebook" :loading="loading" class="q-mb-md q-mr-md" rounded icon="fab fa-facebook-f" size="sm" color="blue-10" text-color="white" @click="facebook" :label="$t('components.authentication.login.facebook')"/>-->
<!--
<q-btn v-if="$myconfig.socialLogin.facebook" class="q-mb-md q-mr-md" rounded icon="fab fa-facebook-f" size="sm" color="blue-10" text-color="white" @click="facebook" :label="$t('components.authentication.login.facebook')"/>
<q-btn v-if="$myconfig.socialLogin.google" class="q-mb-md q-mr-md" rounded icon="fab fa-google" size="sm" color="deep-orange-14" text-color="white" @click="google" :label="$t('components.authentication.login.google')"/>
-->
</q-card>
<div align="center">
<q-btn rounded size="lg" color="primary" @click="submit" :disable="$v.$error || iswaitingforRes">{{$t('login.enter')}}
</q-btn>
<div align="center">
<q-btn rounded size="lg" color="primary" @click="submit"
:disable="$v.$error || iswaitingforRes">{{$t('login.enter')}}
</q-btn>
</div>
</div>
</form>
</q-page>

View File

@@ -88,11 +88,6 @@ export default class Signup extends Vue {
return process.env
}
showNotif(params: any) {
this.$q.notify(params)
}
public errorMsg(cosa: string, item: any) {
try {
if (!item.$error) return ''
@@ -126,19 +121,19 @@ export default class Signup extends Vue {
checkErrors(riscode: number) {
console.log('checkErrors', riscode)
if (riscode === tools.DUPLICATE_EMAIL_ID) {
this.showNotif(this.$t('reg.err.duplicate_email'))
tools.showNotif(this.$q, this.$t('reg.err.duplicate_email'))
} else if (riscode === tools.DUPLICATE_USERNAME_ID) {
this.showNotif(this.$t('reg.err.duplicate_username'))
tools.showNotif(this.$q, this.$t('reg.err.duplicate_username'))
} 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)
tools.showNotif(this.$q, msg)
} else if (riscode === tools.OK) {
this.$router.push('/signin')
this.showNotif({type: 'warning', textColor: 'black', message: this.$t('components.authentication.email_verification.link_sent')})
tools.showNotif(this.$q, this.$t('components.authentication.email_verification.link_sent'), {color: 'warning', textColor: 'black'})
} else {
this.showNotif('Errore num ' + riscode)
tools.showNotif(this.$q, 'Errore num ' + riscode)
}
@@ -152,12 +147,12 @@ export default class Signup extends Vue {
this.duplicate_username = false
if (!this.signup.terms) {
this.showNotif(this.$t('reg.err.terms'))
tools.showNotif(this.$q, this.$t('reg.err.terms'))
return
}
if (this.$v.signup.$error) {
this.showNotif(this.$t('reg.err.errore_generico'))
tools.showNotif(this.$q, this.$t('reg.err.errore_generico'))
return
}

View File

@@ -69,6 +69,7 @@
import { required } from "vuelidate/lib/validators"
import { UserStore } from "../../store/Modules";
import { IUserState } from "../../model";
import { tools } from "../../store/Modules/tools";
export default class UpdatePassword extends Vue {
emailsent = false
@@ -96,15 +97,11 @@
// }
// },
showNotif(msg: any) {
this.$q.notify(msg)
}
submit() {
this.$v.form.$touch()
if (this.$v.form.$error) {
this.showNotif(this.$t('reg.err.errore_generico'))
tools.showNotif(this.$q, this.$t('reg.err.errore_generico'))
return
}