1/** 2 * Signup Popup 3 * @constructor 4 */ 5function hgLoginPopupSignup( wrap ){ 6 var _this = this; 7 _this.wrap = wrap; 8 9 10 _this.authorizing = false; 11 12 13 _this.initPopup = function(){ 14 jQuery.when( _this.loadPopup() ).done(function() { 15 setTimeout(function(){ 16 _this.container = jQuery("#hg_login_primary_form_popup"); 17 _this.formBody = jQuery(".hg-login-modal-body"); 18 _this.closeBtn = jQuery(".hg-login-modal-close"); 19 _this.submitBtn = jQuery("#hg-login-button-signup-submit"); 20 _this.loginInput = jQuery("#hg-login-modal-user-login"); 21 _this.emailInput = jQuery("#hg-login-modal-user-email"); 22 _this.passInput = jQuery("#hg-login-modal-user-pass"); 23 _this.passStrength = 0; 24 _this.termsInput = jQuery("#hg-login-modal-terms"); 25 _this.newsletterInput = jQuery("#hg-login-modal-newsletter"); 26 _this.recaptcha = _this.container.find(".hg-login-modal-recaptcha"); 27 _this.googleBtn = _this.container.find('.hg-login-google-button'); 28 _this.googleEnabled = _this.googleBtn.length; 29 _this.enableRecaptcha = _this.recaptcha.length; 30 _this.acceptWeakPass = jQuery("#hg-login-signup-accept-weak-password").val() === "yes"; 31 _this.closeBtn.off("click"); 32 _this.closeBtn.on("click",_this.closePopup); 33 _this.formBody.off("keypress"); 34 _this.formBody.on("keypress",_this.keypressForm); 35 _this.submitBtn.off("click"); 36 _this.submitBtn.on("click",_this.submitForm); 37 _this.container.find("input").on("keyup",_this.checkInvalidKeyPress); 38 _this.container.find("input").on("blur",_this.checkInvalidBlur); 39 _this.container.find("input[type=checkbox]").on("change",_this.checkRequiredCheckbox); 40 if(_this.enableRecaptcha){ 41 _this.recpatchaWidgetID = grecaptcha.render(_this.recaptcha[0], 42 { 43 "sitekey": _this.recaptcha.data('sitekey'), 44 "theme": _this.recaptcha.data('theme') 45 } 46 ); 47 } 48 if(_this.googleEnabled){ 49 gapi.load('auth2', function(){ 50 // Retrieve the singleton for the GoogleAuth library and set up the client. 51 _this.auth2 = gapi.auth2.init({ 52 client_id: hgSignupPopupL10n.googleClientID, 53 cookiepolicy: 'single_host_origin', 54 scope: 'profile email' 55 }); 56 _this.attachGoogleSignin(_this.googleBtn[0]); 57 }); 58 } 59 },0); 60 }); 61 }; 62 63 _this.attachGoogleSignin = function(element){ 64 _this.auth2.attachClickHandler(element, {}, 65 function(googleUser) { 66 var gData = { 67 "name": googleUser.getBasicProfile().getGivenName(), 68 "lastName": googleUser.getBasicProfile().getFamilyName(), 69 "email": googleUser.getBasicProfile().getEmail(), 70 "displayName": googleUser.getBasicProfile().getName() 71 }; 72 73 jQuery.ajax({ 74 url: hgSignupPopupL10n.ajax_admin, 75 method: 'post', 76 dataType: 'json', 77 data: {action: 'hg_g_signin_ajax', gData: gData,nonceName:"hg_signup", nonce: hgSignupPopupL10n.nonce}, 78 beforeSend: function () { 79 var container = jQuery("#hg_login_primary_form_popup"); 80 if (container.length) { 81 _this.wrap = container.parent(); 82 container.remove(); 83 } 84 jQuery("body").addClass("hg-login-popup-open"); 85 86 _this.wrap.append( 87 '<div id="hg_login_primary_form_popup">' + 88 '<div id="hg-login-modal-reset-pass" class="hg-login-modal hg-login-modal-overlay hg-login-modal-reset-pass">' + 89 '<div class="hg-login-modal-fit center-center hg-login-layout">' + 90 '<div class="hg-login-modal-container">' + 91 '<div class="hg-login-popup-spinner-flex">' + 92 '<div class="hg-login-popup-spinner">' + 93 '<div class="hg-login-popup-spin hg-spinner-1"></div>' + 94 '<div class="hg-login-popup-spin hg-spinner-2"></div>' + 95 '<div class="hg-login-popup-spin hg-spinner-3"></div>' + 96 '<div class="hg-login-popup-spin hg-spinner-4"></div>' + 97 '</div>' + 98 '</div>' + 99 '</div>' + 100 '</div>' + 101 '</div>' + 102 '</div>'); 103 } 104 }).done(function (response) { 105 window.location.replace(response.redirect); 106 107 }).fail(function (error) { 108 window.location.replace(error.redirect); 109 }); 110 }, function(error) { 111 /*console.log(JSON.stringify(error, undefined, 2));*/ 112 }); 113 }; 114 115 116 _this.loadPopup = function(){ 117 var dfd = jQuery.Deferred(); 118 jQuery.ajax({ 119 url : hgSignupPopupL10n.ajax_admin, 120 method: 'post', 121 dataType :'json', 122 data : { action : 'hg_signup_popup_ajax', nonce: hgSignupPopupL10n.nonce }, 123 beforeSend : function(){ 124 var container = jQuery("#hg_login_primary_form_popup"); 125 if( container.length){ 126 _this.wrap = container.parent(); 127 container.remove(); 128 } 129 jQuery("body").addClass("hg-login-popup-open"); 130 131 _this.wrap.append( 132 '<div id="hg_login_primary_form_popup">' + 133 '<div class="hg-login-modal hg-login-modal-overlay hg-login-modal-signup">' + 134 '<div class="hg-login-modal-fit center-center hg-login-layout">' + 135 '<div class="hg-login-modal-container">' + 136 '<div class="hg-login-popup-spinner-flex">' + 137 '<div class="hg-login-popup-spinner">' + 138 '<div class="hg-login-popup-spin hg-spinner-1"></div>' + 139 '<div class="hg-login-popup-spin hg-spinner-2"></div>' + 140 '<div class="hg-login-popup-spin hg-spinner-3"></div>' + 141 '<div class="hg-login-popup-spin hg-spinner-4"></div>' + 142 '</div>' + 143 '</div>' + 144 '</div>' + 145 '</div>' + 146 '</div>' + 147 '</div>' ); 148 149 150 } 151 }).done(function(response){ 152 153 _this.wrap.find('.hg-login-modal-container').html(response.return); 154 155 setTimeout(function(){ 156 dfd.resolve(); 157 },0); 158 159 }).fail(function(error){ 160 console.log(error); 161 }); 162 return dfd.promise(); 163 }; 164 165 _this.submitForm = function(){ 166 if(_this.authorizing) return false;
167 168 var valid = true, 169 pass = _this.passInput.val(), 170 login = _this.loginInput.val(), 171 email = _this.emailInput.val(), 172 newsletter = false; 173 174 _this.checkValidLogin(login); 175 176 if( _this.newsletterInput.length ){ 177 newsletter = _this.newsletterInput.is(":checked"); 178 } 179 180 if( pass == "" ){ 181 _this.isInvalid( _this.passInput, hgSignupPopupL10n.requiredField ); 182 valid = false; 183 } 184 185 if( !_this.checkValidLoginFormat( login ) ){ 186 _this.isInvalid(_this.loginInput, hgSignupPopupL10n.onlyLatinAndNumbers ); 187 valid = false; 188 } 189 190 191 if( !_this.checkValidEmail( email ) ){ 192 _this.isInvalid( _this.emailInput, hgSignupPopupL10n.invalidEmail ); 193 valid = false; 194 } 195 196 if( _this.termsInput.length ){ 197 if( !_this.termsInput.is(":checked") ){ 198 _this.isInvalid( _this.termsInput, hgSignupPopupL10n.requiredField ); 199 valid = false; 200 } 201 } 202 203 if( _this.container.find("input.invalid").length ) valid = false; 204 205 /** 206 * check password against whitespaces 207 */ 208 var invalidPass = /\s/g.test(pass ); 209 210 if( invalidPass ){ 211 _this.isInvalid( _this.passInput, hgSignupPopupL10n.noWhiteSpaces ); 212 valid = false; 213 }else if( _this.passStrength <= 2 && !_this.acceptWeakPass ){ 214 /** 215 * Password weakness 216 */ 217 hg_login.showPopupInfo('-error', hgSignupPopupL10n.passTooWeak); 218 valid = false; 219 }else if( pass.length < hgSignupPopupL10n.passwordMinLength ){ 220 /** 221 * Check against minimum allowed length 222 */ 223 _this.isInvalid( _this.passInput, hgSignupPopupL10n.minSymbols ); 224 valid = false; 225 }else if( pass.length > hgSignupPopupL10n.passwordMaxLength ){ 226 /** 227 * Check against maximum allowed length 228 */ 229 _this.isInvalid( _this.passInput, hgSignupPopupL10n.maxSymbols ); 230 valid = false; 231 } 232 233 if(_this.enableRecaptcha){ 234 var recaptcha_response = grecaptcha.getResponse(_this.recpatchaWidgetID); 235 if(recaptcha_response == ''){ 236 hg_login.showPopupInfo( '-error', hgSignupPopupL10n.recaptchaErrorMsg ); 237 valid = false; 238 } 239 } 240 241 if(!valid){ 242 return false; 243 } 244 245 _this.doSignup(login,email,pass,newsletter); 246 return false; 247 }; 248 249 250 _this.doSignup = function( login,email,pass,newsletter){ 251 var data = { 252 action : 'hg_login_do_signup', 253 user_email: email, 254 user_login: login, 255 user_pass: pass, 256 user_newsletter : newsletter, 257 nonce: hgSignupPopupL10n.nonce 258 }; 259 260 if( _this.enableRecaptcha ){ 261 data.recaptchaResponse = grecaptcha.getResponse(_this.recpatchaWidgetID); 262 } 263 264 jQuery.ajax({ 265 url: hgSignupPopupL10n.ajax_admin, 266 method: 'post', 267 dataType :'json', 268 data : data, 269 beforeSend : function(){ 270 _this.submitBtnOriginal = _this.submitBtn.find(".button--content").text(); 271 _this.submitBtn.find(".button--content").text("Authorizing"); 272 _this.authorizing = true; 273 } 274 }).done(function(response){ 275 if(response.success){ 276 _this.submitBtn.find(".button--content").text(_this.submitBtnOriginal); 277 _this.authorizing = false; 278 if(response.verify_required){ 279 hg_login.showPopupInfo( '-success', response.verify_msg ); 280 _this.closePopup(); 281 }else{ 282 hg_login.doRedirect( response.redirect_to ); 283 } 284 285 }else{ 286 _this.submitBtn.find(".button--content").text(_this.submitBtnOriginal); 287 _this.authorizing = false;
288 289 if( typeof response.errorMsg != "undefined" && response.errorMsg ){ 290 hg_login.showPopupInfo( '-error', response.errorMsg ); 291 } 292 293 if( _this.enableRecaptcha ){ 294 grecaptcha.reset(_this.recpatchaWidgetID); 295 } 296 297 } 298 }).fail(function(error){ 299 console.log(error); 300 }); 301 }; 302 303 304 _this.checkInvalidKeyPress = function(){ 305 if(jQuery(this).hasClass("invalid") && jQuery(this).val() != ""){ 306 _this.isValid( jQuery(this) ); 307 jQuery(this).removeClass("invalid"); 308 } 309 310 var valid = true, 311 validMsg = hgSignupPopupL10n.requiredField; 312 if( jQuery(this)[0].hasAttribute("data-type") ){ 313 switch( jQuery(this).data('type') ){ 314 case 'password': 315 _this.checkPasswordStrength( jQuery(this) ); 316 break; 317 default : 318 valid = true; 319 break; 320 } 321 } 322 323 }; 324 325 _this.checkPasswordStrength = function( el ){ 326 var pass1 = el.val(),strength; 327 328 el.removeClass( 'pass-bad pass-good pass-strong pass-mismatch pass-short' ); 329 330 strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 ); 331 332 switch ( strength ) { 333 case 2: 334 _this.isInvalid(el, pwsL10n.bad, 'pass-bad'); 335 break; 336 case 3: 337 _this.isInvalid(el, pwsL10n.good, 'pass-good'); 338 break; 339 case 4: 340 _this.isInvalid(el, pwsL10n.strong, 'pass-strong'); 341 break; 342 case 5: 343 _this.isInvalid(el, pwsL10n.mismatch, 'pass-mismatch'); 344 break; 345 default: 346 _this.isInvalid(el, pwsL10n.short, 'pass-short'); 347 } 348 349 _this.passStrength = strength; 350 351 }; 352 353 _this.checkInvalidBlur = function( event ){ 354 if(jQuery(this).hasClass("invalid") && jQuery(this).val() != ""){ 355 _this.isValid(jQuery(this)); 356 jQuery(this).removeClass("invalid"); 357 } 358 359 var valid = true, 360 validMsg = hgSignupPopupL10n.requiredField, 361 val = jQuery(this).val(); 362 if( jQuery(this)[0].hasAttribute("data-type") ){ 363 switch( jQuery(this).data('type') ){ 364 case 'email': 365 valid = _this.checkValidEmail( val ); 366 validMsg = hgSignupPopupL10n.invalidEmail; 367 _this.checkUniqueEmail( val ); 368 369 break; 370 case 'login': 371 valid = true; 372 _this.checkValidLogin( val ); 373 _this.checkValidLoginFormatBlur( val ); 374 break; 375 default : 376 valid = true; 377 break; 378 } 379 }else if( typeof event.target.checkValidity == 'function' ){ 380 valid = event.target.checkValidity(); 381 }else if( jQuery(this).is(":required") ){ 382 valid = jQuery(this).val() == ""; 383 }else{ 384 valid = true; 385 } 386 387 if( !valid ){ 388 _this.isInvalid( jQuery(this), validMsg ); 389 } 390 }; 391 392 _this.isValid = function( el ){ 393 el.removeClass('invalid'); 394 if(el.parent().find("sup").length){ 395 el.parent().find("sup").remove(); 396 } 397 }; 398 399 _this.isInvalid = function( el, message, html_class ){ 400 401 html_class = typeof html_class !== 'undefined' ? html_class : 'invalid'; 402 403 el.addClass(html_class); 404 405 message = typeof message !== 'undefined' ? message : ''; 406 407 408 409 if( message == '' ) return false; 410 411 if( el.parent().find("sup").length ){ 412 el.parent().find("sup").remove(); 413 } 414 415 el.siblings("label").append("<sup class='" + html_class + "'> * "+message+"</sup>"); 416 }; 417 418 _this.checkValidLoginFormatBlur = function(login){ 419 if( !_this.checkValidLoginFormat(login) ){ 420 _this.isInvalid(_this.loginInput, hgSignupPopupL10n.onlyLatinAndNumbers ); 421 } 422 }; 423 424 _this.checkValidLoginFormat = function (login) { 425 var r = /^\w+$/g.test(login); 426 427 return r; 428 429 }; 430 431 _this.checkValidLogin = function( login ){ 432 if( typeof login != 'string' || login == '' ){ 433 _this.isInvalid(_this.loginInput,hgSignupPopupL10n.requiredField); 434 return false;
435 } 436 437 jQuery.ajax({ 438 url: hgSignupPopupL10n.ajax_admin, 439 method: 'post', 440 dataType :'json', 441 data : { action: 'hg_login_check_unqiue_login',login:login,nonce:hgSignupPopupL10n.nonce }, 442 beforeSend: function(){ 443 444 } 445 }).done(function(response){ 446 if(response.error){ 447 _this.isInvalid(_this.loginInput, hgSignupPopupL10n.usernameInUse ); 448 return false; 449 } 450 }).fail(function(error){ 451 452 }); 453 return false; 454 }; 455 456 _this.checkValidEmail = function( val ){ 457 if( val == "" ){ 458 return false; 459 } 460 461 var atpos = val.indexOf("@"), 462 dotpos = val.lastIndexOf("."); 463 464 return !(atpos<1 || dotpos<atpos+2 || dotpos+2>=val.length); 465 }; 466 467 _this.checkUniqueEmail = function( email ){ 468 if( typeof email != 'string' || email == '' ){ 469 _this.isInvalid(_this.emailInput,hgSignupPopupL10n.requiredField); 470 return false; 471 } 472 473 jQuery.ajax({ 474 url: hgSignupPopupL10n.ajax_admin, 475 method: 'post', 476 dataType :'json', 477 data : { action: 'hg_login_check_unqiue_email',email:email,nonce:hgSignupPopupL10n.nonce }, 478 beforeSend: function(){ 479 480 } 481 }).done(function(response){ 482 if(response.error){ 483 _this.isInvalid(_this.emailInput,hgSignupPopupL10n.emailInUse); 484 return false; 485 } 486 }); 487 return false; 488 }; 489 490 _this.checkRequiredCheckbox = function(){ 491 if( jQuery(this).is(":checked") ){ 492 _this.isValid(jQuery(this)); 493 }else if(jQuery(this).is(":required")){ 494 _this.isInvalid(jQuery(this),hgSignupPopupL10n.requiredField); 495 } 496 }; 497 498 _this.showInlineNotice = function( msg ){ 499 500 if( typeof msg == 'undefined' || msg == '' ){ 501 return false; 502 } 503 504 this.container.find(".hg-login-modal-body").html("<p class='hg_login_signup_form_inline_notice'>" + msg + "</p>"); 505 return true; 506 }; 507 508 _this.focusLogin = function(){ 509 if (_this.loginInput.length) _this.loginInput.focus(); 510 }; 511 512 513 _this.closePopup = function(){ 514 _this.container.remove(); 515 jQuery("body").removeClass("hg-login-popup-open"); 516 return false; 517 }; 518 519 _this.keypressForm = function(e){ 520 var code = e.keyCode || e.which; 521 if( code == 13 ) { 522 _this.submitBtn.click(); 523 } 524 }; 525 526 527 _this.init = function(){ 528 _this.initPopup(); 529 }; 530 531 532 _this.init(); 533}
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.