function loginController(n){var t=this;t.data={userName:null,password:null,errTxt:null,showError:!1,tooManyAttempts:!1,loginAttempts:0,notActivated:!1,showSuccessMessage:!1,showPinIsNotPasswordMsg:!1,passwordVisible:!1};t.setUpLoginAttempts=function(){typeof Storage!="undefined"?localStorage.currentUsername&&(t.data.loginAttempts=Number(localStorage.currentUsername)):console.error("HTML 5 Storage is not supported on this browser.")};t.submit=function(){t.data.showSuccessMessage=!1;(t.data.userName===null||t.data.password===null)&&(t.data.showError=!0,t.data.errTxt="Username and Password are required.");localStorage.currentUsername||localStorage.setItem("currentUsername",0);var i={username:t.data.userName,password:t.data.password};t.data.tooManyAttempts=!1;t.data.notActivated=!1;t.data.showPinIsNotPasswordMsg=!1;n.getUserByUsername(t.data.userName).then(function(r){var u=r.accountLockedDatetime;if(u===null||u==="null")n.authenticateUser(i).then(function(n){if(t.data.loginSuccess=n,t.data.password.length===4&&t.isPIN(t.data.password)&&(t.data.showPinIsNotPasswordMsg=!0),t.data.loginSuccess==="Login Successful"){localStorage.removeItem("currentUsername");console.log("Login attempts reset.");try{var i=new URLSearchParams(window.location.search);window.location.href=i.has("ReturnTo")?i.get("ReturnTo"):"/MyAccount"}catch(r){window.location.href="/MyAccount"}t.data.showError=!1;return}if(t.data.loginSuccess.includes("Your account has not been activated")){t.data.showError=!1;t.data.notActivated=!0;return}if(t.data.loginAttempts=Number(t.data.loginAttempts)+1,localStorage.currentUsername=t.data.loginAttempts,t.data.showError=!0,console.log("Fail. Login attempts: ",localStorage.currentUsername),t.data.loginAttempts>=5){t.data.showError=!1;t.data.tooManyAttempts=!0;return}if(t.data.loginAttempts===4){t.data.errTxt="Please use the Forgot Username/Password link to access your account. This is your fourth failed attempt. You will be locked out of your account after five failed attempts.";return}if(t.data.loginAttempts===3){t.data.errTxt="Please use the Forgot Username/Password link to access your account. This is your third failed attempt. You will be locked out of your account after five failed attempts.";return}n==="The username or password is incorrect."?t.data.errTxt="We didn’t recognize that username and password combination. Please try again, or select Forgot Username/Password to get a link emailed to you to reset your password.":n==="Your account has been locked. For assistance, please call customer service at 1.800.888.1300."?(t.data.showError=!1,t.data.tooManyAttempts=!0):t.data.errTxt="Your account is temporarily unavailable. Please contact our customer service department at 1.800.888.1300."},function(){t.data.showError=!0;t.data.errTxt="An error occurred while logging in. Please reload the page and try logging in again.";return});else{t.data.showError=!1;t.data.tooManyAttempts=!0;return}},function(){t.data.showError=!0;t.data.errTxt="An error occurred while logging in. Please reload the page and try logging in again.";return})};t.togglePasswordHidden=function(){this.data.passwordVisible?$("#Password").prop("type","text"):$("#Password").prop("type","password")};t.keyPress=function(n){n.keyCode===13&&t.submit()};t.isEmail=function(n){var t=new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);return t.test(n)};t.isPIN=function(n){var t=new RegExp(/^\d+$/);return t.test(n)};t.sendActivationEmail=function(){t.data.errTxt="";t.data.showError=!1;t.data.showSuccessMessage=!1;t.data.notActivated=!1;n.sendActivationEmail(t.data.userName).then(function(n){if(n){t.data.successTxt="Activation Email has been sent.";t.data.showError=!1;t.data.notActivated=!1;t.data.showSuccessMessage=!0;return}t.data.errTxt="An error occurred while sending activation email. For assistance, please call customer service at 1.800.888.1300.";t.data.showSuccessMessage=!1;t.data.showError=!0;return},function(){t.data.errTxt="An error occurred while sending activation email. For assistance, please call customer service at 1.800.888.1300.";t.data.showError=!0;return})}}angular.module("midcoComm").controller("loginController",loginController);loginController.$inject=["siteService","$sce"]