Vue.component('login', {
template: `
سيتم تحويلك للصفحة الرئيسية.
`,
props: ['api_url', 'site_url'],
data: function () {
return {
valid: true,
name: '',
password: '',
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() {
this.is_loading = true;
// Native form submission is not yet supported
var thisCompo = this;
axios.post(this.api_url + '/users/auth', {
'email': thisCompo.email,
'password': thisCompo.password,
}).then(function (response) {
var responseRes = response.data;
if (responseRes.success) {
setCookie("access_token", responseRes.data.access_token, 900);
unsetCookie("enaseej_scid");
unsetCookie("enaseej_wlid");
thisCompo.show_create_form = false;
thisCompo.show_success_form = true;
window.location = thisCompo.site_url;
} else {
thisCompo.show_error = true;
}
thisCompo.is_loading = false;
})
.catch(function (error) {
console.log(error);
});
},
clear() {
this.$refs.form.reset()
}
}
});