// Page - Login Page (View) var ENTER_KEY_CODE = 13; var emailTemplates = new Array(); var submitTrue = false; //IFY Remove prefix from ajax call jQuery.ajaxSetup({ dataFilter: function(data, type) { //alert(data); var prefixes = ['//', 'while(1);', 'for(;;);'], i, l, pos; if (type != 'json' && type != 'jsonp') { return data; } for (i = 0, l = prefixes.length; i < l; i++) { pos = data.indexOf(prefixes[i]); if (pos === 0) { return data.substring(prefixes[i].length); } } return data; } }); /** IFY - frame busting defence*/ if (self == top) { var theBody = document.getElementsByTagName('body')[0] theBody.style.display = "block" } else { top.location = self.location } /** * Removes all css files */ function removeCssFile() { var link = jQuery('head').find('link[href$="css"]').each(function() { jQuery(this).remove(); }); jQuery('head > style').remove(); } /** * Shows an dom element with the specified id. * * @param id the of the dom element to show. */ function show(id) { document.getElementById(id).className = 'visisble'; return false; } /** * Hides an dom element with the specified id. * * @param id the of the dom element to hide. */ function hide(id) { document.getElementById(id).className = 'hidden'; return false; } /** * Check if email matches template @uspto.gov * @param String elementValue email address * @return true if matches else in other case */ function validateUsptoEmail(elementValue) { var isUspto = false; for (var i = 0; i < emailTemplates.length; i++) { var email = emailTemplates[i].replace('.', '\\.'); var usptoEmailPattern = '^([\\w]+(?:[\\.\\+\\-][\\w]+)*)' + email + '$' var regex = RegExp(usptoEmailPattern, "i") isUspto = regex.test(elementValue); if (isUspto == true) break; } return isUspto; } /** * Get email template using AJAX. * Runs asynchronous */ function getEmailTemplate() { var url = 'page.request.do'; jQuery.ajax({ type: "POST", data: {page:"page.pageUserRegistrationCheckEmail",type:"template"}, dataType: "json", url: url, cache:false, async : false }).done(function(data){ for (var i in data.result) { emailTemplates.push(data.result[i].NAME); } }); } /** * Check if email matches any template * @param String elementValue email address * @return true if matches else in other case */ function validateEmail(elementValue) { var simpleEmailPatter = /^([\w]+(?:[\.\+\-][\w]+)*)@([\w]+(?:[\.\-][\w]+)*)\.(\w{2,6})$/; return simpleEmailPatter.test(elementValue); } /** * Reset elements to default state when username is empty */ function resetElementsToDefault() { jQuery('#password').prop('disabled', true).val(''); } /** * Check if current screen is password reset screen * * @return true if password reset screen false in other case */ function isResetPasswordScreen() { return jQuery('#passwordConfirm').size() > 0; } /** * Initialize form controls for Password Reset screen * */ function initializePasswordResetControls() { jQuery('#forgot-password').remove(); jQuery('#banner-top').css('margin-bottom', '0px'); //jQuery('#banner-bottom').css('padding-top', '10px'); jQuery('#banner-bottom-help').css('padding-left', '10px'); jQuery('input[type=submit]').css('margin', '15px'); jQuery('#password').css('width', '290px'); jQuery('label[for=password]').css('display', 'block').after(jQuery('input#password')); jQuery('label[for=passwordConfirm]').css('display', 'block').after(jQuery('input#passwordConfirm')); } function loginSite() { if (submitTrue == false) { submitTrue = true; document.signonForm.submit(); } } //detect IE function detectIE() { var ua = window.navigator.userAgent; var msie = ua.indexOf('MSIE '); var trident = ua.indexOf('Trident/'); if (msie > 0) { // IE 10 or older => return version number return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10); } if (trident > 0) { // IE 11 (or newer) => return version number var rv = ua.indexOf('rv:'); return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10); } // other browser return false; } /** * Initialize controls behaviour */ function initializeControls() { //resetElementsToDefault(); //jQuery('label[for=password]').css({"position" : "relative", "top" : "14px"}); var passLabel = jQuery('label[for=username]').css('display', 'block').after(jQuery('input#username')).text('Log in with your email address'); jQuery('label[for=password]').css('display', 'block').after(jQuery('input#password')); jQuery('label[for=username]').addClass("loginLabel"); jQuery('label[for=password]').addClass("loginLabel"); jQuery('#submit').remove(); //jQuery('#banner-bottom').css('padding-top', '10px'); jQuery('#banner-bottom-help').css('padding-left', '10px'); //jQuery('#password').after(jQuery('#image-submit')); jQuery('#password').parent().after(); var table = jQuery('#inputTable'); jQuery('#password').after(table); table.find('#passwordCell').append(jQuery('#password')); table.after(jQuery('#forgot-password')); jQuery('#forgot-password').parent().nextAll().remove(); jQuery('#forgot-password').remove(); jQuery( "#image-block" ).on("keypress keydown", function( event ) { if (event.type == 'keypress' || (detectIE() == false && event.type == 'keydown')){ if ( event.which == ENTER_KEY_CODE ) { loginSite(); } } }); jQuery( "#password" ).on("keypress keydown", function( event ) { if (event.type == 'keypress' || (detectIE() == false && event.type == 'keydown')){ if ( event.which == ENTER_KEY_CODE ) { document.signonForm.submit(); } } }); jQuery('#image-block').on('click', function() { //if (jQuery('#password').prop('disabled') == false) { loginSite(); // } }); jQuery('#password').on('keydown mousedown', function(e) { validateEnteredUsername("password"); }); jQuery('#username').on('blur', function(e) { validateEnteredUsername("username"); }); } function setHref(){ var hrefStart = 'page.request.do?email=' + jQuery('#username').val() + '&page='; var hrefEnd=""; if(this.id == 'employee-register'){ hrefEnd = 'page.pageEmployeeRegistration'; } else{ hrefEnd = 'page.applicantRegistration'; } jQuery(this).prop("href",hrefStart + hrefEnd); } /** * Validate entered username to check if it exist. * if it exist than activate password field * if it doesn't exist - check to what registration process case * should be done */ function validateEnteredUsername(f) { //resetElementsToDefault(); var username= jQuery('#username').val(); if (f == "password") { //jQuery('.error').remove(); if (username == "") { jQuery('.error').remove(); jQuery('#login').prepend('

