var check; var emailCheck; var passwordCheck; $(document).ready(function(){ var error =1; var message = ""; $('#txt_email, #txt_password, #txt_password2').keyup(function() { validateSignup(); }); $('#chk_terms, #chk_email, #chk_privacypop').click(function() { validateSignup(); }); $('#txt_first').focus(); setupCreateAccountButton(); }); function setupCreateAccountButton() { $('#btnCreate').click(function (e) { e.preventDefault(); //$('#btnCreate').prop('disabled', 'disabled'); validateSignup(); $('#txt_first').focus(); $('#txt_email2pop').bind("cut copy paste",function(e) { e.preventDefault(); }); if (error == "1") { toastr["error"](message, "Invalid details"); return; } if (!$('#chk_termspop').is(':checked')) { error = 1; toastr["error"]("Please accept the Terms and Conditions", "Problem with signup details"); return; } if (!$('#chk_privacypop').is(':checked')) { error = 1; toastr["error"]("Please accept the Privacy Policy", "Problem with signup details"); return; } if (!$('#chk_emailpop').is(':checked')) { error = 1; toastr["error"]("Please accept the email alerts", "Problem with signup details"); return; } emailCheck = $('#txt_email').val(); passwordCheck = $('#txt_password').val(); $.ajax({ method: "POST", url: "/controllers/user/create_user.php", data: { first: $('#txt_first').val(), last: $('#txt_last').val(), email: $('#txt_email').val(), password: $('#txt_password').val(), referrer: $('#referrer').val(), language_id: '16' }, dataType: "JSON", success: function (data) { if (data.error == 1) { toastr["error"](data.message, "Problem with signup details"); $('#btnCreate').prop('disabled', false); } else { $('#btnCreate').html(' Creating Account...'); $('#btnCreate').attr('disabled', 'disabled'); checkRequest2(data.request_id); check = setTimeout(function () { checkRequest2(data.request_id); }, 2000) } } }); }); } function validateSignup(){ error = 0; if ($('#txt_first').val().length < 3) { error = 1; message = "Please enter your first name"; $('#txt_password').removeClass('borderGreenRight'); return; } if (!isValidEmail($('#txt_email').val())) { $('#txt_email').removeClass('borderGreenRight'); message = "Invalid Email Address"; error = 1; return; } else { $('#txt_email').addClass('borderGreenRight'); } if ($('#txt_email').val() != $('#txt_email2pop').val()) { $('#txt_email').removeClass('borderGreenRight'); $('#txt_email2pop').removeClass('borderGreenRight'); message = "Email addresses do not match"; error = 1; return; } else { $('#txt_email').addClass('borderGreenRight'); $('#txt_email2pop').addClass('borderGreenRight'); } if ($('#txt_password').val().length < 6) { error = 1; message = "Password must be at least 6 characters"; $('#txt_password').removeClass('borderGreenRight'); return; } else { $('#txt_password').addClass('borderGreenRight'); } if ($('#txt_password').val() != $('#txt_password2pop').val() || $('#txt_password').val().length < 6) { error = 1; message = "Passwords do not match"; $('#txt_password2').removeClass('borderGreenRight'); return; } else { $('#txt_password2').addClass('borderGreenRight'); } } function checkRequest2(request){ $.ajax({ url: 'controllers/user/create_check.php', type: 'POST', dataType: 'JSON', data:{ check:'check_request', request:request, email: emailCheck, password: passwordCheck }, success: function (data) { if(data.error == 0){ if(data.is_complete == 1){ clearTimeout(check); window.location = 'https://office.mycryptoconsult.io/onetimelogin.php?l=' + data.reference_guid; } }else{ clearTimeout(check); swal({ type:'error', title:'Problem Creating Account', html:data.message }).then(function() { window.location.reload(); }) } } }); } function isValidEmail(email) { email = email.toLowerCase(); return /^[a-z0-9]+([-._+][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/.test(email) && /^(?=.{1,64}@.{4,64}$)(?=.{6,100}$).*/.test(email); }