$(document).on("keypress", "#username,#password", function (e) { let key = e.keyCode; if (key == 32) { return false; } }); new Vue({ el: "#loginModal", data() { return { modalVisible: true, pre_loader: true, form: { username: login_username, password: login_password, }, }; }, mounted() { this.pre_loader = false; }, methods: { async doLogin() { console.log("start doLogin"); let app = this; if (app.form.username.trim().length == 0) { $("#username").focus(); sweetAlert2("warning", "กรุณาระบุเบอร์มือถือ"); } else if (app.form.username.trim().length != 10) { $("#username").focus(); sweetAlert2("warning", "เบอร์มือถือไม่ถูกต้อง"); } else if (app.form.password.trim().length == 0) { $("#password").focus(); sweetAlert2("warning", "กรุณาระบุพาสเวิร์ด"); } else if (app.form.password.trim().length < 5) { $("#password").focus(); sweetAlert2("warning", "พาสเวิร์ดต้องมี 6 ตัวอักษรขึ้นไป"); } else { app.pre_loader = true; await axios .post(BaseURL + "auth/login", Qs.stringify(app.form), { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", }) .then((response) => { app.pre_loader = false; if (atob(response.data.qrlq) === "admin") { if (response.data.result && response.data.qacscq !== "") { app.modalVisible = false; Swal.fire({ title: "แจ้งเตือน", text: "กรุณากรอกเลข 6 หลัก", showConfirmButton: true, showCancelButton: true, input: "text", inputLabel: "2fanumber", inputPlaceholder: "เลข 6 หลัก", confirmButtonText: "ตกลง", cancelButtonText: "ยกเลิก", }).then(async (result) => { if ( result.value !== "" && typeof result.value !== "undefined" ) { let data = JSON.stringify({ username: app.form.username, password: app.form.password, code_check: result.value, }); await axios .post(BaseURL + "auth/check_2fa_login", data, { headers: { "Content-Type": "application/json" }, }) .then((res) => { if (res.data.result) { location.href = "dashboard"; } else { Swal.fire({ title: "แจ้งเตือน", text: "รหัสยืนยันไม่ถูกต้อง", showConfirmButton: true, confirmButtonText: "ตกลง", }).then((result) => { location = ""; }); } }) .catch((err) => { console.log({ err }); }); } else { Swal.fire({ title: "แจ้งเตือน", text: "ทำรายการไม่สำเร็จ", showConfirmButton: true, confirmButtonText: "ตกลง", }); location = ""; } }); } else { } } else { if (response.data.result) { location.href = "dashboard"; } else { sweetAlert2("error", response.data.message); } } }) .catch((err) => { app.pre_loader = false; sweetAlert2("warning", "ทำรายการไม่สำเร็จ"); }); } }, }, });