1var LoginBox = function () { 2 var self = this; 3 var userNameBox = $('#UserName'); 4 var passwordBox = $('#Password'); 5 var signInButton = $('#SignInButton'); 6 7 self.hostUrl = window.location.origin; 8 9 var prePopulatedUsername; 10 11 self.setPrePopulatedUsername = function(username){ 12 prePopulatedUsername = username; 13 }; 14 15 self.authenticationResultType = { 16 Error: -1, 17 Success: 0, 18 UserNeedsToAcceptTerms: 1, 19 UserCancelled: 2 20 }; 21 22 self.validateCredentialsPopupulated = function () { 23 if (userNameBox.val() == '') { 24 alert($('#UsernameEmptyMessage').val()); 25 return false; 26 } 27 if (passwordBox.val() == '') { 28 alert($('#PasswordEmptyMessage').val()); 29 return false; 30 } 31 return true; 32 }; 33 34 self.getDataForSubmission = function () { 35 return { 36 username: userNameBox.val(), 37 password: passwordBox.val(), 38 setCookie: $('#RememberMe2').is(':checked') 39 }; 40 }; 41 42 self.forgotPassword = function () { 43 if (userNameBox.val() == '') { 44 alert($('#UsernameEmptyMessage').val()); 45 } else { 46 $.getScript(self.hostUrl + '/Common/GlobalJSFunctionsDetail.js', function () { 47 $.getScript(self.hostUrl + '/Areas/MyAccount/Assets/Scripts/HomeIndex.js', function () { 48 recover(userNameBox.val()); 49 }); 50 }); 51 } 52 }; 53 54 self.submit = function () { 55 var data = self.getDataForSubmission(); 56 if (self.validateCredentialsPopupulated()) { 57 $.ajax({
58 type: "post", 59 dataType: "json", 60 url: self.hostUrl + '/Authentication/AuthenticateInternal', 61 data: data, 62 success: self.handleResponse 63 }); 64 } 65 }; 66 67 self.handleResponse = function (response) { 68 var authenticationJs; 69 if (response.ResultType == self.authenticationResultType.Error) { 70 alert(response.Message); 71 } else if (response.ResultType == self.authenticationResultType.UserNeedsToAcceptTerms) { 72 authenticationJs = new Authentication(); 73 authenticationJs.acceptTerms(); 74 } else { 75 authenticationJs = new Authentication(); 76 authenticationJs.handleRedirect(response.Message); 77 } 78 }; 79 80 self.bindControlClick = function (control, whatToDo) { 81 $(control).unbind('click').bind('click', function(event) { 82 whatToDo(event); 83 return false; 84 }); 85 }; 86 87 self.bindControlKeypress = function(control, whatToDo) { 88 $(control).unbind('keypress').bind('keypress', function(event) { 89 whatToDo(event); 90 }); 91 }; 92 93 self.bindControl = function (control, whatToDoOnClick) { 94 self.bindControlKeypress(control, function (event) { event.target.click(); }); 95 self.bindControlClick(control, whatToDoOnClick); 96 }; 97 98 self.initialize = function () { 99 100 self.bindControl(signInButton, self.submit); 101 self.bindControl('#ForgotPasswordButton', self.forgotPassword); 102 self.bindControl('#createProfileButton', self.createProfile); 103 104 self.bindControlKeypress(userNameBox, self.onUserNameKeypress); 105 self.bindControlKeypress(passwordBox, self.onPasswordEnter); 106 107 self.setUsernameAndInitialFocus(); 108 }; 109 110 self.setUsernameAndInitialFocus = function () { 111 userNameBox.val(prePopulatedUsername); 112 if(userNameBox.val() != ''){ 113 passwordBox.focus(); 114 } else { 115 userNameBox.focus(); 116 } 117 }; 118 119 self.onUserNameKeypress = function(event) { 120 if (event.which == 13) { 121 $(passwordBox).focus(); 122 return false; 123 } 124 }; 125 126 self.onPasswordEnter = function(event) { 127 if (event.which == 13) { 128 $(signInButton).click(); 129 } 130 }; 131 132 self.createProfile = function () { 133 $.ajax({
134 type: "get", 135 dataType: "json", 136 url: self.hostUrl + '/Authentication/GetCreateProfileUrl', 137 success: self.createProfileResponse 138 }); 139 }; 140 141 self.createProfileResponse = function (response) { 142 var authenticationJs = new Authentication(); 143 authenticationJs.handleRedirect(response.url); 144 }; 145}
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.