Vue.component('create_account', { template: `
{{error_msg}}



تم ارسال رابط للتفعيل إلى : {{ email }}
سيتم تحويلك للصفحة الرئيسية.
`, props: ['api_url', 'site_url'], data: function () { return { valid: true, name: '', password: '', password_show: true, repeat_password: '', repeat_password_show: true, requiredRules: [ v => !!v || 'This field is required', ], passwordRules: [ v => !!v || 'Password is required', ], email: '', emailRules: [ v => !!v || 'E-mail is required', v => /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(v) || 'E-mail must be valid' ], select: null, checkbox: false, show_error: false, error_msg: '', is_loading: false, show_create_form: true, show_success_form: false, } }, watch: {}, methods: { submit(e) { e.preventDefault(); var proceed = true; if (this.password != this.repeat_password) { alert("passwords didn't match."); proceed = false; } else if (!(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(this.email))) { alert("Please enter a valid email address"); proceed = false; } // Native form submission is not yet supported var thisCompo = this; if(proceed) { this.is_loading = true; axios.post(this.api_url + '/users/create_account', { 'name': thisCompo.name, 'email': thisCompo.email, 'password': thisCompo.password, 'type': 'buyer' }).then(function (response) { var responseRes = response.data; if (responseRes.success) { setCookie("access_token", responseRes.data.access_token, 900); thisCompo.show_create_form = false; thisCompo.show_success_form = true; setTimeout(function () { window.location = thisCompo.site_url; }, 5000); } else { if (responseRes.data.error == 'email_used') { thisCompo.show_error = true; thisCompo.error_msg = thisCompo.email + ' is used by another user, if it is you, please try logging in or resetting your password.'; } } thisCompo.is_loading = false; }) .catch(function (error) { console.log(error); }); } }, clear() { this.$refs.form.reset(); } } });