/*========================================================================================= File Name: auth-login.js Description: Auth login js file. ---------------------------------------------------------------------------------------- Author: ACTOVISION Author URL: https://actovision.com ==========================================================================================*/ $(function () { 'use strict'; //Remove localstroge items localStorage.removeItem("OnLoadToast"); var pageLoginForm = $('.auth-login-form'); var magicLoginForm = $('.magic-login-form'); // jQuery Validation // -------------------------------------------------------------------- if (pageLoginForm.length) { pageLoginForm.validate({ /* * ? To enable validation onkeyup onkeyup: function (element) { $(element).valid(); },*/ /* * ? To enable validation on focusout onfocusout: function (element) { $(element).valid(); }, */ rules: { 'user_email': { required: true, email: true }, 'user_password': { required: true } }, submitHandler: function (form) { $.ajax({ type: "POST", url: "/api/auth_login", dataType: "json", data: $(form).serialize(), beforeSend: function () { $("button[type=button]").addClass('disabled'); Swal.fire({ title: 'Please wait...', html: 'We are validating your account.', allowEscapeKey: false, allowOutsideClick: false, didOpen: () => { Swal.showLoading() } }); }, success: function (response) { // console.log(response); if (response.status == 1) { window.location.href = response.data['redirect_to']; } else { Swal.fire({ title: 'Error !', text: response.message, icon: 'error', customClass: { confirmButton: 'btn btn-primary' }, buttonsStyling: false }); } } }); return false; // required to block normal submit since you used ajax } }); } /* Magic Login */ if (magicLoginForm.length) { magicLoginForm.validate({ /* * ? To enable validation onkeyup onkeyup: function (element) { $(element).valid(); },*/ /* * ? To enable validation on focusout onfocusout: function (element) { $(element).valid(); }, */ rules: { 'magic_user_email': { required: true, email: true } }, submitHandler: function (form) { $.ajax({ type: "POST", url: "/api/magic_auth_login", dataType: "json", data: $(form).serialize(), beforeSend: function () { $("button[type=button]").addClass('disabled'); Swal.fire({ title: 'Please wait...', html: 'We are validating your account.', allowEscapeKey: false, allowOutsideClick: false, didOpen: () => { Swal.showLoading() } }); }, success: function (response) { console.log(response); if (response.status == 1) { //window.location.href = response.data['redirect_to']; console.log(response); Swal.fire({ title: 'Success!', text: 'A login link will be sent to your email if an account with that email exists.', icon: 'success', customClass: { confirmButton: 'btn btn-primary' }, buttonsStyling: false }); } //else if (response.status == 3) { // window.location.href = response.data['redirect_to']; // console.log(response); //} else { Swal.fire({ title: 'Error ' + response.responseCode + '!', text: response.message, icon: 'error', customClass: { confirmButton: 'btn btn-primary' }, buttonsStyling: false }); } } }); return false; // required to block normal submit since you used ajax } }); } });