/* Account Settings Page validation - Start */ var enteredUserNameField = false; var enteredPasswordField = false; var enteredEmailAddressField = false; var validUserName = false; var validPassword = false; var validEmailAddress = false; var pvtKeyFieldEnabled = false; var enteredPvtKeyField = false; var validPrivateKey = false; var accountSettingTimeout; var updatedUserName; function pageLoad() { var errorMsgStr = "."; var errorMsgElement = document.getElementById("errorMsg"); errorMsgElement.innerHTML = errorMsgStr.fontcolor("WHITE"); var userNameElement = document.getElementById("userName"); setTimeout(function(){userNameElement.focus()}, 10); } function setUserNameStatus() { enteredUserNameField = true; } function setPasswordStatus() { enteredPasswordField = true; } function setEmailAddressStatus() { enteredEmailAddressField = true; } function validateUserName() { if(enteredUserNameField) { validUserName = false; var userNameElement = document.getElementById("userName"); if(userNameElement.value != "") { var strUserName = userNameElement.value; strUserName = strUserName.replace(/\s+/g, ""); if(strUserName == "") { var errorMsgStr = "Username field contains only whitespaces"; /*jQuery('.error_msg').show( 500, function() { setTimeout("jQuery('.error_msg').hide('slow');",5000 ); }); jQuery('.error_msg p').html(errorMsgStr);*/ showErrorMessages('.head_search .error_msg',errorMsgStr); userNameElement.value = ""; setTimeout(function(){userNameElement.focus()}, 10); } else { validUserName = true; var passwordElement = document.getElementById("password"); setTimeout(function(){passwordElement.focus()}, 10); } } else { var errorMsgStr = "Username field cannot be blank"; /* jQuery('.error_msg p').html(errorMsgStr); jQuery('.error_msg').show( 500, function() { setTimeout("jQuery('.error_msg').hide('slow');",5000 ); });*/ showErrorMessages('.head_search .error_msg',errorMsgStr); setTimeout(function(){userNameElement.focus()}, 10); } } } function validatePassword() { if(validUserName && enteredPasswordField) { validPassword = false; var passwordElement = document.getElementById("password"); if(passwordElement.value != "") { var strPassword = passwordElement.value; strPassword = strPassword.replace(/\s+/g, ""); if(strPassword == "") { var errorMsgStr = "Password field contains only whitespaces"; /* jQuery('.error_msg p').html(errorMsgStr); jQuery('.error_msg').show( 500, function() { setTimeout("jQuery('.error_msg').hide('slow');",5000 ); });*/ showErrorMessages('.head_search .error_msg',errorMsgStr); passwordElement.value = ""; setTimeout(function(){passwordElement.focus()}, 10); } else { validPassword = true; } } else { var errorMsgStr = "Password field cannot be blank"; /*jQuery('.error_msg p').html(errorMsgStr); jQuery('.error_msg').show( 500, function() { setTimeout("jQuery('.error_msg').hide('slow');",5000 ); });*/ showErrorMessages('.head_search .error_msg',errorMsgStr); setTimeout(function(){passwordElement.focus()}, 10); } } } function changePrivateKeyFieldStatus(encTypeObj) { if(encTypeObj.value == "Default") { var privateKeyFieldElement = document.getElementById("pvtKey"); privateKeyFieldElement.value = ""; privateKeyFieldElement.disabled = true; jQuery("input#pvtKey").addClass('pvtKey_grey'); pvtKeyFieldEnabled = false; var pattern = /^Private Key field/; var errorMsgElement = document.getElementById("errorMsg"); var errorMsgElementString = errorMsgElement.childNodes[0].textContent; if(pattern.test(errorMsgElementString)) { var errorMsgStr = "."; errorMsgElement.innerHTML = errorMsgStr.fontcolor("WHITE"); } } else if(encTypeObj.value == "Private") { var privateKeyFieldElement = document.getElementById("pvtKey"); privateKeyFieldElement.disabled = false; jQuery("input#pvtKey").removeClass('pvtKey_grey'); pvtKeyFieldEnabled = true; setTimeout(function(){privateKeyFieldElement.focus()}, 10); } } function checkPrivateKeyFieldStatus() { var encTypeElement = document.getElementById("encType"); if(encTypeElement.value == "Default") { pvtKeyFieldEnabled = false; } else if(encTypeElement.value == "Private") { pvtKeyFieldEnabled = true; } } function setPvtKeyStatus() { enteredPvtKeyField = true; } function validatePvtKey() { var encryptionKey = jQuery('input[name="encryptionKey"]:checked').val(); if(encryptionKey == 'private') { var pvtKeyElement = document.getElementById("pvtKey"); var validPrivateKey = false; if(pvtKeyElement.value != "") { var strPvtKey = pvtKeyElement.value; var strPvtKeyCopy = strPvtKey.replace(/\s+/g, ""); if(strPvtKeyCopy == "") { var errorMsgStr = "Private Key field contains only whitespaces"; showErrorMessages('.error_msg', errorMsgStr); pvtKeyElement.value = ""; setTimeout(function() { pvtKeyElement.focus(); }, 10); return false; } else { var lenPvtKey = strPvtKey.length; if(lenPvtKey < 6 || lenPvtKey > 250) { var errorMsgStr = "Private encryption key must be between 6 and 250 characters in length."; showErrorMessages('.error_msg', errorMsgStr); pvtKeyElement.value = ""; setTimeout(function() { pvtKeyElement.focus(); }, 10); return false; } else { validPrivateKey = true; } } var confmPvtKeyElement = document.getElementById("confmPvtKey"); if(confmPvtKeyElement.value != "") { if(pvtKeyElement.value != confmPvtKeyElement.value) { var errorMsgStr = "Encryption key and confirm encryption key must be the same."; showErrorMessages('.error_msg', errorMsgStr); confmPvtKeyElement.value = ""; setTimeout(function() { confmPvtKeyElement.focus(); }, 10); return false; } } else { var errorMsgStr = "Please enter the confirm encryption key"; showErrorMessages('.error_msg',errorMsgStr); confmPvtKeyElement.value = ""; setTimeout(function(){confmPvtKeyElement.focus()}, 10); return false; } ajaxCallForEncryption('set'); } else { var errorMsgStr = "Private Key field cannot be blank"; showErrorMessages('.error_msg', errorMsgStr); setTimeout(function(){ pvtKeyElement.focus(); }, 10); } return false; } ajaxCallForEncryption('set'); return false; } function validateForm1() { var idriveUserName = jQuery('#registered_user').html(); if(idriveUserName!=''){ return false; } setUserNameStatus(); validateUserName(); setPasswordStatus(); validatePassword(); if(validUserName && validPassword) { jQuery('.error_msg').hide(); var prevAlertMsg = jQuery('.alert p').html(); jQuery('.alert p').html('Verifying your account details...Please wait').parent().show('slow'); jQuery('html,body').scrollTop(0); var actualUsername = jQuery('#username').val(); jQuery('#username').val(rawurlencode(actualUsername)); var actualPassword = jQuery('#password').val(); //jQuery('#password').val(base64_encode(actualPassword)); jQuery('#passwordHidden').val(rawurlencode(actualPassword)); var data = jQuery("form[name*='accountSettingsForm']").serialize(); jQuery('.alert,#page_loader').show(); //AJAX call to validate the username & password $.ajax({ url: "account.php", type: "POST", data: data, success: function(validatedData){ if(validatedData.indexOf('')>0){ window.location.href='../index.php'; } validatedRes=$.parseJSON(validatedData); if(validatedRes[0]==false){ jQuery('.alert,#page_loader').hide(); if(validatedRes[1]=="MULTIPLE_ACCOUNT"){ var idriveUsernameListHTML = ''; jQuery(".userNameField").html(idriveUsernameListHTML); jQuery('#password').val(''); jQuery('#passwordHidden').val(''); jQuery('.account-desc').html('Multiple accounts are associated with your email, select a Username'); } else { showErrorMessages('.error_msg',validatedRes[1]); jQuery('#password').val(actualPassword); jQuery('#passwordHidden').val(rawurlencode(actualPassword)); } } else { jQuery('.alert,#page_loader').hide(); $('#toplink_upgrade').show(); if(validatedRes[1]=="Default"){ //AJAX call to create account settings file //$('#idriveUserInfo').show(); createAccountSettings(); clearTimeout(activeJobsTimeoutVar); activeJobsTimeoutVar = setTimeout(watcherForActiveJobs, PROGRESS_WATCHER_ENABLE_TIME); setTimeout(processNextScheduledEvent, 1000); } else if(validatedRes[1]=="Private"){ jQuery('#getEncryptionKey').show().siblings('div').hide(); jQuery('#encrypt_key').focus(); } else if(validatedRes[1]=="NotSet"){ jQuery('#configEncryption').show().siblings('div').hide(); } updatedUserName = validatedRes[2]; } if (machine == 'twotier') { $('.update-btn>a').click(function() { $('#page_loader').show(); showErrorMessages('.alert','Updating...'); }); } } }); return false; } else { $('#nse_main_div').hide(); return false; } } /* Account Settings Page validation - End */ /* Logoff account settings - Start */ jQuery('#logoff,.lotw_logout').die('click').live('click', function (event) { if(jQuery('#registered_user').html()==''){ //commented to fix Yuvaraj_2.04.06_06_2 : //jQuery('.error_msg p').html('Your account has already been logged off'); /*jQuery('.error_msg').show( 500, function() { setTimeout(function(){ jQuery('.error_msg').removeAttr("title"); //jQuery('.error_msg p').html('Login to IDrive'); },5000 ); });*/ jQuery('html,body').scrollTop(0); // Hide the div if user is logging off $("#nse_main_div").hide(); } else { //AJAX call to logoff account settings $.ajax({ url: "action.php?action=logoff", success: function(logoffData){ if(logoffData.indexOf('')>0){ window.location.href='../index.php'; } // Hide the div if user is logging off $("#nse_main_div").hide(); //clearing progress details if(ajaxRequestJobs) abortAjax(ajaxRequestJobs); activeJobsTimeoutVar = ''; progressJobBackupCount = 0; progressJobRestoreCount = 0; $("#RestoreProgress").html(""); $("#BackupProgress").html(""); $(".activity_prog_con,.progress_box,.drag_body_con").css("display","none"); $("#ptype").val(""); logoffRes=$.parseJSON(logoffData); if(logoffRes[0]==true){ //jQuery('.idr_user h3').html(logoffRes[2]); jQuery('#registered_user').html(''); $('#idriveUserInfo').hide(); $('#toplink_upgrade').hide(); /* Reset account usage - Start */ jQuery('.storage_used').html(''); //Clearing All Global Array clearArrayValues(); //For IDrive Vault //if(machine=='twotier'){ jQuery('.sliding a:first').trigger('click'); showErrorMessages('.welcome_message',logoffRes[1]); return false; //} /* showErrorMessages('.welcome_message',logoffRes[1]); jQuery('.login-bgliner').show(); jQuery('.disable_save').hide(); jQuery('input[name="save"]').show(); jQuery('.disable_logoff').show(); jQuery('#logoff').hide(); jQuery('span.forgotSpan').show(); jQuery(':input','#accountSettingsForm').not(':button, :submit').val('').removeAttr('selected'); jQuery('#pvtKey').attr('disabled',true).addClass('pvtKey_grey'); */ } else if(logoffRes[0]==false){ jQuery('.error_msg p').html(logoffRes[1]); jQuery('.error_msg').slideDown( 200, function() { setTimeout("jQuery('.error_msg').hide('slow');",5000 ); setTimeout(rediretToLogin,3000); }); jQuery('html,body').scrollTop(0); } }, error: function() { window.location.href='../index.php'; } }); } //$('.update-btn').hide(); // Commented by Senthil on 13-Feb-2017 return false; }); /* Logoff account settings - End */ function rediretToLogin(){ window.location.href="../index.php?logout"; } /* Create account settings file - Start */ function createAccountSettings(){ jQuery('#page_loader').show(); prevAlertMsg = jQuery('.alert p').html(); //AJAX call to create account settings file $.ajax({ url: "createAccountSettingsFile.php", success: function(settingsData){ checkUserForStatUpdate(); if(settingsData.indexOf('')>0){ window.location.href='../index.php'; } settingsRes=$.parseJSON(settingsData); if(settingsRes[0]==true){ if(settingsRes[2]!=false){ delayTime = 5000; jQuery('.alert p').html(settingsRes[2]); } else { delayTime = 0; } dedup = settingsRes[3]; accountSettingsOutput = settingsRes[1]; if(dedup==false || settingsRes[5]==true){ loadBackupPage(); //Dedup - False } else if(parseInt(settingsRes[4])==0) { jQuery('#deDupPopupSection').load('dedupBucket.php',function(){ jQuery('#locationNamePopup #backToSelectLocation').hide(); createNewLocation(); //Dedup - True & no devices }); } else if(parseInt(settingsRes[4])>0) { jQuery('#deDupPopupSection').load('dedupBucket.php',function(){ selectDedupLocation(); //Dedup - True }); } } else { jQuery('.alert,#page_loader').hide(); showErrorMessages('.error_msg',settingsRes[1]); } } }); //AJAX call to create Default Backup Set $.ajax({ url: "action.php?action=createDefaultBackupSet", success: function(settingsData){ if(settingsData.indexOf('')>0){ window.location.href='../index.php'; } } }); } function loadBackupPage(){ clearTimeout(activeJobsTimeoutVar); activeJobsTimeoutVar = setTimeout(watcherForActiveJobs, PROGRESS_WATCHER_ENABLE_TIME); setTimeout(processNextScheduledEvent, 1000); setTimeout(function(){ //if(isDedup==false) loadRestoreList(); //Getting remote list jQuery('#content').load('backup.php',function(){ jQuery('#content').css('margin-top','125px'); clearTimeout(accountSettingTimeout); jQuery('.alert,.welcome_message').hide('slow'); jQuery('#page_loader').hide(); }); setTimeout(function(){ jQuery('a').removeClass('act'); jQuery('a.leftnavbutton:eq(0)').addClass('act'); jQuery('.page_title h4').html(jQuery('a#nav_backup').attr('alt')); }, 500); //jQuery('.storage_used').load("accountUsage.php"); storageCalculate(1); var userName = updatedUserName; jQuery('.idr_user h3,#registered_user').html(userName); jQuery('.idr_user h3,#registered_user').attr("title", userName) ; $('#idriveUserInfo').show(); //jQuery('.head_usercont').show(); jQuery('.sliding ul li').show(); jQuery('.alert').hide('slow').find('p').html(prevAlertMsg); jQuery('.welcome_message').show( 500, function() { accountSettingTimeout = setTimeout(function(){ jQuery('.welcome_message').hide('slow'); if(jQuery('#page_loader').is(':visible')){ jQuery('.alert p').html('Loading...Please wait').parent().show(); } },500 ); }); jQuery('.welcome_message p').html(accountSettingsOutput); jQuery('html,body').scrollTop(0); },delayTime); } /* verify Private Key - Start */ $(document).on('click','#encryption',function(){$('.key_password').show(); }); $(document).on('click','#default',function(){$('.key_password').hide(); }); function verifyPrivateKey(){ var pvtKeyElement = document.getElementById("encrypt_key"); var validPrivateKey = false; if(pvtKeyElement.value != "") { var strPvtKey = pvtKeyElement.value; var strPvtKeyCopy = strPvtKey.replace(/\s+/g, ""); if(strPvtKeyCopy == "") { var errorMsgStr = "Private Key field contains only whitespaces"; showErrorMessages('.error_msg',errorMsgStr); pvtKeyElement.value = ""; setTimeout(function(){pvtKeyElement.focus()}, 10); } else { var lenPvtKey = strPvtKey.length; if(lenPvtKey < 4 || lenPvtKey > 256) { var errorMsgStr = "Private encryption key must be between 4 and 256 characters in length."; showErrorMessages('.error_msg',errorMsgStr); pvtKeyElement.value = ""; setTimeout(function(){pvtKeyElement.focus()}, 10); } else { validPrivateKey = true; ajaxCallForEncryption('validate'); } } } else { var errorMsgStr = "Private Key field cannot be blank"; showErrorMessages('.error_msg',errorMsgStr); setTimeout(function(){pvtKeyElement.focus()}, 10); } return false; } /* verify Private Key - End */ //Function to set/verify encryption key function ajaxCallForEncryption(type) { jQuery('#page_loader').show(); var data; if(type == 'set') { var url = "action.php?action=setEncryption"; var dataarr = jQuery('form#enc_conf').serializeArray(); jQuery.each(dataarr, function(inx, val) { if(val.name == 'pvtKey' || val.name == 'confmPvtKey') { //dataarr[inx]['value'] = base64_encode(val.value); dataarr[inx]['value'] = rawurlencode(val.value); } }); data = jQuery.param(dataarr); } else { var url = "action.php?action=validateEncryption"; data = 'encryptKey=' + rawurlencode($('#encrypt_key').val()); //data = 'encryptKey=' + base64_encode($('#encrypt_key').val()); } //AJAX call to create account settings file $.ajax({ url: url, type: "POST", data: data, success: function(settingsData){ if(settingsData.indexOf('')>0){ window.location.href='../index.php'; } jQuery('#page_loader').hide(); //$('#idriveUserInfo').show(); settingsRes=$.parseJSON(settingsData); if(settingsRes[0]==true){ createAccountSettings(); } else { showErrorMessages('.error_msg',settingsRes[1]); return false; } } }); return false; } //Function to load account settings page if not logged in jQuery('.head_user').die('click').live('click', function (event) { if(jQuery('#registered_user').html()=='' && !jQuery('.body_wrap').hasClass('account_page')){ jQuery('.sliding a:first').trigger('click'); return false; } else if(jQuery('#registered_user').html()==''){ showErrorMessages('.head_search .error_msg',GUEST_USER); return false; } }); /* check and update user stat at installation time */ function checkUserForStatUpdate(){ $.ajax({ url: "action.php?action=installationScript", success: function(){ } }); }