Files

683 lines
45 KiB
JavaScript
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
/*! jQuery Validation Plugin - v1.16.0 - 12/2/2016
* http://jqueryvalidation.org/
* Copyright (c) 2016 Jörn Zaefferer; Licensed MIT */
!function (a) { "function" == typeof define && define.amd ? define(["jquery"], a) : "object" == typeof module && module.exports ? module.exports = a(require("jquery")) : a(jQuery) }(function (a) { a.extend(a.fn, { validate: function (b) { if (!this.length) return void (b && b.debug && window.console && console.warn("Nothing selected, can't validate, returning nothing.")); var c = a.data(this[0], "validator"); return c ? c : (this.attr("novalidate", "novalidate"), c = new a.validator(b, this[0]), a.data(this[0], "validator", c), c.settings.onsubmit && (this.on("click.validate", ":submit", function (b) { c.settings.submitHandler && (c.submitButton = b.target), a(this).hasClass("cancel") && (c.cancelSubmit = !0), void 0 !== a(this).attr("formnovalidate") && (c.cancelSubmit = !0) }), this.on("submit.validate", function (b) { function d() { var d, e; return !c.settings.submitHandler || (c.submitButton && (d = a("<input type='hidden'/>").attr("name", c.submitButton.name).val(a(c.submitButton).val()).appendTo(c.currentForm)), e = c.settings.submitHandler.call(c, c.currentForm, b), c.submitButton && d.remove(), void 0 !== e && e) } return c.settings.debug && b.preventDefault(), c.cancelSubmit ? (c.cancelSubmit = !1, d()) : c.form() ? c.pendingRequest ? (c.formSubmitted = !0, !1) : d() : (c.focusInvalid(), !1) })), c) }, valid: function () { var b, c, d; return a(this[0]).is("form") ? b = this.validate().form() : (d = [], b = !0, c = a(this[0].form).validate(), this.each(function () { b = c.element(this) && b, b || (d = d.concat(c.errorList)) }), c.errorList = d), b }, rules: function (b, c) { var d, e, f, g, h, i, j = this[0]; if (null != j && null != j.form) { if (b) switch (d = a.data(j.form, "validator").settings, e = d.rules, f = a.validator.staticRules(j), b) { case "add": a.extend(f, a.validator.normalizeRule(c)), delete f.messages, e[j.name] = f, c.messages && (d.messages[j.name] = a.extend(d.messages[j.name], c.messages)); break; case "remove": return c ? (i = {}, a.each(c.split(/\s/), function (b, c) { i[c] = f[c], delete f[c], "required" === c && a(j).removeAttr("aria-required") }), i) : (delete e[j.name], f) }return g = a.validator.normalizeRules(a.extend({}, a.validator.classRules(j), a.validator.attributeRules(j), a.validator.dataRules(j), a.validator.staticRules(j)), j), g.required && (h = g.required, delete g.required, g = a.extend({ required: h }, g), a(j).attr("aria-required", "true")), g.remote && (h = g.remote, delete g.remote, g = a.extend(g, { remote: h })), g } } }), a.extend(a.expr.pseudos || a.expr[":"], { blank: function (b) { return !a.trim("" + a(b).val()) }, filled: function (b) { var c = a(b).val(); return null !== c && !!a.trim("" + c) }, unchecked: function (b) { return !a(b).prop("checked") } }), a.validator = function (b, c) { this.settings = a.extend(!0, {}, a.validator.defaults, b), this.currentForm = c, this.init() }, a.validator.format = function (b, c) { return 1 === arguments.length ? function () { var c = a.makeArray(arguments); return c.unshift(b), a.validator.format.apply(this, c) } : void 0 === c ? b : (arguments.length > 2 && c.constructor !== Array && (c = a.makeArray(arguments).slice(1)), c.constructor !== Array && (c = [c]), a.each(c, function (a, c) { b = b.replace(new RegExp("\\{" + a + "\\}", "g"), function () { return c }) }), b) }, a.extend(a.validator, { defaults: { messages: {}, groups: {}, rules: {}, errorClass: "error", pendingClass: "pending", validClass: "valid", errorElement: "label", focusCleanup: !1, focusInvalid: !0, errorContainer: a([]), errorLabelContainer: a([]), onsubmit: !0, ignore: ":hidden", ignoreTitle: !1, onfocusin: function (a) { this.lastActive = a, this.settings.focusCleanup && (this.settings.unhighlight && this.settings.unhighlight.call(this, a, this.settings.errorClass, this.settings.validClass), this.hideThese(this.errorsFor(a))) }, onfocusout: function (a) { this.checkable(a) || !(a.name in this.submitted) && this.optional(a) || this.element(a) }, onkeyup: function (b, c) { var d = [16, 17, 18, 20, 35, 36, 37, 38, 39, 40, 45, 144, 225]; 9 === c.whic
(function ($) {
'use strict';
window.sp_baseContext = 'https://app.secureprivacy.ai/';
window.sp_domainPath = window.location.host;
window.sp_exp = {};
$(function () {
$("#login").validate({
rules: {
useremail: {
required: true,
email: true
},
userpassword: {
required: true,
minlength: 5
}
},
messages: {
userpassword: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
useremail: "Please enter a valid email address"
},
submitHandler: function (form) {
loginToSP();
}
});
});
function loginToSP(email, password) {
$('#btn_login_page_submit').text('Processing...');
$('#btn_login_page_submit').prop('disabled', true);
$.ajax({
url: window.sp_baseContext + 'api/auth/credentials',
type: "POST",
data: JSON.stringify({
"UserName": $('#tbx_useEmail').val(),
"Password": $('#tbx_password').val()
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (data) {
sp_exp.SessionId = data.SessionId;
$.ajax({
url: window.sp_baseContext + '/api/AdminUser',
type: "GET",
headers: {
"X-ss-id": data.SessionId
},
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (adminUser) {
$('#outdated_notice_adminId').val(adminUser.ApiKey);
if (adminUser.UpdatedPaymentStatus.AddOns) {
$('#outdated_notice_planName').val(adminUser.UpdatedPaymentStatus.PlanName + '##' + adminUser.UpdatedPaymentStatus.AddOns.join(','));
} else {
$('#outdated_notice_planName').val(adminUser.UpdatedPaymentStatus.PlanName + '##');
}
$.ajax({
url: window.sp_baseContext + '/api/Domain',
type: "GET",
headers: {
"X-ss-id": data.SessionId
},
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (domain) {
if (domain.length === 1) {
$('#outdated_notice_domainId').val(domain[0].Id);
loginToSPStep2();
} else {
$('#domainSelectBox').append("<option value=''>Select</option>");
for (var i = 0; i < domain.length; i++) {
$('#domainSelectBox').append("<option value='" + domain[i].Id + "'>" + domain[i].Url + "</option>");
}
$('#domainPanel').show();
$('#loginPanel').hide();
}
},
error: function (e, x, v) {
console.log('Error fetching Admin user data. Try again.');
}
});
},
error: function (e, x, v) {
console.log('Error fetching Admin user data. Try again.');
}
});
},
error: function (e) {
$('#btn_login_page_submit').prop('disabled', false);
$('#btn_login_page_submit').text('Login to your account');
alert('Invalid credentials.');
}
});
}
sp_exp.selectDomain = function() {
$('#outdated_notice_domainId').val($('#domainSelectBox').val());
}
sp_exp.step2 = function() {
loginToSPStep2();
}
function loginToSPStep2() {
if ($('#outdated_notice_domainId').val() === '') {
alert("Please select a domain name");
return;
}
$.ajax({
url: window.sp_baseContext + '/api/adminsettings/apitoken',
type: "GET",
headers: {
"X-ss-id": sp_exp.SessionId
},
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (auth) {
$('#outdated_notice_sessionId').val(auth);
var b = $('#saveValueForm').serialize();
$.post('options.php', b).error(
function () {
$('#btn_login_page_submit').prop('disabled', false);
$('#btn_login_page_submit').text('Login to your account');
alert('Error! Please try again.');
}).success(function () {
if (window.getQueryString('redirectTo') && window.getQueryString('redirectTo').length > 1) {
window.location.href = window.getQueryString('redirectTo');
window.close();
} else {
window.location.href = $('#hdn_dashboard_page_url').val();
window.close();
}
});
},
error: function (e, x, v) {
}
});
}
//////////////**************Reset password starts**********//////////////////
$(function () {
$("#resetPassword").validate({
rules: {
useremail: {
required: true,
email: true
}
},
messages: {
useremail: "Please enter a valid email address"
},
submitHandler: function (form) {
recoverPassword();
}
});
});
function recoverPassword() {
$.ajax({
url: window.sp_baseContext + '/api/passwordreset',
type: "POST",
data: JSON.stringify({
"Email": $('#tbx_rp_useEmail').val(),
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (data) {
alert(data.Result);
},
error: function (e) {
alert('Email Id is not valid.');
}
});
}
//////////////**************Reset password ends**********//////////////////
//////////////**************Onboarding starts**********//////////////////
var bannerInterval;
var editModalBanner;
var onboardingPrefernces = {
'privacyPolicy': false,
'multipleLanguage': false,
'cookieConsent': false,
'multipleWebsites': false,
'targetEu': false,
};
var bestPlan = '';
var pricingDetails = {};
function activateStep(stepnum) {
$('.allSteps').hide();
$('#step' + stepnum).fadeIn();
$('.dots-indicator ul li span').removeClass('active');
$('#li_step' + stepnum + ' span').addClass('active');
}
window.getAuthToken = function () {
return 'Bearer' + ' ' + $('#outdated_notice_sessionId').val();
}
window.getQueryString = function (name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(function () {
$("#checkoutForm").validate({
ignore: ":hidden",
rules: {
fullName: {
required: true,
},
companyName: {
required: true,
},
country: {
required: true,
},
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 6
},
confirmPassword: {
required: true,
minlength: 6,
equalTo: "#password"
}
},
submitHandler: function (form) {
$('#btn_checkout_Submit').prop('disabled', true);
$('#btn_checkout_Submit').text(' Creating account... ', false);
registerUser();
}
});
});
function registerUser() {
/// Before registering you need to clear all the data of wordpress so that old API keys are not used.
$('#outdated_notice_adminId').val('');
$('#outdated_notice_sessionId').val('');
$('#outdated_notice_domainId').val('');
$('#outdated_notice_planName').val('');
$('#outdated_notice_client_id').val('');
$('#outdated_notice_client_secret').val('');
var b = $('#saveValueForm').serialize();
$.post('options.php', b).success(function () {
$.ajax({
url: window.sp_baseContext + '/api/register',
type: "POST",
data: JSON.stringify({
'FirstName': $('#companyName').val(),
'companyaddress': '',
'DisplayName': $('#fullName').val(),
'Email': $('#email').val(),
'Password': $('#password').val(),
'AutoLogin': false,
'Continue': ''
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (response, textStatus, xhr) {
if (response && xhr.status === 200) {
$.ajax({
url: window.sp_baseContext + '/api/adminsettings/openid/client',
type: "GET",
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (response) {
$('#outdated_notice_client_id').val(response.ClientId);
$('#outdated_notice_client_secret').val(response.ClientSecret);
saveUserDetails();
},
error: function (e, x, v) {
console.log('Error fetching Admin user data. Try again.');
}
});
}
},
error: function (e) {
alert(e.responseJSON.ResponseStatus.Message);
$('#btn_checkout_Submit').prop('disabled', false);
$('#btn_checkout_Submit').text(' Create account ', false);
}
});
});
}
function saveUserDetails() {
$.ajax({
url: window.sp_baseContext + '/api/auth/credentials',
type: "POST",
data: JSON.stringify({
'UserName': $('#email').val(),
'Password': $('#password').val()
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (res) {
$.ajax({
url: window.sp_baseContext + '/api/adminsettings/apitoken',
type: "GET",
headers: {
"X-ss-id": res.SessionId
},
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (auth) {
$('#outdated_notice_sessionId').val(auth);
sessionStorage.setItem('loginUser', JSON.stringify(res));
$.ajax({
url: window.sp_baseContext + '/api/AdminUser',
type: "POST",
headers: {
"Authorization": getAuthToken()
},
data: JSON.stringify({
'CompanyName': $('#companyName').val(),
'CompanyEmail': $('#email').val(),
'WebsiteURL': window.sp_domainPath,
'RegistationDate': new Date(),
'IsScriptInstalled': false,
'PaymentStatus': 'ONBOARDING-SUCCESSFULL',
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (response) {
$('#outdated_notice_adminId').val(response.ApiKey);
if (response.UpdatedPaymentStatus.AddOns) {
$('#outdated_notice_planName').val(response.UpdatedPaymentStatus.PlanName + '##' + response.UpdatedPaymentStatus.AddOns.join(','));
} else {
$('#outdated_notice_planName').val(response.UpdatedPaymentStatus.PlanName + '##');
}
sessionStorage.setItem('fullAdminDetails', JSON.stringify(response));
$.ajax({
url: window.sp_baseContext + '/api/Domain',
type: "POST",
headers: {
"Authorization": getAuthToken()
},
data: JSON.stringify({
'Domain': window.sp_domainPath
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (domain) {
$.ajax({
url: window.sp_baseContext + '/api/Domain',
type: "GET",
headers: {
"Authorization": getAuthToken()
},
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (allDomains, textStatus, xhr) {
var domainId = '';
for (var i = 0; i < allDomains.length; i++) {
if (allDomains[i].Url === window.sp_domainPath) {
domainId = allDomains[i].Id;
$('#outdated_notice_domainId').val(domainId);
break;
}
}
$.ajax({
url: window.sp_baseContext + '/api/payments/customerinfo',
type: "PUT",
headers: {
"Authorization": getAuthToken()
},
data: JSON.stringify({
"CompanyName": $('#companyName').val(),
"DisplayName": $('#fullName').val(),
"Vat": '',
"CityOrTown": '',
"Country": $('#country').val(),
"Line1": '',
"Line2": '',
"PostalCode": '',
"State": ''
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (response, textStatus, xhr) {
if (xhr.status === 204) {
var b = $('#saveValueForm').serialize();
window.create_first_dashboard();
$.post('options.php', b).success(function () {
window.location.href = $('#hdn_dashboard_page_url').val() + '&setupBanners=true';
});
}
},
error: function (e) {
alert(e.responseJSON.ResponseStatus.Message);
$('#btn_checkout_Submit').prop('disabled', false);
$('#btn_checkout_Submit').text(' Create account ', false);
}
});
},
error: function (e) {
alert(e.responseJSON.ResponseStatus.Message);
$('#btn_checkout_Submit').prop('disabled', false);
$('#btn_checkout_Submit').text(' Create account ', false);
}
});
},
error: function (e) { }
});
},
error: function (e) { }
});
},
error: function (e, x, v) {
}
});
},
error: function (e) { }
});
}
//***********Scan page and keep it inside a session object************//
function automaticScan() {
$.ajax({
url: window.sp_baseContext + '/api/plugins/website',
type: "POST",
data: JSON.stringify({
'Url': window.sp_domainPath
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function () { }
})
}
automaticScan();
//***********Scan page and keep it inside a session object************//
//////////////**************Onboarding Ends**********//////////////////
window.create_first_dashboard = function () {
$.ajax({
url: window.sp_baseContext + '/api/adminsettings/page',
type: "POST",
headers: {
"Authorization": window.getAuthToken()
},
data: JSON.stringify({
"Domain": $('#outdated_notice_domainId').val(),
"PrivacyLanguage": 'en',
"InstallScript": 'Completed',
"PrivacyBanner": true,
"TrustSeal": true,
"PrivacyCenter": true,
"PrivacyPolicy": false,
"MonthlyScanning": false
}),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (response, textStatus, xhr) {
if (response && xhr.status === 200) {
console.log('Saved');
}
},
error: function (e) { }
})
}
window.resetPlan = function (isRefresh) {
$.ajax({
url: window.sp_baseContext + '/api/AdminUser',
type: "GET",
headers: {
"Authorization": window.getAuthToken()
},
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (adminUser) {
if (adminUser.UpdatedPaymentStatus.AddOns) {
$('#outdated_notice_planName').val(adminUser.UpdatedPaymentStatus.PlanName + '##' + adminUser.UpdatedPaymentStatus.AddOns.join(','));
} else {
$('#outdated_notice_planName').val(adminUser.UpdatedPaymentStatus.PlanName + '##');
}
var b = $('#saveValueForm').serialize();
$.post('options.php', b).success(function () {
console.log('plan updated');
if (isRefresh) {
window.location.reload();
}
});
},
error: function (e, x, v) {
console.log('Error fetching Admin user data. Try again.');
}
});
}
window.sp_upgradePlan = function (planName) {
var plan_name = '';
if ($('#outdated_notice_planName').val() === '' || $('#outdated_notice_planName').val() === '##') {
plan_name = 'free';
} else {
plan_name = $('#outdated_notice_planName').val().split('##')[0];
}
var url = window.sp_baseContext + '#/login/wplogin/' + plan_name + '/' + $('#outdated_notice_sessionId').val();
var child = window.open(url, "_blank", "toolbar=no,scrollbars=yes,resizable=no,top=0,left=0,width=" + $(window).width() + ",height=" + $(window).height());
var leftDomain = false;
var interval = setInterval(function () {
try {
if (child.document.domain === document.domain) {
if (leftDomain && child.document.readyState === "complete") {
clearInterval(interval);
alert("returned: " + child.document.URL);
child.postMessage({ message: "requestResult" }, "*");
}
}
else {
leftDomain = true;
}
}
catch (e) {
// we're here when the child window has been navigated away or closed
if (child.closed) {
clearInterval(interval);
window.resetPlan(true);
return;
}
leftDomain = true;
}
}, 500);
}
window.getSupportedFeatures = function (planObj) {
var plan = $('#outdated_notice_planName').val().split('##')[0];
var feature = {
multiLanguage: false,
multidomain: false,
targetEU: false,
consentdashboard: false,
scandashboard: false,
priorConsent: false,
dpoSupport: false,
monthlyScanning: false,
privacyPolicy: false,
hideTrustWidget: true,
cssChanges: false
};
if (plan) {
// this is 5 E
if (plan === 'Standard Monthly Plan' || plan === 'Standard Annual Plan') {
feature.multiLanguage = false;
feature.multidomain = true;
feature.targetEU = true;
feature.consentdashboard = false;
feature.dpoSupport = true;
feature.scandashboard = true;
feature.priorConsent = true;
feature.monthlyScanning = false;
feature.privacyPolicy = false;
feature.hideTrustWidget = true;
feature.cssChanges = false;
}
else if (plan === 'Plus Annual Plan' || plan === 'Plus Monthly Plan') {
// this is 14 E
feature.multiLanguage = true;
feature.targetEU = true;
feature.multidomain = true;
feature.consentdashboard = false;
feature.dpoSupport = true;
feature.scandashboard = true;
feature.priorConsent = true;
feature.monthlyScanning = true;
feature.privacyPolicy = true;
feature.hideTrustWidget = true;
feature.cssChanges = false;
}
else if (plan === 'Premium Annual Plan' || plan === 'Premium Monthly Plan' || plan === 'Large - Monthly' || plan === 'Large - Annual') {
// this is 27 E
feature.multiLanguage = true;
feature.targetEU = true;
feature.multidomain = true;
feature.consentdashboard = true;
feature.dpoSupport = true;
feature.scandashboard = true;
feature.priorConsent = true;
feature.monthlyScanning = true;
feature.privacyPolicy = true;
feature.hideTrustWidget = true;
feature.cssChanges = true;
}
else if (plan === 'Basic Plan') {
feature.multiLanguage = false;
feature.targetEU = true;
feature.multidomain = true;
feature.consentdashboard = false;
feature.dpoSupport = true;
feature.scandashboard = true;
feature.priorConsent = true;
feature.monthlyScanning = false;
feature.privacyPolicy = checkAddOnExists();
feature.hideTrustWidget = false;
feature.cssChanges = false;
} else if (plan === 'Unlimited Plan') {
feature.multiLanguage = true;
feature.targetEU = true;
feature.multidomain = true;
feature.consentdashboard = false;
feature.dpoSupport = true;
feature.scandashboard = true;
feature.priorConsent = true;
feature.monthlyScanning = true;
feature.privacyPolicy = checkAddOnExists();
feature.hideTrustWidget = true;
feature.cssChanges = true;
} else if (plan === 'Premium Plan') {
feature.multiLanguage = true;
feature.targetEU = true;
feature.multidomain = true;
feature.consentdashboard = true;
feature.dpoSupport = true;
feature.scandashboard = true;
feature.priorConsent = true;
feature.monthlyScanning = true;
feature.privacyPolicy = true;
feature.hideTrustWidget = true;
feature.cssChanges = true;
}
}
window.sp_supportedFeatures = feature;
}
function checkAddOnExists() {
var exists = false;
var planArray = $('#outdated_notice_planName').val().split('##');
if (planArray && planArray.length > 0 && planArray[1].length > 0) {
var plan = planArray[1].split(',');
for (let i = 0; i < plan.length; i++) {
if (plan[i] === 'Privacy Policy Add-on') {
exists = true;
}
}
}
return exists;
}
})(jQuery);