var regxPass = new RegExp(/^[a-zA-Z\d]{6,32}$/); var regxUser = new RegExp(/^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]{3,32}$/); var regxPS1 = new RegExp(/^(0[bB]0)[0-9a-fA-F]{2}(0|2|4|6|8|[aA]|[cC]|[eE])$/); var regxPS2 = new RegExp(/^(0[bB]10)[0-9a-fA-F]{2}$/); var regIS = new RegExp(/^(0[bB]11)[0-9a-fA-F]{2}$/); var regI1 = new RegExp(/^(0[bB]2)[0-9a-fA-F]{3}$/); var regVier = new RegExp(/^(0[bB]80)[0-9a-fA-F]{2}$/); var regGoogleAnalytics = /(UA|YT|MO)-\d+-\d+/i; var validFolder = new RegExp(/^((?!\/)(?!\;)(?!\?)(?!\@)(?!\&)(?!\=)(?!\+)(?!\$).)*$/i); var regxUUID = new RegExp(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/); var opts_dp_onlydate = { format: 'L' } var opts_dp_onlytime = { format: 'LT' } var uploadkeepalive; var keepaliveURL = 'keepalive.php'; function keepalive(upd){ //console.log("KEEPALIVE" + upd) clearInterval(uploadkeepalive); uploadkeepalive = 0; if (upd){ keepaliveURL = 'keepalive.php?1'; } else { keepaliveURL = 'keepalive.php'; } uploadkeepalive = setInterval(function(){ /*$.get(keepaliveURL, function( data ) { //console.log(data) if (data.status < 1){ window.location.replace("login.php"); } });*/ $.ajax({ url: "//misenate.viebit.com/" + keepaliveURL, success: function( data ) { //console.log(data) if (data.status < 1){ window.location.replace("/"); } }, //timeout: 1 }); }, 60000); } function hexToRgb(hex) { // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; hex = hex.replace(shorthandRegex, function(m, r, g, b) { return r + r + g + g + b + b; }); var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null; } function getContrastYIQ(hex){ var r = hexToRgb(hex).r; var g = hexToRgb(hex).g; var b = hexToRgb(hex).b; var yiq = ((r*299)+(g*587)+(b*114))/1000; return (yiq >= 128) ? 'black' : 'white'; } function showAlert(msg, field){ $( field ).parent().addClass( "has-error" ); $( "#status" ).empty().append( "
Please enter the email address attached to your account below. An email will be dispatched with further instructions on how to reset your password.
", size: BootstrapDialog.SIZE_NORMAL, type: BootstrapDialog.TYPE_INFO, buttons: [buttonSubmitForgot, buttonClose], onshown: function(dialog){ $( "#email").focus(); $( "#forgot_form" ).submit(function( event ) { event.preventDefault(); $( "#status" ).empty(); if ($(this).find( "input[name='email']" ).val() == ""){ showAlert2("Please enter your email address","#email"); } else { var forgot_attempt = $.post( 'include/process_forgot_pass.php', { email: $( this ).find( "input[name='email']" ).val() } ); forgot_attempt.done(function( data ) { //console.log( data ); switch (data.responce){ case 1: //SUCCESS dialog.close(); BootstrapDialog.alert(dialogForgotSucess); break; case 2: //INVALID EMAIL showAlert2("The email address you entered is not valid.Please choose which destionation is used to send the unique, one time authentication code:
", size: BootstrapDialog.SIZE_SMALL, buttons: [{ label: ' Submit', cssClass: 'btn-success', action: function(dialog) { $( "#authsel_form" ).submit(); } }], onshown: function(dialog){ $( "#authsel_form" ).submit(function( event ) { event.preventDefault(); var postData = $(this).serializeArray(); var auth_attempt = $.post( 'include/send_auth_token.php', postData ); auth_attempt.done(function( data ) { if (data.responce == 1 || data.responce == 2){ var destSel = ""; switch (data.responce){ case 1: //SUCCESS destSel = "your mobile phone number ending in"; break; case 2: //BAD PASS destSel = "the email address"; break; } dialog.close(); BootstrapDialog.show({ title: 'Two-Factor Authentication', closable: true, message: "A code was sent to " + destSel + " " + data.dest + ". Please enter the code below to continue:
", size: BootstrapDialog.SIZE_SMALL, buttons: [{ label: ' Authenticate', cssClass: 'btn-success', action: function(dialog) { $( "#auth_form" ).submit(); } }], onshown: function(dialog){ $( "#auth_form" ).submit(function( event ) { event.preventDefault(); $( "#auth_status" ).empty(); $( ".form-group").removeClass( "has-error" ); var $form = $( this ), token = $form.find( "input[name='token']" ).val(); if (token == ""){ showAlert4("Please enter the code you recieved","#token"); } else { var auth_attempt = $.post( 'include/process_auth.php', { token: token } ); } auth_attempt.done(function( data ) { switch (data.responce){ case 1: //SUCCESS window.location.href = "/"; break; case 2: //BAD PASS showAlert4("The code you entered does not match.Since this is your first visit we'd like to offer you the opportunity to change your password from the default you were given. Please enter a new password and confirm it below:
", size: BootstrapDialog.SIZE_SMALL, buttons: [{ label: ' Change Password', cssClass: 'btn-success', action: function(dialog) { $( "#pass_reset" ).submit(); } }], onshown: function(dialog){ $( "#pass_reset" ).submit(function( event ) { event.preventDefault(); $( "#status" ).empty(); $( ".form-group").removeClass( "has-error" ); var $form = $( this ), password_val = $form.find( "input[name='new_password']" ).val(); passwordConf_val = $form.find( "input[name='confim_new_password']" ).val(); if (password_val == ""){ showAlert3("Please enter a new password","#new_password"); } else { if (!regxPass.test(password_val)){ showAlert3("You have entered an invalid password","#new_password"); } else { if (password_val != passwordConf_val){ showAlert3("The passwords you have entered do not match. Please try again.","#confim_new_password"); } else { var reset_attempt = $.post( 'include/process_pass_chg_at_login.php', { password: password_val } ); reset_attempt.done(function( data ) { switch (data.responce){ case 1: //SUCCESS dialog.close(); BootstrapDialog.show({ title: 'Password Reset', closable: true, message: "Thank you for securing your account.
", size: BootstrapDialog.SIZE_SMALL, buttons: [{ label: 'Close', cssClass: 'btn-success', action: function(dialog) { window.location.href = "/"; } }], onshown: function(dialog){ setTimeout(function() { window.location.href = "/"; }, 3000); } }); break; } }); } } } }); } } $('.vbNavTop .btnLogin').off('click').on('click', function() { BootstrapDialog.show({ title: ' User Login', closable: false, message: "", size: BootstrapDialog.SIZE_SMALL, type: BootstrapDialog.TYPE_INFO, buttons: [buttonForgot, buttonLogin, buttonClose], onshown: function(dialog){ $( "#username").focus(); $( "#login_form" ).submit(function( event ) { event.preventDefault(); $( "#status" ).empty(); //$( ".form-group").removeClass( "has-error" ); //var postData = $(this).serializeArray(); //console.log(postData) var form = $( "#login_form" ), username_val = form.find( "input[name='username']" ).val(); password_val = form.find( "input[name='password']" ).val(); if (username_val == ""){ showAlert("Please enter your username to login","#username"); } else { if (!regxUser.test(username_val)){ showAlert("You have entered an invalid username","#username"); } else { if (password_val == ""){ showAlert("Please enter your password to login","#password"); } else { if (!regxPass.test(password_val)){ showAlert("You have entered an invalid password","#password"); } else { var hashUserPass = Sha256.hash(username_val + ":" + password_val); hashAll = Sha256.hash(hashUserPass + ":"); var login_attempt = $.post( 'include/process_login.php', { username: username_val, hash: hashAll } ); } } } } login_attempt.done(function( data ) { //console.log(data); switch (data.responce){ case 1: //SUCCESS //window.location.href = "/"; window.location.reload(); break; case 2: //BAD PASS showAlert("Incorrect Password","#password"); break; case 3: //UNKNOWN USER showAlert("Unknown user account","#username"); break; case 4: //NO DATA showAlert("ERROR","#password"); break; case 5: //AUTHENTICATE //dialog.setTitle('Two-Factor Authentication'); //dialog.setMessage("Please choose which destionation is used to send the unique, one time authentication code:
"); dialog.close(); BootstrapDialog.show(dialogTwoFactor); $('cell_phone').text(data.cell) $('email').text(data.email) break; case 7: //FIRST LOGIN - REQUIRE PASS CHANGE dialog.close(); BootstrapDialog.show(dialogFirstVisit); break; } }); }); } }); }); $('.vbNavTop .btnProfile').off('click').on('click', function() { BootstrapDialog.show({ title: ' User Profile', closable: false, message: "", size: BootstrapDialog.SIZE_NORMAL, type: BootstrapDialog.TYPE_INFO, buttons: [buttonChangePass, buttonSave, buttonClose], onshow: function(dialog){ $dialogHead = dialog.getModalHeader(); $dialogBody = dialog.getModalBody(); $dialogFooter = dialog.getModalFooter(); $dialogBody.find('input[name=chk2Factor]').bootstrapToggle('on'); $.getJSON( "//misenate.viebit.com/admin/data_users.php", function( data ) { //console.log(data) var id = data[0].user_id; //$dialogBody.find("input[name='user_id']").val(data[0].user_id); $dialogBody.find("input[name='txtUserName']").val(data[0].username); $dialogBody.find("input[name='txtUserMobilePhone']").val(data[0].mobile_phone).mask('(000) 000-0000').trigger('keyup'); $dialogBody.find("input[name='txtUserEmail']").val(data[0].email); if (data[0].bypass == 1){ $dialogBody.find("input[name='chk2Factor']").bootstrapToggle('on'); } else { $dialogBody.find("input[name='chk2Factor']").bootstrapToggle('off'); } //$dialogBody.find("#btnPasswordMod").attr("value", data[0].user_id); //$dialogBody.find("#btnPasswordMod").attr("data-name", data[0].username); var validator = $dialogBody.find("form").validate({ onkeyup: false, //errorContainer: "#profileErrors", rules: { txtUserMobilePhone: { required: true, phoneUS: true }, txtUserEmail: { required: true, email: true } }, messages: { txtUserMobilePhone: { required: "Please enter your mobile telephone number including the area code", phoneUS: "Please enter a valid US telephone number" } }, invalidHandler: function() { console.log(validator.numberOfInvalids() + " field(s) are invalid" ); }, submitHandler: function (){ if (!$dialogBody.find("input[name='chk2Factor']").prop('checked')){ BootstrapDialog.show({ type:BootstrapDialog.TYPE_WARNING, title: ' WARNING', message:'Two-Factor authentication has been enabled by default to protect your site. Disabling this feature is NOT recomended.