Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #131 from cfpb/reduce-requests
Browse files Browse the repository at this point in the history
Disallow dotless domains and debounce getInstitutions
  • Loading branch information
awolfe76 authored Jul 28, 2017
2 parents 77a32da + 7f3dad0 commit 0f34413
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions keycloak/themes/hmda/login/register.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

<script>
var institutionSearchUri = "${properties.institutionSearchUri!}/institutions";
var emailExp = new RegExp("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*");
var emailExp = new RegExp("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-]+");
function emailToDomain(email) {
return email.split("@", 2)[1];
Expand Down Expand Up @@ -153,6 +153,16 @@ function addInstitutionsToInput() {
$("#user\\.attributes\\.institutions").val(listOfInstitutions.join(","));
}
function makeDebouncer(delay){
var timeout
return function(domain){
clearTimeout(timeout)
timeout = setTimeout(function(){getInstitutions(domain)}, delay)
}
}
var debounceRequest = makeDebouncer(300)
$(document).ready(function() {
var email = $('#email');
Expand All @@ -164,7 +174,7 @@ $(document).ready(function() {
// e.keyCode will be 'undefined' on tab key
// don't make the API call on tab keyup
if(emailExp.test(email.val()) && e.keyCode) {
getInstitutions(emailToDomain(email.val().trim()));
debounceRequest(emailToDomain(email.val().trim()))
}
}
});
Expand Down

0 comments on commit 0f34413

Please sign in to comment.