' + 'Nothing has been entered in the email address. Please enter a valid ' + 'email address.

'); return; } else { jQuery('.error').remove(); } } // The below AJAX Call wasn't working // TRR fixed the issue 1/15/16 // But since this isn't working in production we'll leave it turned of unless the client explicitly ask for it /* else { show('loading'); var url = 'page.request.do'; jQuery.ajax({ type:"POST", data: {page:"page.pageUserRegistrationCheckEmail", type:"echeck", un:username}, url: url, cache:false, dataType: "text", async: false }).done(function(datax){ var data = jQuery.parseJSON( datax.replace("while(1);", "")); var emaildata = data.result[0].EMAIL; if ( emaildata > 0) { //data[0] && data[0].EMAIL > 0) { jQuery('#password').prop('disabled', false).focus(); } else if ( emaildata == 0) { // data[0] && data[0].EMAIL == 0) { var isSimpleEmail = validateEmail(username); var isUsptoEmail = validateUsptoEmail(username); if (isSimpleEmail == false) { jQuery('#login').prepend('

' + 'Username entered is not authorized to have access.' + ' Contact your Supervisor if you should be an authorized user.

'); //document.getElementById("username").focus(); } else if (isSimpleEmail == true && isUsptoEmail == false) { jQuery('#login').prepend('

Use ' + 'the Job Applicant Registration link below to make an Accommodation Request.' + '

