CINXE.COM
Login | Singapore Tourism Board
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><meta http-equiv="X-UA-Compatible" content="IE=edge"><link rel="icon" href="/iamsso/favicon.ico" type="image/x-icon"/><title>Login | Singapore Tourism Board</title> <link type="text/css" rel="stylesheet" href="/iamsso/css/bootstrap.min.css"><link type="text/css" rel="stylesheet" href="/iamsso/css/font-awesome.min.css"><link type="text/css" rel="stylesheet" href="/iamsso/css/animate.css"><link type="text/css" rel="stylesheet" href="/iamsso/css/screen.css"><script type="text/javascript" src="/iamsso/js/jquery.min.js"></script> <script type="text/javascript" src="/iamsso/js/bootstrap.min.js"></script> <script type="text/javascript" src="/iamsso/js/uri.min.js"></script> <script type="text/javascript" src="/iamsso/js/jsencrypt.js"></script> <style> .custom-text-holder { font-size: 18px; margin-bottom: 5px; } @media (min-width: 992px) { #form-container .loginSectionHolder { margin-bottom: 0; } } .btn.rounded-pill { border-radius: 50rem !important; } </style> </head> <body> <div class="simpleLoginHolder"> <div class="container"> <div class="masterFormHolder"> <header class="simpleLoginHolderHeader"> <div class="siteLogoHolder"> <a href="https://tih.stb.gov.sg/content/tih/en/home.html" class="siteLogo"> <div class="siteLogoInfo"> <img src="/iamsso/images/tih-logo.svg" alt="Logo"></div> </a> </div> </header> <div role="tabpanel" class="tab-pane active"> <form id="loginForm" method="get"> <div class="inputSectionHolder"> <div class="inputSectionHeader text-center"> <h3 class="inputTitleHeading">TIH Portal Sign In</h3> </div> <div class="inputSectionBody altLoginStyling"> <noscript> <div class="row"> <div class="col-md-12 text-center"> <p>Please enable javascript to access this page</p> </div> </div> </noscript> <div class="row" id="loader-container"> <div class="col-md-12 text-center"> <img src="/iamsso/images/loader.gif" style="display:none;" onload="((this && this.style && this.style.display) ? (this.style.display = 'inline') : '')" onerror="((this && this.style && this.style.display) ? (this.style.display = 'inline') : '')"></div> </div> <div class="row hide" id="entry-error-container"> <div class="col-md-12 text-center"> <p id="entry-error-msg">An unexpected error occurred</p> <button type="button" class="btn btn-green rounded-pill" id="entry-error-retry-btn">Try Again</button> </div> </div> <div class="row hide" id="form-container"> <div class="col-md-6"> <div class="loginSectionHolder hide" id="all-pass-holder"> <div class="corpPass-login-holder"> <div class="custom-text-holder">For Business Users</div> <div class="formLoginBottomInfo"> <a class="btn btn-green rounded-pill corpPass-login corppass-sign-in-link"> <i class="fa fa-play-circle"></i> Sign in with <strong>Singpass</strong> </a> </div> </div> <br><div class="corpPass-login-holder"> <div class="custom-text-holder">For Basic Users / Developers</div> <div class="formLoginBottomInfo"> <a class="btn btn-green rounded-pill corpPass-login singpass-sign-in-link"> <i class="fa fa-play-circle"></i> Sign in with <strong>Singpass</strong> </a> </div> </div> </div> <div class="loginSectionHolder hide" id="only-singpass-holder"> <div class="corpPass-login-holder"> <div class="custom-text-holder">For Basic Users / Developers</div> <div class="formLoginBottomInfo"> <a class="btn btn-green rounded-pill corpPass-login singpass-sign-in-link"> <i class="fa fa-play-circle"></i> Sign in with <strong>Singpass</strong> </a> </div> </div> </div> <div class="loginSectionHolder hide" id="only-corppass-holder"> <div class="corpPass-login-holder"> <div class="custom-text-holder">For Business Users</div> <div class="formLoginBottomInfo"> <a class="btn btn-green rounded-pill corpPass-login corppass-sign-in-link"> <i class="fa fa-play-circle"></i> Sign in with <strong>Singpass</strong> </a> </div> </div> </div> <div class="loginSectionHolder hide" id="no-pass-holder"> <div class="corpPass-login-holder"> <img src="/iamsso/images/tih-logo.svg" alt="CorpPass" class="img-responsive"></div> </div> </div> <div class="col-md-6"> <div class="loginSectionHolder altLoginStyling"> <div class="portal-id-div"> <div class="sign-in-holder"> <h4>Sign in with <span>TIH Portal ID</span></h4> <div id="authenticatMsgId" class="loginErrorHolder hide"> <ul> <li id="login-error-msg"></li> </ul> </div> <div class="form-group"> <input class="form-control" id="username" size="25" tabindex="1" type="text" placeholder="Email *" accesskey="u" autocomplete="off"/></div> <div class="form-group"> <input class="form-control" type="password" id="password" size="25" tabindex="2" placeholder="Password *" accesskey="p" autocomplete="off"/><span id="capslock-on" class="hide"> <p> <i class="fa fa-exclamation-circle"></i> <span>CAPSLOCK key is turned on!</span> </p> </span> </div> <p><a href="https://tih-iam.stb.gov.sg/iamsso/forgetPassword?service=https%3A%2F%2Ftih.stb.gov.sg%2Fcontent%2Ftih%2Fen%2Fhome.html">Forgot Password?</a></p> <button type="button" id="signInBtn" class="btn btn-green rounded-pill">Sign In</button> <p> <div class="login-misc-holder" style="margin: 10px auto;"> Don't have an account? <a href="https://tih.stb.gov.sg/content/tih/en/profile/register.html">Register</a> </div> </p> </div> </div> </div> </div> </div> </div> </div> </form> </div> </div> </div> </div> <script type="text/javascript"> var GLOBAL_ERROR_CODES_FACTORY = (function(){ return { "generate": function() { return { "NO_NETWORK_CONNECTIVITY": 0, "SUCCESS": 200, "USER_NOT_FOUND_WHILE_AUTHENTICATING_USER": -99, "EMPTY_USER_NAME_WHILE_AUTHENTICATING_USER": -94, "EMPTY_PASSWORD_WHILE_AUTHENTICATING_USER": -95, "CP_USER_WHILE_AUTHENTICATING_USER": -958, "SP_USER_WHILE_AUTHENTICATING_USER": -959, "LOCKED_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER": -132, "DISABLED_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER": -133, "BLOCKED_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER": -134, "REGISTERED_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER": -137, "NOT_ACTIVE_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER": -138, "EXPIRED_PASSWORD_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER": -141, "ACCOUNT_LOCKED_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER": -142, "INVALID_USERNAME_PASSWORD_COMBINATION_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER": -143, "MISSING_ENTRY_URL_WHILE_RETRIEVE_LOGIN_INIT_DATA": -940, "MISSING_PARAMETERS_WHILE_RETRIEVE_LOGIN_INIT_DATA": -941, "MISSING_RESPONSE_WHILE_RETRIEVE_LOGIN_INIT_DATA": -942, "MISSING_STATUS_WHILE_RETRIEVE_LOGIN_INIT_DATA": -943, "MISSING_STATUS_CODE_WHILE_RETRIEVE_LOGIN_INIT_DATA": -944, "INVALID_RESPONSE_FORMAT_WHILE_RETRIEVE_LOGIN_INIT_DATA": -945, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_RETRIEVE_LOGIN_INIT_DATA": -946, "INVALID_ERROR_STATUS_WHILE_RETRIEVE_LOGIN_INIT_DATA": -947, "MISSING_RESPONSE_WHILE_INIT_LOGIN": -948, "MISSING_STATUS_WHILE_INIT_LOGIN": -949, "MISSING_STATUS_CODE_WHILE_INIT_LOGIN": -950, "MISSING_DATA_WHILE_INIT_LOGIN": -951, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_INIT_LOGIN": -952, "INVALID_RESPONSE_FORMAT_WHILE_INIT_LOGIN": -953, "INVALID_ERROR_STATUS_WHILE_INIT_LOGIN": -954, "UNKNOWN_ERROR_WHILE_INIT_LOGIN": -955, "MISSING_REDIRECT_UUID_WHILE_INIT_LOGIN": -956, "MISSING_ACTION_WHILE_INIT_LOGIN": -957, "MISSING_RESPONSE_WHILE_GET_PUBLIC_KEY": -1336, "MISSING_STATUS_WHILE_GET_PUBLIC_KEY": -1337, "MISSING_STATUS_CODE_WHILE_GET_PUBLIC_KEY": -1338, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_GET_PUBLIC_KEY": -1339, "INVALID_RESPONSE_FORMAT_WHILE_GET_PUBLIC_KEY": -1340, "MISSING_DATA_WHILE_GET_PUBLIC_KEY": -1341, "MISSING_PUBLIC_KEY_WHILE_GET_PUBLIC_KEY": -1342, "MISSING_TX_UUID_WHILE_GET_PUBLIC_KEY": -1343, "UNABLE_TO_ENCRYPT_KEY_WHILE_ENCRYPTING_KEY": -1344, "EMPTY_ENCRYPTED_KEY_WHILE_ENCRYPTING_KEY": -1345, "INVALID_ACTIVATION_TOKEN": -1365, "ALREADY_LOGIN": -1366, "EMPTY_PASSWORD": -1410, "COMMON_PASSWORD": -1411, "PASSWORD_NOT_COMPLIANT": -1412, "PASSWORD_SAME_AS_USERNAME": -1413, "PASSWORD_IN_HISTORY": -1414, "MISSING_RESPONSE_WHILE_SET_NEW_PSSD": -1415, "MISSING_STATUS_WHILE_SET_NEW_PSSD": -1416, "MISSING_STATUS_CODE_WHILE_SET_NEW_PSSD": -1417, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_SET_NEW_PSSD": -1418, "INVALID_RESPONSE_FORMAT_WHILE_SET_NEW_PSSD": -1419, "MISSING_DATA_WHILE_SET_NEW_PSSD": -1427, "INVALID_ERROR_STATUS_WHILE_SET_NEW_PSSD": -1428, "UNKNOWN_ERROR_WHILE_SET_NEW_PSSD": -1429, "UNKNOWN_STATUS_CODE_WHILE_SET_NEW_PSSD": -1430, "MISSING_PASSWORD_TOKEN_OBJ_WHILE_ACTIVATE_ACCOUNT": -1483, "MISSING_USER_WHILE_ACTIVATE_ACCOUNT": -1487, "USER_ALREADY_ACTIVATED": -1526, "USER_NOT_ABLE_TO_LOGIN": -1527, "USER_NEED_TO_RESET_PASSWORD": -1528, "USER_NO_LONGER_EXISTS": -1529, "IS_CORPPASS_LOGIN": -1530, "IS_SINGPASS_LOGIN": -1531, "EMPTY_USERNAME_WHILE_LOGIN": -1545, "EMPTY_PASSWORD_WHILE_LOGIN": -1546, "EMPTY_PASSWORD_WHILE_ACTIVATION": -1547, "INVALID_CURRENT_PASSWORD_WHILE_CHANGE_PASSWORD": -1566, "UNABLE_TO_CONFORM_NEW_PASSWORD_WHILE_CHANGE_PASSWORD": -1571, "MISSING_RESPONSE_WHILE_CHANGE_PASSWORD": -1572, "MISSING_STATUS_WHILE_CHANGE_PASSWORD": -1573, "MISSING_STATUS_CODE_WHILE_CHANGE_PASSWORD": -1574, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_CHANGE_PASSWORD": -1575, "INVALID_RESPONSE_FORMAT_WHILE_CHANGE_PASSWORD": -1576, "PASSWORD_TOO_COMMON_WHILE_CHANGE_PASSWORD": -1582, "MISSING_RESPONSE_WHILE_GENERATE_CAPTCHA": -1614, "MISSING_STATUS_WHILE_GENERATE_CAPTCHA": -1615, "MISSING_STATUS_CODE_WHILE_GENERATE_CAPTCHA": -1616, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_GENERATE_CAPTCHA": -1617, "INVALID_RESPONSE_FORMAT_WHILE_GENERATE_CAPTCHA": -1618, "MISSING_CAPTCHA_WHILE_OFFLINE_ACTIVATE": -1655, "INVALID_CAPTCHA_WHILE_OFFLINE_ACTIVATE": -1656, "MISSING_PIN_WHILE_OFFLINE_ACTIVATE": -1657, "MISSING_PASSWORD_TOKEN_WHILE_OFFLINE_ACTIVATE": -1658, "INVALID_USER_STATUS_WHILE_OFFLINE_ACTIVATE": -1661, "MISSING_RESPONSE_WHILE_OFFLINE_ACTIVATE": -1667, "MISSING_STATUS_WHILE_OFFLINE_ACTIVATE": -1668, "MISSING_STATUS_CODE_WHILE_OFFLINE_ACTIVATE": -1669, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_OFFLINE_ACTIVATE": -1670, "INVALID_RESPONSE_FORMAT_WHILE_OFFLINE_ACTIVATE": -1671, "MISSING_RESPONSE_WHILE_FORGET_PASSWORD": -2012, "MISSING_STATUS_WHILE_FORGET_PASSWORD": -2013, "MISSING_STATUS_CODE_WHILE_FORGET_PASSWORD": -2014, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_FORGET_PASSWORD": -2015, "INVALID_RESPONSE_FORMAT_WHILE_FORGET_PASSWORD": -2016, "SESSION_FOUND_WHILE_SUBMITTING_FORGET_PASSWORD_PAGE": -2022, "UNKNOWN_ERROR_WHILE_SUBMITTING_FORGET_PASSWORD": -2023, "INCORRECT_GOOGLE_CAPTCHA": -2024, "MISSING_VALIDATE_CATPCHA_STATUS_WHILE_FORGET_PASSWORD": -2025, "MISSING_USER_WHILE_FORGET_PASSWORD": -2026, "INVALID_USER_ACCOUNT_STATUS": -2030, "MISSING_EMAIL_WHILE_SUBMITTING_FORGET_PASSWORD_PAGE": -2039, "MISSING_RECAPTCHA_RESPONSE_WHILE_SUBMITTING_FORGET_PASSWORD_PAGE": -2040, "INVALID_DUE_TO_REGISTERED_ACCOUNT_STATUS": -2042, "ACCOUNT_TYPE_NOT_PL_WHILE_FORGET_PASSWORD": -2043, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_GET_PUBLIC_KEY_RESET_PASSWORD": -2121, "INVALID_RESPONSE_FORMAT_WHILE_GET_PUBLIC_KEY_RESET_PASSWORD": -2122, "MISSING_RESPONSE_WHILE_GET_PUBLIC_KEY_RESET_PASSWORD": -2123, "MISSING_STATUS_WHILE_GET_PUBLIC_KEY_RESET_PASSWORD": -2124, "MISSING_STATUS_CODE_WHILE_GET_PUBLIC_KEY_RESET_PASSWORD": -2125, "SESSION_FOUND_WHILE_SUBMITTING_RESET_PASSWORD_PAGE": -2126, "MISSING_DATA_WHILE_GET_PUBLIC_KEY_RESET_PASSWORD": -2127, "MISSING_PUBLIC_KEY_WHILE_GET_PUBLIC_KEY_RESET_PASSWORD": -2128, "MISSING_TX_UUID_WHILE_GET_PUBLIC_KEY_RESET_PASSWORD": -2129, "UNABLE_TO_ENCRYPT_KEY_WHILE_ENCRYPTING_KEY_RESET_PASSWORD": -2130, "EMPTY_ENCRYPTED_KEY_WHILE_ENCRYPTING_KEY_RESET_PASSWORD": -2131, "MISSING_RESPONSE_WHILE_RESET_PASSWORD": -2132, "MISSING_STATUS_WHILE_RESET_PASSWORD": -2133, "MISSING_STATUS_CODE_WHILE_RESET_PASSWORD": -2134, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_RESET_PASSWORD": -2135, "INVALID_RESPONSE_FORMAT_WHILE_RESET_PASSWORD": -2136, "MISSING_NEW_PASSWORD_WHILE_SUBMIT_RESET_PASSWORD": -2158, "PASSWORD_DOES_NOT_CONFORM_TO_IM8_WHILE_SUBMIT_RESET_PASSWORD": -2163, "PASSWORD_TOO_COMMON_WHILE_SUBMIT_RESET_PASSWORD": -2165, "MISSING_RESPONSE_WHILE_UPDATE_PASSWORD": -2212, "MISSING_STATUS_WHILE_UPDATE_PASSWORD": -2213, "MISSING_STATUS_CODE_WHILE_UPDATE_PASSWORD": -2214, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_UPDATE_PASSWORD": -2215, "INVALID_RESPONSE_FORMAT_WHILE_UPDATE_PASSWORD": -2216, "MISSING_ENCRYPTED_CURRENT_PASSWORD_WHILE_SUBMIT_UPDATE_PASSWORD": -2223, "MISSING_ENCRYPTED_NEW_PASSWORD_WHILE_SUBMIT_UPDATE_PASSWORD": -2224, "INCORRECT_CURRENT_PASSWORD_WHILE_UPDATE_PASSWORD": -2340, "PASSWORD_TOO_COMMON_WHILE_SUBMIT_UPDATE_PASSWORD": -2345, "PASSWORD_DOES_NOT_CONFORM_TO_IM8_WHILE_SUBMIT_UPDATE_PASSWORD": -2346, "MISSING_UEN_WHILE_LOGIN": -6006, "MISSING_NRIC_FIN_WHILE_LOGIN": -6007, "MISSING_RESPONSE_WHILE_INIT_CORPPASS_TEST_LOGIN": -6069, "MISSING_STATUS_WHILE_INIT_CORPPASS_TEST_LOGIN": -6070, "MISSING_STATUS_CODE_WHILE_INIT_CORPPASS_TEST_LOGIN": -6071, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_INIT_CORPPASS_TEST_LOGIN": -6072, "INVALID_RESPONSE_FORMAT_WHILE_INIT_CORPPASS_TEST_LOGIN": -6073, "MISSING_DATA_WHILE_INIT_CORPPASS_TEST_LOGIN": -6074, "MISSING_REDIRECT_URL_WHILE_INIT_CORPPASS_TEST_LOGIN": -6075, "INVALID_ERROR_STATUS_WHILE_INIT_CORPPASS_TEST_LOGIN": -6076, "UNKNOWN_ERROR_WHILE_INIT_CORPPASS_TEST_LOGIN": -6077, "EMPTY_UEN_AND_NRIC_FIN_WHILE_LOGIN": -6078, "EMPTY_UEN_WHILE_LOGIN": -6079, "EMPTY_UEN_AND_INVALID_NRIC_FIN_WHILE_LOGIN": -6080, "EMPTY_NRIC_FIN_WHILE_LOGIN": -6081, "INVALID_UEN_AND_EMPTY_NRIC_FIN_WHILE_LOGIN": -6082, "INVALID_UEN_AND_INVALID_NRIC_FIN_WHILE_LOGIN": -6083, "INVALID_NRIC_FIN_WHILE_LOGIN": -6084, "INVALID_UEN_WHILE_LOGIN": -6085, "MISSING_RESPONSE_WHILE_INIT_SINGPASS_TEST_LOGIN": -6090, "MISSING_STATUS_WHILE_INIT_SINGPASS_TEST_LOGIN": -6091, "MISSING_STATUS_CODE_WHILE_INIT_SINGPASS_TEST_LOGIN": -6092, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_INIT_SINGPASS_TEST_LOGIN": -6093, "INVALID_RESPONSE_FORMAT_WHILE_INIT_SINGPASS_TEST_LOGIN": -6094, "MISSING_DATA_WHILE_INIT_SINGPASS_TEST_LOGIN": -6095, "MISSING_REDIRECT_URL_WHILE_INIT_SINGPASS_TEST_LOGIN": -6096, "INVALID_ERROR_STATUS_WHILE_INIT_SINGPASS_TEST_LOGIN": -6097, "UNKNOWN_ERROR_WHILE_INIT_SINGPASS_TEST_LOGIN": -6098, "MISSING_RESPONSE_WHILE_RETRIEVE_ERROR_PAGE_RESOURCES": -6373, "MISSING_STATUS_WHILE_RETRIEVE_ERROR_PAGE_RESOURCES": -6374, "MISSING_STATUS_CODE_WHILE_RETRIEVE_ERROR_PAGE_RESOURCES": -6375, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_RETRIEVE_ERROR_PAGE_RESOURCES": -6376, "INVALID_RESPONSE_FORMAT_WHILE_RETRIEVE_ERROR_PAGE_RESOURCES": -6377, "SESSION_FOUND_WHILE_RESEND_ACTIVATION": -6649, "MISSING_GOOGLE_CAPTCHA_RESPONSE_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6656, "INVALID_CAPTCHA_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6657, "MISSING_USER_EMAIL_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6658, "USER_NOT_FOUND_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6661, "ACTIVE_USER_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6663, "BLOCKED_USER_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6664, "DISABLED_USER_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6665, "LOCKED_USER_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6666, "MISSING_RESPONSE_WHILE_RESEND_ACTIVATION": -6681, "MISSING_STATUS_WHILE_RESEND_ACTIVATION": -6682, "MISSING_STATUS_CODE_WHILE_RESEND_ACTIVATION": -6683, "INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_RESEND_ACTIVATION": -6684, "INVALID_RESPONSE_FORMAT_WHILE_RESEND_ACTIVATION": -6685, "INVALID_ERROR_STATUS_WHILE_RESEND_ACTIVATION": -6686, "UNKNOWN_ERROR_WHILE_RESEND_EMAIL_FOR_ACTIVATION": -6687, "UNKNOWN_STATUS_CODE_WHILE_RESEND_ACTIVATION": -6688, "ACTIVE_CORPPASS_USER_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6691, "ACTIVE_SINGPASS_USER_WHILE_RESEND_ACTIVATION_WITHOUT_LOGIN": -6692 }; } } })(); </script> <script type="text/javascript"> (function(GLOBAL_ERROR_CODES, $){ var CORPPASS_LINK_SELECTOR = "a.corppass-sign-in-link"; var SINGPASS_LINK_SELECTOR = "a.singpass-sign-in-link"; var ALL_PASS_HOLDER_ID = "all-pass-holder"; var ONLY_SINGPASS_HOLDER_ID = "only-singpass-holder"; var ONLY_CORPPASS_HOLDER_ID = "only-corppass-holder"; var NO_PASS_HOLDER_ID = "no-pass-holder"; var LOADER_CONTAINER_ID = "loader-container"; var FORM_CONTAINER_ID = "form-container"; var ENTRY_ERROR_CONTAINER_ID = "entry-error-container"; var ENTRY_ERROR_RETRY_BTN_ID = "entry-error-retry-btn"; var ENTRY_ERROR_MSG_TEXT_ID = "entry-error-msg"; var LOGIN_ERROR_MSG_HOLDER_ID = "authenticatMsgId"; var LOGIN_ERROR_MSG_TEXT_ID = "login-error-msg"; var MAX_ERROR_MSG_LENGTH = 30; var ENTER_KEY_IDENTIFIER = 13; var RETRIEVE_INIT_DATA_EVENT = "retrievedInitData"; var DOCUMENT_LOADED_EVENT = "documentLoaded"; var FORM_ELEMENT_ID = "loginForm"; var USERNAME_FIELD_ID = "username"; var PASSWORD_FIELD_ID = "password"; var SIGN_IN_BTN_FIELD_ID = "signInBtn"; var ENTRY_URL = getCurrentUrl(); var SERVICE_URL = getCurrentUrlQueryParam("service"); var ACTION = getCurrentUrlQueryParam("action"); var FROM_SERVICE = getCurrentUrlQueryParam("from"); var ACCOUNT_NOT_FOUND_ERROR_MSG = "Invalid username or password."; var INVALID_PASSWORD_OR_USERNAME_ERROR_MSG = "Invalid username or password."; var CORPPASS_LOGIN_ERROR_MSG = "Please login via Singpass for business users."; var SINGPASS_LOGIN_ERROR_MSG = "Please login via Singpass for basic users / developers."; var HELPDESK_ERROR_MSG = "Please contact the helpdesk to access your account."; var ACTIVATE_ACCOUNT_ERROR_MSG = "Please activate your account before login."; var RESET_ACOUNT_PASSWORD_ERROR_MSG = "Please reset your password before login."; if(SERVICE_URL.includes("tih")) { HELPDESK_ERROR_MSG = "Please contact tih_servicedesk@ncs.com.sg to access your account."; } else if (SERVICE_URL.includes("stan")) { HELPDESK_ERROR_MSG = "Please contact stan_servicedesk@ncs.com.sg to access your account."; } else { HELPDESK_ERROR_MSG = "Please contact the helpdesk to access your account."; } var DELAYED_EXECUTOR_FACTORY = (function(){ return { "generate": function(completedCallbackFn, errorCallbackFn, eventKeysArr) { if(typeof(completedCallbackFn) !== "function"){ completedCallbackFn = function(){}; } if(typeof(errorCallbackFn) !== "function"){ errorCallbackFn = function(){}; } if(!Array.isArray(eventKeysArr) || eventKeysArr.length <= 0){ completedCallbackFn(); return { "complete": function(){}, "setError": function(){} }; } var totalEventsLapsed = 0; var totalEvents = 0; var eventKeysObj = {}; for(var i = 0, sz = eventKeysArr.length; i < sz; ++i){ var eventKy = eventKeysArr[i]; if(typeof(eventKy) !== "string" || eventKy.length <= 0){ continue; } if(eventKeysObj[eventKy] === false){ continue; } totalEvents += 1; eventKeysObj[eventKy] = false; } if(totalEvents <= 0){ completedCallbackFn(); return { "complete": function(){}, "setError": function(){} }; } var hasError = false; return { "complete": function(eventKey) { if(typeof(eventKey) !== "string" || eventKey.length <= 0){ return; } var eventValue = eventKeysObj[eventKey]; if(typeof(eventValue) !== "boolean" || eventValue){ return; } eventKeysObj[eventKey] = true; totalEventsLapsed += 1; if(totalEventsLapsed >= totalEvents){ if(hasError === true){ errorCallbackFn(); } else { completedCallbackFn(); } } }, "setError": function() { hasError = true; } } } } })(); var ENTRY_EXECUTOR = DELAYED_EXECUTOR_FACTORY.generate(displayForm, displayEntryError, [RETRIEVE_INIT_DATA_EVENT, DOCUMENT_LOADED_EVENT]); getInitData(ENTRY_URL, function(code, data){ setupInitData(code, data, function(){ ENTRY_EXECUTOR.complete(RETRIEVE_INIT_DATA_EVENT); }, function(){ ENTRY_EXECUTOR.setError(); ENTRY_EXECUTOR.complete(RETRIEVE_INIT_DATA_EVENT); }) }); $(document).ready(function(){ setupRetryBtn(); setupForm(); setupUsernameField(); setupPasswordField(); setupLoginButton(); ENTRY_EXECUTOR.complete(DOCUMENT_LOADED_EVENT); }); function preventDefaultAction(evt) { try { if(!evt){ return; } evt.preventDefault(); } catch(e){ console.log("preventDefaultAction() => e =", e); } } function setupForm() { $("#" + FORM_ELEMENT_ID).off("submit").on("submit", function(evt){ preventDefaultAction(evt); }); } function setupLoginButton() { $("#" + SIGN_IN_BTN_FIELD_ID).off("click").on("click", function(evt){ preventDefaultAction(evt); if(isDisabled(SIGN_IN_BTN_FIELD_ID)){ return; } login(); }); } function isEnterKeyFromEvent(evt) { try { return evt && (evt.which === ENTER_KEY_IDENTIFIER); } catch(e){ console.log("isEnterKeyFromEvent() => e =", e); } return false; } function setupUsernameField() { $("#" + USERNAME_FIELD_ID).off("keyup").on("keyup", function(evt){ if(isDisabled(SIGN_IN_BTN_FIELD_ID)){ return; } if(!isEnterKeyFromEvent(evt)){ return; } login(); }); } function setupPasswordField() { $("#" + PASSWORD_FIELD_ID).off("keyup").on("keyup", function(evt){ if(isDisabled(SIGN_IN_BTN_FIELD_ID)){ return; } if(!isEnterKeyFromEvent(evt)){ return; } login(); }); } function validateOnSubmit(userName, password, callbackFn) { if(typeof(callbackFn) !== "function"){ callbackFn = function(){}; } if(isEmptyString(userName)){ displayLoginStatusMsg(INVALID_PASSWORD_OR_USERNAME_ERROR_MSG); callbackFn(false); } else if(isEmptyString(password)) { displayLoginStatusMsg(INVALID_PASSWORD_OR_USERNAME_ERROR_MSG); callbackFn(false); } else { hideLoginStatusMsg(); callbackFn(true); } } function trimString(str) { try { if(isEmptyString(str)){ return str; } return str.trim(); } catch(e) { console.log("trimString() => e =", e); } return str; } function login() { hideLoginStatusMsg(); var enableUIFn = disableUI(); var userName = trimString(getStringValueFromInput(USERNAME_FIELD_ID)); var password = getStringValueFromInput(PASSWORD_FIELD_ID); validateOnSubmit(userName, password, function(isValid){ if(typeof(enableUIFn) !== "function"){ enableUIFn = function(){}; } if(isValid !== true){ enableUIFn(); return; } initiateLogin(userName, password, SERVICE_URL, ACTION, ENTRY_URL, FROM_SERVICE, function(code, data){ handleLogin(code, data, function(){ console.log("successful login"); }, function(){ enableUIFn(); }); }); }); } function disableUI() { disableElement(USERNAME_FIELD_ID); disableElement(PASSWORD_FIELD_ID); disableElement(SIGN_IN_BTN_FIELD_ID); return function() { enableElement(USERNAME_FIELD_ID); enableElement(PASSWORD_FIELD_ID); enableElement(SIGN_IN_BTN_FIELD_ID); } } function isDisabled(elementId) { try { var ele = document.getElementById(elementId); if(!ele){ return false; } return ele.disabled === true; } catch(e){ console.log("isDisabled() => e =", e); } return false; } function enableElement(elementId) { try { var ele = document.getElementById(elementId); if(!ele){ return false; } ele.disabled = false; return true; } catch(e){ console.log("enableElement() => e =", e); } return false; } function disableElement(elementId) { try { var ele = document.getElementById(elementId); if(!ele){ return false; } ele.disabled = true; return true; } catch(e){ console.log("disableElement() => e =", e); } return false; } function getStringValueFromInput(elementId) { try { var ele = document.getElementById(elementId); if(!ele){ return ""; } var eleValue = ele.value; if(typeof(eleValue) !== "string" || eleValue.length <= 0){ return ""; } return eleValue; } catch(e){ console.log("getStringValueFromInput() => e =", e); } return ""; } function getCurrentUrlQueryParam(key) { try { if(typeof(key) !== "string" || key.length <= 0){ return ""; } var currentUrl = window.location.href; var uriObj = URI(currentUrl); var queryMap = uriObj.query(true); if(!queryMap){ return ""; } var queryVal = queryMap[key]; if(typeof(queryVal) === "string"){ return queryVal; } else if(Array.isArray(queryVal) && queryVal.length > 0){ return findFirstString(queryVal); } else { return ""; } } catch(e) { console.log("getCurrentUrlQueryParam() => e =", e); } return ""; } function findFirstString(strArr) { if(!Array.isArray(strArr) || strArr.length <= 0){ return ""; } for(var i = 0, sz = strArr.length; i < sz; ++i){ if(typeof(strArr[i]) === "string"){ return strArr[i]; } } return ""; } function getCurrentUrl() { try { return window.location.href; } catch(e) { console.log("getCurrentUrl() => e =", e); } return ""; } function displayLoader() { try { var loaderContainer = $("#" + LOADER_CONTAINER_ID); var errorContainer = $("#" + ENTRY_ERROR_CONTAINER_ID); var formContainer = $("#" + FORM_CONTAINER_ID); errorContainer.addClass("hide"); formContainer.addClass("hide"); loaderContainer.removeClass("hide"); } catch (e) { console.log("displayForm() => e =", e); } } function displayForm() { try { var loaderContainer = $("#" + LOADER_CONTAINER_ID); var errorContainer = $("#" + ENTRY_ERROR_CONTAINER_ID); var formContainer = $("#" + FORM_CONTAINER_ID); loaderContainer.addClass("hide"); errorContainer.addClass("hide"); formContainer.removeClass("hide"); } catch(e){ console.log("displayForm() => e =", e); } } function displayEntryError() { try { var loaderContainer = $("#" + LOADER_CONTAINER_ID); var errorContainer = $("#" + ENTRY_ERROR_CONTAINER_ID); var formContainer = $("#" + FORM_CONTAINER_ID); loaderContainer.addClass("hide"); formContainer.addClass("hide"); errorContainer.removeClass("hide"); } catch(e){ console.log("displayEntryError() => e =", e); } } function isEmptyString(str) { return typeof(str) !== "string" || str.length <= 0; } function getSearchStringFromUrl(url) { try { if(isEmptyString(url)){ return ""; } var uri = URI(url); return uri.search(); } catch(e){ console.log("getSearchStringFromUrl() => e =", e); } return ""; } function showAllPassHolder(singpassUrl, corppassUrl) { if(isEmptyString(singpassUrl)){ singpassUrl = "#"; } if(isEmptyString(corppassUrl)){ corppassUrl = "#"; } var holder = $("#" + ALL_PASS_HOLDER_ID); var corppassSignInLinkEle = holder.find(CORPPASS_LINK_SELECTOR); var singpassSignInLinkEle = holder.find(SINGPASS_LINK_SELECTOR); corppassSignInLinkEle.attr("href", corppassUrl); singpassSignInLinkEle.attr("href", singpassUrl); holder.removeClass("hide"); } function showOnlySingpassHolder(singpassUrl) { if(isEmptyString(singpassUrl)){ singpassUrl = "#"; } var holder = $("#" + ONLY_SINGPASS_HOLDER_ID); var singpassSignInLinkEle = holder.find(SINGPASS_LINK_SELECTOR); singpassSignInLinkEle.attr("href", singpassUrl); holder.removeClass("hide"); } function showOnlyCorppassHolder(corppassUrl) { if(isEmptyString(corppassUrl)){ corppassUrl = "#"; } var holder = $("#" + ONLY_CORPPASS_HOLDER_ID); var corppassSignInLinkEle = holder.find(CORPPASS_LINK_SELECTOR); corppassSignInLinkEle.attr("href", corppassUrl); holder.removeClass("hide"); } function showNoPassHolder() { var holder = $("#" + NO_PASS_HOLDER_ID); holder.removeClass("hide"); } function setEntryErrorMsg(errorMsg) { try { if(isEmptyString(errorMsg)){ errorMsg = "An unexpected error occurred"; } var errorMsgTextEle = $("#" + ENTRY_ERROR_MSG_TEXT_ID); errorMsgTextEle.text(errorMsg); } catch(e){ console.log("displayEntryError() => e =", e); } } function getFormattedErrorMsgWithCode(errorCode) { if(!hasStatusCode(errorCode)){ return "An unexpected error occurred. Please try again."; } return "An unexpected error (code: " + errorCode + ") occurred"; } function getFormattedErrorMsgWithText(errorText, maxLength) { if(isEmptyString(errorText)){ return "An unexpected error occurred."; } if(typeof(maxLength) === "number" && errorText.length > maxLength){ errorText = errorText.substring(0, maxLength) + " ..."; } return "An unexpected error (text: " + errorText + ") occurred." } function getFormattedErrorCodeForXHR(errorCode) { if(!hasStatusCode(errorCode)){ return "IM-009"; } return "IM" + errorCode; } function hasStatusCode(statusCode) { return typeof(statusCode) === "number" || !isEmptyString(statusCode); } function setupRetryBtn() { var retryBtn = $("#" + ENTRY_ERROR_RETRY_BTN_ID); retryBtn.off("click").on("click", function(evt){ preventDefaultAction(evt); if(isDisabled(ENTRY_ERROR_RETRY_BTN_ID)){ return; } disableElement(ENTRY_ERROR_RETRY_BTN_ID); displayLoader(); getInitData(ENTRY_URL, function(code, data){ setupInitData(code, data, function(){ displayForm(); }, function(){ enableElement(ENTRY_ERROR_RETRY_BTN_ID); displayEntryError(); }); }); }); } function displayLoginStatusMsg(statusMsg, isHtml) { try { if(isEmptyString(statusMsg)){ statusMsg = "An unexpected error occurred"; isHtml = false; } var loginStatusMsgHolder = $("#" + LOGIN_ERROR_MSG_HOLDER_ID); var loginStatusMsgEle = $("#" + LOGIN_ERROR_MSG_TEXT_ID); if(isHtml === true){ loginStatusMsgEle.html(statusMsg); } else { loginStatusMsgEle.text(statusMsg); } loginStatusMsgHolder.removeClass("hide"); } catch(e){ console.log("displayLoginStatusMsg() => e =", e); } } function hideLoginStatusMsg() { try { var loginStatusMsgHolder = $("#" + LOGIN_ERROR_MSG_HOLDER_ID); loginStatusMsgHolder.addClass("hide"); } catch(e){ console.log("hideLoginStatusMsg() => e =", e); } } function redirectTo(url) { if(isEmptyString(url)){ return; } if(!window || !window.location){ return; } window.location.href = url; } function handleLogin(code, data, onSuccessFn, onErrorFn) { if(typeof(onSuccessFn) !== "function"){ onSuccessFn = function(){}; } if(typeof(onErrorFn) !== "function"){ onErrorFn = function(){}; } if(code === GLOBAL_ERROR_CODES["SUCCESS"]) { if(!data){ displayLoginStatusMsg(getFormattedErrorMsgWithCode(GLOBAL_ERROR_CODES["MISSING_DATA_WHILE_INIT_LOGIN"])); onErrorFn(); return; } /* var action = data["action"]; if(isEmptyString(action)){ displayLoginStatusMsg(getFormattedErrorMsgWithCode(GLOBAL_ERROR_CODES["MISSING_ACTION_WHILE_INIT_LOGIN"])); onErrorFn(); return; }*/ var redirectUuid = data["redirectUuid"]; if(isEmptyString(redirectUuid)){ displayLoginStatusMsg(getFormattedErrorMsgWithCode(GLOBAL_ERROR_CODES["MISSING_REDIRECT_UUID_WHILE_INIT_LOGIN"])); onErrorFn(); return; } var redirectEndpoint = "/iamsso/postLogin"; var redirectEndpointObj = URI(redirectEndpoint).addSearch({"uuid": redirectUuid}); var finalRedirectEndpoint = redirectEndpointObj.toString(); redirectTo(finalRedirectEndpoint); onSuccessFn(); } else if(code === GLOBAL_ERROR_CODES["USER_NOT_FOUND_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(ACCOUNT_NOT_FOUND_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["EMPTY_USERNAME_WHILE_LOGIN"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(INVALID_PASSWORD_OR_USERNAME_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["EMPTY_PASSWORD_WHILE_LOGIN"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(INVALID_PASSWORD_OR_USERNAME_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["EMPTY_USER_NAME_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(INVALID_PASSWORD_OR_USERNAME_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["EMPTY_PASSWORD_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(INVALID_PASSWORD_OR_USERNAME_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["CP_USER_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(CORPPASS_LOGIN_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["SP_USER_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(SINGPASS_LOGIN_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["LOCKED_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(RESET_ACOUNT_PASSWORD_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["DISABLED_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(HELPDESK_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["BLOCKED_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(HELPDESK_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["REGISTERED_USER_ACCOUNT_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(ACTIVATE_ACCOUNT_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["EXPIRED_PASSWORD_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(RESET_ACOUNT_PASSWORD_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["ACCOUNT_LOCKED_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(RESET_ACOUNT_PASSWORD_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["INVALID_USERNAME_PASSWORD_COMBINATION_DURING_USER_CREDENTIAL_VALIDATION_WHILE_AUTHENTICATING_USER"]) { //TODO Might have to remove for security reasons, only for testing purposes displayLoginStatusMsg(INVALID_PASSWORD_OR_USERNAME_ERROR_MSG); onErrorFn(); } else if(code === GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_INIT_LOGIN"] || code === GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_GET_PUBLIC_KEY"]) { var statusCode = getStatusCodeFromErrorObj(data); var statusText = getStatusTextFromErrorObj(data); if(statusCode === GLOBAL_ERROR_CODES["NO_NETWORK_CONNECTIVITY"]){ displayLoginStatusMsg("Please try again when you have network connectivity."); } else if(hasStatusCode(statusCode)){ displayLoginStatusMsg(getFormattedErrorMsgWithCode(getFormattedErrorCodeForXHR(statusCode))); } else if(!isEmptyString(statusText)){ displayLoginStatusMsg(getFormattedErrorMsgWithText(statusText, MAX_ERROR_MSG_LENGTH)); } else { displayLoginStatusMsg(getFormattedErrorMsgWithCode(GLOBAL_ERROR_CODES["INVALID_ERROR_STATUS_WHILE_INIT_LOGIN"])); } onErrorFn(); } else if(typeof(code) === "number") { displayLoginStatusMsg(getFormattedErrorMsgWithCode(code)); onErrorFn(); } else { displayLoginStatusMsg(getFormattedErrorMsgWithCode(GLOBAL_ERROR_CODES["UNKNOWN_ERROR_WHILE_INIT_LOGIN"])); onErrorFn(); } } function setupInitData(code, data, onSuccessFn, onErrorFn) { if(typeof(onSuccessFn) !== "function"){ onSuccessFn = function(){}; } if(typeof(onErrorFn) !== "function"){ onErrorFn = function(){}; } if(code === GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_RETRIEVE_LOGIN_INIT_DATA"]){ var statusCode = getStatusCodeFromErrorObj(data); var statusText = getStatusTextFromErrorObj(data); if(statusCode === GLOBAL_ERROR_CODES["NO_NETWORK_CONNECTIVITY"]){ setEntryErrorMsg(getFormattedErrorMsgWithText("Please try again when you have network connectivity.")); } else if(hasStatusCode(statusCode)){ setEntryErrorMsg(getFormattedErrorMsgWithCode(getFormattedErrorCodeForXHR(statusCode))); } else if(!isEmptyString(statusText)){ setEntryErrorMsg(getFormattedErrorMsgWithText(statusText, MAX_ERROR_MSG_LENGTH)); } else { setEntryErrorMsg(getFormattedErrorMsgWithCode(GLOBAL_ERROR_CODES["INVALID_ERROR_STATUS_WHILE_RETRIEVE_LOGIN_INIT_DATA"])); } onErrorFn(); return; } else if(code !== GLOBAL_ERROR_CODES["SUCCESS"]){ showNoPassHolder(); onSuccessFn(); return; } if(!data) { showNoPassHolder(); onSuccessFn(); return; } var singpassUrl = data["singpassLink"]; var corppassUrl = data["corppassLink"]; var isSingpassUrlEmpty = isEmptyString(singpassUrl); var isCorppassUrlEmpty = isEmptyString(corppassUrl); if(!isSingpassUrlEmpty && !isCorppassUrlEmpty){ showAllPassHolder(singpassUrl, corppassUrl); } else if(!isSingpassUrlEmpty) { showOnlySingpassHolder(singpassUrl); } else if(!isCorppassUrlEmpty) { showOnlyCorppassHolder(corppassUrl); } else { showNoPassHolder(); } onSuccessFn(); } function getStringErrorObj(code, text) { return { "xhrCode": code, "xhrText": text } } function getStatusCodeFromErrorObj(errorObj) { if(!errorObj){ return undefined; } return errorObj["xhrCode"]; } function getStatusTextFromErrorObj(errorObj) { if(!errorObj){ return undefined; } return errorObj["xhrText"]; } function initiateLogin(userName, pd, service, action, referringUrl, fromService, callbackFn) { if(typeof(callbackFn) !== "function"){ callbackFn = function(){}; } var triggerLoginFn = function(epd, txUuid) { var input = { "userName": userName, "password": epd, "service": service, "action": action, "referringUrl": referringUrl, "from": fromService, "txUuid": txUuid }; $.ajax({ url: "/iamsso/initiateLogin", data: JSON.stringify(input), contentType: 'application/json;charset=utf-8', type: 'POST', dataType: 'json', success: function(data) { console.log("initiateLogin() success => data =", data); if(!data){ callbackFn(GLOBAL_ERROR_CODES["MISSING_RESPONSE_WHILE_INIT_LOGIN"]); return; } var status = data["status"]; if(!status){ callbackFn(GLOBAL_ERROR_CODES["MISSING_STATUS_WHILE_INIT_LOGIN"]); return; } var statusCode = status["statusCode"]; if(typeof(statusCode) !== "number"){ callbackFn(GLOBAL_ERROR_CODES["MISSING_STATUS_CODE_WHILE_INIT_LOGIN"]); return; } callbackFn(statusCode, data["data"]); }, error: function(xhr) { console.log("initiateLogin() error => xhr =", xhr); if(xhr && xhr["status"] === GLOBAL_ERROR_CODES["SUCCESS"] && typeof(xhr["responseText"]) === "string"){ callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_INIT_LOGIN"], getStringErrorObj(xhr["status"], xhr["responseText"]) ); } else if(xhr && typeof(xhr["status"]) === "number") { callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_INIT_LOGIN"], getStringErrorObj(xhr["status"], "") ); } else { callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WHILE_INIT_LOGIN"] ); } } }); }; var encryptKeyFn = function(publicKey, encryptedPd, txUuid) { var encrypted = ""; try { var encrypt = new JSEncrypt(); encrypt.setPublicKey(publicKey); encrypted = encrypt.encrypt(encryptedPd); } catch(e) { console.log("encryptKeyFn() => e =", e); callbackFn(GLOBAL_ERROR_CODES["UNABLE_TO_ENCRYPT_KEY_WHILE_ENCRYPTING_KEY"]); return; } if(isEmptyString(encrypted)){ callbackFn(GLOBAL_ERROR_CODES["EMPTY_ENCRYPTED_KEY_WHILE_ENCRYPTING_KEY"]); return; } triggerLoginFn(encrypted, txUuid); }; getPublicKey(function(keyCode, keyData){ if(keyCode === GLOBAL_ERROR_CODES["SUCCESS"]){ if(!keyData){ callbackFn(GLOBAL_ERROR_CODES["MISSING_DATA_WHILE_GET_PUBLIC_KEY"]); return; } var publicKey = keyData["publicKey"]; if(isEmptyString(publicKey)){ callbackFn(GLOBAL_ERROR_CODES["MISSING_PUBLIC_KEY_WHILE_GET_PUBLIC_KEY"]); return; } var txUuid = keyData["uuid"]; if(isEmptyString(txUuid)){ callbackFn(GLOBAL_ERROR_CODES["MISSING_TX_UUID_WHILE_GET_PUBLIC_KEY"]); return; } encryptKeyFn(publicKey, pd, txUuid); } else { callbackFn(keyCode, keyData); } }); } function getInitData(entryUrl, callbackFn) { if(typeof(callbackFn) !== "function"){ callbackFn = function(){}; } if(isEmptyString(entryUrl)){ callbackFn(GLOBAL_ERROR_CODES["MISSING_ENTRY_URL_WHILE_RETRIEVE_LOGIN_INIT_DATA"]); return; } var searchStr = getSearchStringFromUrl(entryUrl); if(isEmptyString(searchStr)){ callbackFn(GLOBAL_ERROR_CODES["MISSING_PARAMETERS_WHILE_RETRIEVE_LOGIN_INIT_DATA"]); return; } var dataUrl = "/iamsso/loginSetup"; var url = dataUrl + searchStr; $.ajax({ url: url, contentType: 'application/json;charset=utf-8', type: 'GET', dataType: 'json', success: function(data) { console.log("getInitData() success => data =", data); if(!data){ callbackFn(GLOBAL_ERROR_CODES["MISSING_RESPONSE_WHILE_RETRIEVE_LOGIN_INIT_DATA"]); return; } var status = data["status"]; if(!status){ callbackFn(GLOBAL_ERROR_CODES["MISSING_STATUS_WHILE_RETRIEVE_LOGIN_INIT_DATA"]); return; } var statusCode = status["statusCode"]; if(typeof(statusCode) !== "number"){ callbackFn(GLOBAL_ERROR_CODES["MISSING_STATUS_CODE_WHILE_RETRIEVE_LOGIN_INIT_DATA"]); return; } callbackFn(statusCode, data["data"]); }, error: function(xhr) { console.log("getInitData() error => xhr =", xhr); if(xhr && xhr["status"] === GLOBAL_ERROR_CODES["SUCCESS"] && typeof(xhr["responseText"]) === "string"){ callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_RETRIEVE_LOGIN_INIT_DATA"], getStringErrorObj(xhr["status"], xhr["responseText"]) ); } else if(xhr && typeof(xhr["status"]) === "number") { callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_RETRIEVE_LOGIN_INIT_DATA"], getStringErrorObj(xhr["status"], "") ); } else { callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WHILE_RETRIEVE_LOGIN_INIT_DATA"]); } } }); } function getPublicKey(callbackFn) { if(typeof(callbackFn) !== "function"){ callbackFn = function(){}; } $.ajax({ url: "/iamsso/generateKey", contentType: 'application/json;charset=utf-8', type: 'GET', dataType: 'json', success: function(data) { console.log("getPublicKey() success => data =", data); if(!data){ callbackFn(GLOBAL_ERROR_CODES["MISSING_RESPONSE_WHILE_GET_PUBLIC_KEY"]); return; } var status = data["status"]; if(!status){ callbackFn(GLOBAL_ERROR_CODES["MISSING_STATUS_WHILE_GET_PUBLIC_KEY"]); return; } var statusCode = status["statusCode"]; if(typeof(statusCode) !== "number"){ callbackFn(GLOBAL_ERROR_CODES["MISSING_STATUS_CODE_WHILE_GET_PUBLIC_KEY"]); return; } callbackFn(statusCode, data["data"]); }, error: function(xhr) { console.log("getPublicKey() error => xhr =", xhr); if(xhr && xhr["status"] === GLOBAL_ERROR_CODES["SUCCESS"] && typeof(xhr["responseText"]) === "string"){ callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_GET_PUBLIC_KEY"], getStringErrorObj(xhr["status"], xhr["responseText"]) ); } else if(xhr && typeof(xhr["status"]) === "number") { callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WITH_STATUS_WHILE_GET_PUBLIC_KEY"], getStringErrorObj(xhr["status"], "") ); } else { callbackFn( GLOBAL_ERROR_CODES["INVALID_RESPONSE_FORMAT_WHILE_GET_PUBLIC_KEY"] ); } } }); } })(GLOBAL_ERROR_CODES_FACTORY.generate(), $); </script> </body> </html>