2018-11-07 22:42:22 +01:00
|
|
|
import { Component, Vue, Prop } from 'vue-property-decorator'
|
|
|
|
|
import { UserModule } from '@/store/modules/user'
|
|
|
|
|
import { ErroriMongoDb } from '@/store/modules/user'
|
|
|
|
|
|
|
|
|
|
import { validationMixin } from 'vuelidate'
|
|
|
|
|
import { required, minValue } from 'vuelidate/lib/validators'
|
|
|
|
|
import { ISignupOptions, IUserState } from '@/model'
|
|
|
|
|
import { validations, TSignup } from './signup-validate'
|
2018-11-08 01:09:33 +01:00
|
|
|
|
|
|
|
|
import './signup.scss'
|
2018-11-07 22:42:22 +01:00
|
|
|
|
|
|
|
|
// import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
mixins: [validationMixin],
|
|
|
|
|
name: 'Signup',
|
|
|
|
|
validations: validations
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default class Signup extends Vue {
|
|
|
|
|
duplicate_email: boolean = false
|
|
|
|
|
duplicate_username: boolean = false
|
|
|
|
|
user: ISignupOptions = {
|
|
|
|
|
email: process.env.TEST_EMAIL,
|
|
|
|
|
username: process.env.TEST_USERNAME || '',
|
|
|
|
|
password: process.env.TEST_PASSWORD,
|
|
|
|
|
repeatPassword: process.env.TEST_PASSWORD
|
|
|
|
|
}
|
|
|
|
|
terms = true
|
|
|
|
|
|
|
|
|
|
$v: any
|
2018-11-08 01:09:33 +01:00
|
|
|
$t: any
|
2018-11-07 22:42:22 +01:00
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
created() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
|
if (this.$v) {
|
|
|
|
|
this.$v.$touch()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get allowSubmit() {
|
|
|
|
|
|
|
|
|
|
let error = this.$v.signup.$error || this.$v.signup.$invalid
|
|
|
|
|
return !error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
validations: {
|
|
|
|
|
isAsync: true,
|
|
|
|
|
form: {
|
|
|
|
|
email: {
|
|
|
|
|
required, email,
|
|
|
|
|
isUnique: value => {
|
|
|
|
|
if (value === '') return true;
|
|
|
|
|
return axios.get(process.env.MONGODB_HOST + '/email/' + value)
|
|
|
|
|
.then(res => {
|
|
|
|
|
return (res.status !== 200)
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
return true;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
password: {required, minLength: minLength(8), maxLength: maxLength(20)},
|
|
|
|
|
username: {
|
|
|
|
|
required, minLength: minLength(6), maxLength: maxLength(20),
|
|
|
|
|
isUnique: value => {
|
|
|
|
|
if (value === '') return true;
|
|
|
|
|
return axios.get(process.env.MONGODB_HOST + '/users/' + value)
|
|
|
|
|
.then(res => {
|
|
|
|
|
return (res.status !== 200)
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
return true;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
repeatPassword: {
|
|
|
|
|
sameAsPassword: sameAs('password')
|
|
|
|
|
},
|
|
|
|
|
terms: {required},
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}, */
|
|
|
|
|
env() {
|
|
|
|
|
return process.env
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showNotif(msg: any) {
|
|
|
|
|
this.$q.notify(msg)
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 01:09:33 +01:00
|
|
|
errorMsg(cosa: string, item: any) {
|
2018-11-07 22:42:22 +01:00
|
|
|
try {
|
|
|
|
|
if (!item.$error) return ''
|
|
|
|
|
if (item.$params.email && !item.email) return this.$t('reg.err.email')
|
|
|
|
|
|
|
|
|
|
if (cosa === 'repeatpassword') {
|
|
|
|
|
if (!item.sameAsPassword) {
|
|
|
|
|
return this.$t('reg.err.sameaspassword')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cosa === 'email') {
|
2018-11-08 01:09:33 +01:00
|
|
|
// console.log("EMAIL " + item.isUnique);
|
|
|
|
|
// console.log(item);
|
2018-11-07 22:42:22 +01:00
|
|
|
if (!item.isUnique) return this.$t('reg.err.duplicate_email')
|
|
|
|
|
} else if (cosa === 'username') {
|
2018-11-08 01:09:33 +01:00
|
|
|
// console.log(item);
|
2018-11-07 22:42:22 +01:00
|
|
|
if (!item.isUnique) return this.$t('reg.err.duplicate_username')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2018-11-08 01:09:33 +01:00
|
|
|
// console.log("ERR : " + error);
|
2018-11-07 22:42:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 01:09:33 +01:00
|
|
|
checkErrors(riscode: number) {
|
|
|
|
|
// console.log("RIS = " + riscode);
|
2018-11-07 22:42:22 +01:00
|
|
|
if (riscode === ErroriMongoDb.DUPLICATE_EMAIL_ID) {
|
|
|
|
|
this.showNotif(this.$t('reg.err.duplicate_email'))
|
|
|
|
|
} else if (riscode === ErroriMongoDb.DUPLICATE_USERNAME_ID) {
|
|
|
|
|
this.showNotif(this.$t('reg.err.duplicate_username'))
|
|
|
|
|
} else if (riscode === ErroriMongoDb.OK) {
|
|
|
|
|
this.$router.push('/')
|
|
|
|
|
} else {
|
2018-11-08 01:09:33 +01:00
|
|
|
this.showNotif('Errore num ' + riscode)
|
2018-11-07 22:42:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2018-11-08 01:09:33 +01:00
|
|
|
/*
|
2018-11-07 22:42:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
submit() {
|
|
|
|
|
this.$v.user.$touch()
|
|
|
|
|
|
|
|
|
|
this.duplicate_email = false
|
|
|
|
|
this.duplicate_username = false
|
|
|
|
|
|
|
|
|
|
if (!this.user.terms) {
|
|
|
|
|
this.showNotif(this.$t('reg.err.terms'))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.v.user.$error) {
|
|
|
|
|
this.showNotif(this.$t('reg.err.errore_generico'))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.$q.loading.show({ message: this.$t('reg.incorso') })
|
|
|
|
|
|
|
|
|
|
console.log(this.user)
|
|
|
|
|
UserModule.signup(this.user)
|
|
|
|
|
.then((riscode) => {
|
|
|
|
|
this.checkErrors(riscode)
|
|
|
|
|
this.$q.loading.hide()
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.log("ERROR = " + error)
|
|
|
|
|
this.$q.loading.hide()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|