'); //jQuery('#applicant-register').attr('href', 'page.request.do?page=page.applicantRegistration&email=' + username); //document.getElementById("applicant-register").focus(); } else if (isSimpleEmail == true && isUsptoEmail == true) { jQuery('#login').prepend('

' + 'Email address does not exist. Please register below.' + '

'); //jQuery('#employee-register').attr('href', 'page.request.do?page=page.pageEmployeeRegistration&email=' + username); //document.getElementById("employee-register").focus(); } } else { jQuery('#login').prepend('

' + 'Error occurred. Please, contact your system administrator.' + '

'); } }).complete(function(){ hide('loading'); }).error(function (xhr, ajaxOptions, thrownError) { //alert(xhr.status); //alert(thrownError); }); } */ } /** * Check if current username field is empty * it could be filled by the browser with 'remember password' feature * if not empty run username validation */ function checkUsernameEmpty() { if (jQuery('#username').val() != "") { validateEnteredUsername(); } } /** * Replace 'Invalid Username and Password.' message if present. * PTORACMSEN-221 */ function replaceSignonFailureMessage() { var strInvUserOrPass = 'Invalid Username or Password.'; var strInvUserOrPassCustom = 'If you have not registered for an account with Accommodation Point, please register using the "Go register" link below.

If you already have an account with Accommodation Point and you are having trouble accessing the system, please contact AccommodationPoint@uspto.gov'; var aSignonFailure = jQuery('#signonFailure'); if (aSignonFailure.length) { if (aSignonFailure.text().toLowerCase().indexOf(strInvUserOrPass.toLowerCase()) >= 0) { aSignonFailure.html(strInvUserOrPassCustom); } } } jQuery(document).ready(function() { if(jQuery(window.location.pathname.split("/")).last()[0].indexOf("enforce.update.password") >= 0) { jQuery('#employee-register').parent().hide(); jQuery('#applicant-register').parent().hide(); /* look for

try to remove the class and add a new class */ jQuery("p.error").removeClass("error").addClass("passwordMessage"); jQuery("label[for='password']").css("margin-left", "11px"); } removeCssFile(); // add USPTO CSS files (https://jira.micropact.com/browse/USPTO-198) jQuery("head").append(""); jQuery("head").append(""); //getEmailTemplate(); jQuery('#login').before(jQuery('#upper').children()); jQuery('#login').after(jQuery('#lower').children()); jQuery('#applicant-register, #employee-register').on("click keypress keydown", setHref); if (isResetPasswordScreen() === false) { initializeControls(); //checkUsernameEmpty(); } else { initializePasswordResetControls(); } //Source http://www.bluenotesentertainment.com/blog/add-a-jquery-toggle-to-any-website/ //if enforce password, do not display security statement var locationref = location.href; if (locationref.indexOf("enforce.update.password.") >= 0) { document.getElementById("divStatement").style.display = 'none'; jQuery("#image-block").hide(); jQuery("#references").hide(); } else { document.getElementById("divStatement").style.display = 'block'; } /* jQuery(".toggle a.toggle-trigger").click(function() { var el = jQuery(this), parent = el.closest('.toggle'); //jQuery("#divStatement").toggle(); if (el.hasClass('active')) { el.removeClass('active'); parent.find('.toggle-content').toggle(); } else { el.addClass('active'); parent.find('.toggle-content').toggle(); } }); */ //PAK&IFY 2014-04-02 Show the login content if(document.getElementById('content')) document.getElementById('content').style.display = ''; if (document.getElementById('password')) { document.getElementById('password').autocomplete = 'off'; } if (document.getElementById('username')) { document.getElementById('username').autocomplete = 'off'; } if (document.signonForm) { document.signonForm.autocomplete = 'off'; } // PTORACMSEN-221, Replace 'Invalid Username and Password.' message if present. replaceSignonFailureMessage(); });