1/* 2 Last revision: 08.04.2022 3*/ 4 5var showCaptcha = jQuery("#show_captcha"); 6var showCaptchaCode = jQuery("#show_captcha_code"); 7 8if (showCaptcha.length && showCaptchaCode.length && (showCaptcha.data("required") != true) && (showCaptchaCode.data("required") != true)) { 9 showCaptcha.hide(); 10 showCaptchaCode.hide(); 11} 12 13// Include CSS 14document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend", "<link rel=\"stylesheet\" href=\"/members/scripts/quick_register.css\" />"); 15 16function quickReg(form_id, name_id = "", email_id, password_id, btn_id, birth_date = "", birth_day = "", birth_month = "", birth_year = "", captcha_id, first_name_id = "", last_name_id = "", seeking_id = "", fk_countries_id = "", post_code_id = "", phone_id = "") { 17 18 // Check if countries select exists 19 if (fk_countries_id != "") { 20 21 var qr_fk_countries = jQuery("#" + fk_countries_id); 22 23 jQuery.ajax({ 24 type: "POST", 25 url: "/members/scripts/quick_register.php", 26 data: {cmd: "get_country_by_ip"}, 27 //dataType: "text", 28 success: function(data) { 29 if (data > 0) { 30 jQuery("#" + fk_countries_id).val(data).change(); 31 } 32 }, 33 error: function(err) { 34 // console.log("Request failed, error" + err); 35 jQuery("#" + fk_countries_id).val(208).change(); 36 } 37 }); 38 39 } 40 41 jQuery("#" + form_id).on("submit", function(e) { 42 43 // Stop form 44 e.preventDefault(); 45 46 47 // Add loading overlayer 48 addLoadingOverlay("#" + form_id); 49 50 var error_color = "#AD0B0A"; 51 var success_color = "#0BAD0A"; 52 53 var qr_profile_name = jQuery("#" + name_id); 54 var qr_logins_email = jQuery("#" + email_id); 55 var qr_logins_password = jQuery("#" + password_id); 56 var qr_captcha = jQuery("#" + captcha_id); 57 var qr_first_name = jQuery("#" + first_name_id); 58 var qr_last_name = jQuery("#" + last_name_id); 59 var qr_seeking = jQuery("#" + seeking_id); 60 var qr_fk_countries = jQuery("#" + fk_countries_id); 61 var qr_profile_post_code = jQuery("#" + post_code_id); 62 var qr_phone = jQuery("#" + phone_id); 63 var qr_form = jQuery("#" + form_id); 64 var receive_woman_profile_updates = qr_form.find("input[name='receive_woman_profile_updates']"); 65 var msg_id = "qr_msg"; 66 var err = {}; 67 var validate_birth_date = false; 68 var validate_qcode = false; 69 70 var qr_birth_day = jQuery("#" + birth_day); 71 var qr_birth_month = jQuery("#" + birth_month); 72 var qr_birth_year = jQuery("#" + birth_year); 73 74 var showCaptcha = jQuery("#show_captcha"); 75 var showCaptchaCode = jQuery("#show_captcha_code"); 76 77 // UK, USA, CA key codes 78 var countries = [34, 70, 208, "34", "70", "208"]; 79 80 var btn_text = jQuery("#" + btn_id).val(); 81 82 // Disable Register button 83 jQuery("#" + btn_id).attr("disabled", "disabled").val("Processing..."); 84 85 // Remove messages 86 if (jQuery("#" + msg_id).length) { 87 jQuery("#" + msg_id).remove(); 88 } 89 90 // Validate name 91 if ( 92 (!qr_profile_name.length && (!qr_first_name.length || !qr_last_name.length)) 93 || (qr_profile_name.length && ((qr_profile_name.val().length < 2) || (qr_profile_name.val().length > 30))) 94 || ((qr_first_name.length && qr_last_name.length) && ((qr_first_name.val().length < 2) || (qr_first_name.val().length > 30) || (qr_last_name.val().length < 2) || (qr_last_name.val().length > 30))) 95 ) { 96 97 if (qr_profile_name.length) { 98 err[name_id] = "Please fill in your name."; 99 } 100 else { 101 if ((qr_first_name.val().length < 2) || (qr_first_name.val().length > 30)) { 102 err[first_name_id] = "Please fill in your first name."; 103 } 104 105 if ((qr_last_name.val().length < 2) || (qr_last_name.val().length > 30)) { 106 err[last_name_id] = "Please fill in your last name."; 107 } 108 } 109 } 110 111 // Validate email 112 if (qr_logins_email.val() == "") { 113 err[email_id] = "Please enter a valid email address."; 114 } 115 116 // Validate phone 117 if (qr_phone.length) { 118 var phone = jQuery.trim(qr_phone.val()); 119 var phoneDigits = phone.replace(/\D/g, ""); 120 if (phone.length > 30 || !/^\+?[0-9() .-]+$/.test(phone) || phoneDigits.length < 7 || phoneDigits.length > 15) { 121 err[phone_id] = "Please enter a valid phone number."; 122 } 123 } 124 125 // Validate password 126 if ((qr_logins_password.val().length < 2) || (qr_logins_password.val().length > 30)) { 127 err[password_id] = "The password must contain 4 to 30 characters."; 128 } 129 130 // Validate birth date 131 if ((birth_date != "") && (birth_day != "") && (birth_month != "") && (birth_year != "")) { 132 133 if ( 134 (qr_birth_day.val() == "") || (qr_birth_day.val() < 1) || (qr_birth_day.val() > 31) 135 || (qr_birth_month.val() == "") || (qr_birth_month.val() < 1) || (qr_birth_month.val() > 12) 136 || (qr_birth_year.val() == "") || (qr_birth_year.val() < 1918) || (qr_birth_year.val() > ((new Date).getFullYear() - 18)) 137 ) { 138 err[birth_date] = "Please complete your birth date."; 139 } 140 141 // Validate birth date in YYYY-MM-DD format 142 var birth_date_string = qr_birth_year.val() + "/" + qr_birth_month.val() + "/" + qr_birth_day.val(); 143 144 if (!(isValidDate(birth_date_string) > 0)) { 145 err[birth_date] = "Please enter a valid birth date."; 146 } 147 148 validate_birth_date = true; 149 } 150 151 // Validate captcha if element exist in html 152 if ((qr_captcha.val() == "") && (showCaptcha.length && showCaptchaCode.length && (showCaptcha.data("required") == true) && (showCaptchaCode.data("required") == true))) { 153 err[captcha_id] = "The captcha code cannot be empty."; 154 } 155 156 if (qr_captcha.length && (qr_profile_name.length || (qr_first_name.length && qr_last_name.length))) { 157 158 var result_name = {}; 159 160 if (qr_profile_name.length) { 161 result_name = qr_profile_name.val().split(" "); 162 } 163 else { 164 result_name[0] = qr_first_name.val(); 165 result_name[1] = qr_last_name.val(); 166 } 167 168 if ((qr_captcha.val() == "") && isset(result_name[0]) && isset(result_name[1]) && (result_name[0].toLowerCase() != "") && (result_name[0].toLowerCase() == result_name[1].toLowerCase())) { 169 jQuery("#show_captcha").show(); 170 jQuery("#show_captcha_code").show(); 171 err[captcha_id] = "The captcha code cannot be empty."; 172 } 173 } 174 175 if (fk_countries_id != "") { 176 177 if (qr_fk_countries.val() < 1) { 178 err[fk_countries_id] = "Please select a country."; 179 } 180 181 if (post_code_id != "") { 182 if ((jQuery.inArray( qr_fk_countries.val(), countries ) !== -1) && qr_profile_post_code.val() == "") { 183 err[post_code_id] = "Please fill in your Postal Code."; 184 } 185 } 186 } 187 188 if (qr_fk_countries.val() != "" && qr_profile_post_code.val() != "" && (jQuery.inArray( jQuery("#" + fk_countries_id).val(), countries ) !== -1)) { 189 190 var qr_fk_countries = jQuery("#" + fk_countries_id); 191 var qr_profile_post_code = jQuery("#" + post_code_id); 192 193 jQuery.ajax({ 194 type: "POST", 195 url: "/members/scripts/quick_register.php", 196 data: {cmd: "check_zip_code", profile_zip: qr_profile_post_code.val(), fk_countries: qr_fk_countries.val()}, 197 //dataType: "text", 198 success: function(data) { 199 200 if (data > 0) { 201 qr_profile_post_code.after("<div id=\"err_post_code_id\" style=\"font-size: 11px; color: " + error_color + ";\">ZIP code not found. Please enter a valid ZIP code.</div>"); 202 } 203 else { 204 jQuery("#err_post_code_id").hide(); 205 } 206 207 }, 208 error: function(err) { 209 console.log("Request failed, error" + err); 210 } 211 }); 212 213 } 214 215 // typeof qr_profile_name != "undefined" && qr_profile_name !== null && console.log(qr_profile_name.val()); 216 // typeof qr_first_name != "undefined" && qr_first_name !== null && console.log(qr_first_name.val()); 217 // typeof qr_last_name != "undefined" && qr_last_name !== null && console.log(qr_last_name.val()); 218 219 // Count errors 220 var len = jQuery.map(err, function(n, i) { return i; }).length; 221 222 // Remove old already existing errors 223 jQuery("[id^='err_']").remove(); 224 225 // Check if there are any errors 226 if (len > 0) { 227 // Go through each error 228 jQuery.each(err, function(i, v) { 229 // Add error messages 230 jQuery("#" + i).after("<div id=\"err_" + i + "\" style=\"font-size: 11px; color: " + error_color + ";\">" + v + "</div>"); 231 }); 232 233 // Remove loading overlayer 234 removeLoadingOverlay("#" + form_id); 235 236 // Restore button 237 jQuery("#" + btn_id).removeAttr("disabled").val(btn_text); 238 } 239 // No errors. Continue 240 else { 241 242 var dataObj; 243 244 if (validate_birth_date == true) { 245 dataObj = jQuery.extend({}, dataObj, {qr_birth_day: qr_birth_day.val(), qr_birth_month: qr_birth_month.val(), qr_birth_year: qr_birth_year.val(), validate_birth_date: validate_birth_date}); 246 } 247 248 if (qr_profile_name && qr_first_name.length && !qr_last_name.length) { 249 dataObj = jQuery.extend({}, dataObj, { 250 qr_profile_name: qr_profile_name.val(), 251 qr_first_name: qr_first_name.val() 252 }); 253 } 254 else if (qr_first_name.length && qr_last_name.length) { 255 dataObj = jQuery.extend({}, dataObj, {qr_first_name: qr_first_name.val(), qr_last_name: qr_last_name.val()}); 256 } 257 else { 258 dataObj = jQuery.extend({}, dataObj, {qr_profile_name: qr_profile_name.val()}); 259 } 260 261 if (qr_seeking.length) { 262 dataObj = jQuery.extend({}, dataObj, {qr_seeking: qr_seeking.val()}); 263 } 264 265 if (qr_fk_countries.length) { 266 dataObj = jQuery.extend({}, dataObj, {qr_fk_countries: qr_fk_countries.val()}); 267 } 268 269 if (qr_profile_post_code.length) { 270 dataObj = jQuery.extend({}, dataObj, {qr_profile_post_code: qr_profile_post_code.val()}); 271 } 272 273 if (qr_phone.length) { 274 dataObj = jQuery.extend({}, dataObj, {qr_phone: jQuery.trim(qr_phone.val())}); 275 } 276 277 if (receive_woman_profile_updates.length && receive_woman_profile_updates.is(":checked")) { 278 dataObj = jQuery.extend({}, dataObj, {receive_woman_profile_updates: receive_woman_profile_updates.val()}); 279 } 280 281 dataObj = jQuery.extend({}, dataObj, {qr_logins_email: qr_logins_email.val(), qr_logins_password: qr_logins_password.val(), qr_captcha: qr_captcha.val(), qr_form: "1"}); 282 283 jQuery("#" + btn_id).val("Registering..."); 284 285 jQuery.ajax({ 286 type: "POST", 287 url: "/members/scripts/quick_register.php", 288 data: dataObj, 289 dataType: "json", 290 success: function(data) { 291 292 qr_form.before("<div id=\"" + msg_id + "\" style=\"color: " + ((data['status'] == "success") ? success_color : error_color) + ";\">" + data['msg'] + "</div>"); 293 294 if (data['status'] == "success") { 295 296 qr_profile_name.val(""); 297 qr_logins_email.val(""); 298 qr_logins_password.val(""); 299 qr_phone.val(""); 300 301 // Skip redirect. Stay on page 302 if (data['skip_redirect'] == 1) { 303 // Nothing to do 304 } 305 // Redirect to members
306 else if (data['must_confirm'] == 1) { 307 //document.location = "/members/member_profile/?must_confirm=1&qr=1"; 308 document.location = "/members/confirm?option=" + data['url_code']; 309 } 310 // Redirect to members 311 else { 312 document.location = "/members/member_profile/?qr=1"; 313 } 314 315 // Restore button 316 jQuery("#" + btn_id).val("SUCCESS!"); 317 } 318 else if (data['status'] == "failed") { 319 document.location = "/members/confirm?option=" + data['url_code']; 320 // Restore button 321 jQuery("#" + btn_id).removeAttr("disabled").val(btn_text); 322 } 323 else { 324 // Restore button 325 jQuery("#" + btn_id).removeAttr("disabled").val(btn_text); 326 } 327 328 // Remove loading overlayer 329 removeLoadingOverlay("#" + form_id); 330 }, 331 error: function(data) { 332 333 qr_form.before("<div id=\"" + msg_id + "\" style=\"color: " + error_color + ";\">An error occurred</div>"); 334 335 // Remove loading overlayer 336 removeLoadingOverlay("#" + form_id); 337 338 // Restore button 339 jQuery("#" + btn_id).removeAttr("disabled").val(btn_text); 340 } 341 }); 342 } 343 }); 344} 345 346function isset(variable) { 347 348 // if ((typeof variable != "undefined") && (variable !== null)) { 349 if (typeof variable != "undefined") { 350 return true; 351 } 352 else { 353 return false; 354 } 355} 356 357// Validate date including epoch, and leap day (2016-02-29) / not leap day (2013-02-29) 358// YYYY-MM-DD format 359function isValidDate(dateString) { 360 var now = new Date(); 361 var past = new Date(dateString); 362 var nowYear = now.getFullYear(); 363 var pastYear = past.getFullYear(); 364 var age = nowYear - pastYear; 365 return age; 366 367 //var regEx = /^\d{4}-\d{2}-\d{2}$/; 368 //if(!dateString.match(regEx)) return false; // Invalid format 369 //var d = new Date(dateString); 370 //if(!d.getTime() && d.getTime() !== 0) return false; // Invalid date 371 //return d.toISOString().slice(0,10) === dateString; 372} 373 374function addLoadingOverlay(identifier) { 375 jQuery(identifier).css("position", "relative"); 376 jQuery(identifier).prepend('<div class="loading-overlay"><div class="spinner"></div></div>'); 377} 378 379function removeLoadingOverlay(identifier) { 380 jQuery(identifier).find(".loading-overlay").remove(); 381}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.