Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************************************
- * WP.idcard
- **********************************************************************************/
- WP.namespace('WP.idcard');
- WP.idcard = (function (){
- //dependencies
- var constant = WP.constants;
- //one-time initialization procedures
- function getVirtualCardInformation(){
- WP.busy.show();
- var invocationData = {
- adapter : 'VirtualIDCard',
- procedure : 'getVirtualIDCard',
- parameters : []
- };
- WL.Client.invokeProcedure(invocationData, {
- onSuccess : getIDCardSuccess,
- onFailure : getIDCardFailure
- });
- }
- function getIDCardSuccess(response){
- WP.busy.hide();
- WL.Logger.debug("[CARD] getIDCardSuccess");
- var card_information = response.invocationResult.item;
- WL.Logger.debug(JSON.stringify(card_information));
- populateCardPage(card_information);
- WL.EncryptedCache.write(constant.WP_CARD_INFO, JSON.stringify(card_information), onWriteSuccess, onWriteFailure);
- function onWriteSuccess(status){
- WL.Logger.debug("Succesfully encrypted card information into cache. Card Info:" + JSON.stringify(card_information));
- }
- function onWriteFailure(status){
- if (status == WL.EncryptedCache.ERROR_EOC_CLOSED){
- somethingWentWrong();
- }
- }
- }
- function getIDCardFailure(){
- WP.busy.hide();
- WL.Logger.debug("[ID CARD] Unable to populate ID card.");
- }
- function populateIdCardForOffline(){
- WL.Logger.debug("[CARD] getIDCarSuccess");
- WL.EncryptedCache.read(constant.WP_CARD_INFO, onDecryptReadSuccess, onDecryptReadFailure);
- function onDecryptReadSuccess(value){
- WL.Logger.debug("Read success. Retrieved value = " + value);
- var card_information = JSON.parse(value);
- populateCardPage(card_information);
- $("#login-page").hide();
- $("#id-page").show();
- changePageGotoMyIdCard();
- }
- function onDecryptReadFailure(status){
- somethingWentWrong();
- }
- }
- function populateCardPage(card_information){
- WL.Logger.debug("Populate card page" + card_information.name);
- $('#name').html("Name: "+card_information.name);
- $('#group').html("Group: "+card_information.group);
- $('#planCode').html("Plan Code: "+card_information.planCode);
- $('#rxBin').html("rxBin: "+card_information.rxBin);
- $('#coverages').html("Coverage: "+card_information.coverages);
- $('#insId a').attr('href', "tel:"+card_information.insId).html("Phone: "+card_information.insId);
- }
- function clearEOC(){
- localStorage.clear(); //TODO: Replace with EOC.destroy()
- }
- function somethingWentWrong(){
- WP.msg.alert("Oops, something went wrong! Try again.");
- WL.Logger.debug("Encrypted cache closed, write failed. error code= "+ status);
- clearEOC();
- changePageGotoIndex();
- }
- //public API
- return {
- populateCardOffline : function(){
- populateIdCardForOffline();
- },
- getCardInfo : function(){
- getVirtualCardInformation();
- }
- };
- }());//end WP.idcard
- /**********************************************************************************
- * WP.eoc
- **********************************************************************************/
- // EOC
- WP.namespace('WP.eoc');
- WP.eoc = (function(){
- //dependencies
- var constant = WP.constants,
- idcard = WP.idcard,
- passcodeAttempts = 3,
- correctPasscodeHasBeenEntered = false;
- $('#submitPasscodeButton').live('click', function(){
- var passcode = $('#passcode').val();
- var passcode_confirmation = $('#confirm_passcode').val();
- if( passcode.length > 0 && (passcode === passcode_confirmation) ){
- WL.Logger.debug("[EOC] The passcode is valid. Creating EOC. Passcode: " + passcode);
- correctPasscodeHasBeenEntered = true;
- // TODO handle failure
- WP.busy.show();
- createEOC(passcode, showLoginPage, function(){});
- }else{
- WL.Logger.debug("[EOC] The passcodes entered are invalid Passcode1: " + passcode + " Passcode2: " + passcode_confirmation);
- WP.msg.alert("Your passcodes did not match. Please try again.");
- // TODO remove/change this
- clearEOC();
- $('#passcode').val('');
- $('#confirm_passcode').val('');
- }
- });
- $('#validatePasscodeButton').live('click', function(){
- WL.Logger.debug("[EOC] Validating user entered passcode");
- var passcode = $('#enter_passcode').val();
- WP.busy.show();
- // Try to open the EOC with
- WL.EncryptedCache.open(passcode, true, onOpenComplete, onOpenError);
- function onOpenComplete(status){
- WP.busy.hide();
- WL.Logger.debug("[EOC] Passcode entered correct. Getting credentials from EOC.");
- correctPasscodeHasBeenEntered = true;
- // Open success, get credentials
- WL.EncryptedCache.read(constant.KEY_CREDENTIALS, onDecryptReadSuccess, onDecryptReadFailure);
- function onDecryptReadSuccess(value){
- WL.Logger.debug("Read success. Retrieved value = " + value);
- var credentials = JSON.parse(value);
- $("#username").val(credentials.j_username);
- $("#password").val(credentials.j_password);
- if(isOnline){
- showLoginPage();
- }else{
- idcard.populateCardOffline();
- }
- }
- function onDecryptReadFailure(status){
- WL.Logger.debug("Encrypted cache closed, reading failed");
- }
- }
- function onOpenError(status){
- WP.busy.hide();
- WL.Logger.debug("[EOC] Open cache with passcode failed. Clearing the EOC");
- failedPasscodeAttempt();
- }
- });
- function showLoginPage(){
- WL.Logger.debug("[Login] Showing login page");
- WP.busy.hide();
- WL.Client.login("WellPointAppRealm", {
- onSuccess: function(){
- WL.Logger.debug("[Authentication] Login was successful.");
- idcard.getCardInfo();
- changePageGotoMyIdCard();
- },
- onFailure: function(){
- WL.Logger.debug("[Authentication] Login failed.");
- }
- });
- };
- function showIDCard(){
- //TODO: Add support for devices that don't support localstorage
- var eocExists = isEocCreated();
- if(WL.Client.isUserAuthenticated("WellPointAppRealm") || correctPasscodeHasBeenEntered){
- changePageGotoMyIdCard();
- }
- else if( eocExists ){
- WL.Logger.debug("[EOC] EOC exists, prompting for passcode to use EOC");
- changePageGotoPasswordPrompt();
- }else if( !isOnline ){ //=== no EOC, offline
- WL.Logger.debug("[EOC] EOC offline and user online. Cannot access anything.");
- WP.msg.alert("You must be online the first time you access this feature.");
- }else{ // === online, no EOC
- WL.Logger.debug("[EOC] The user is online but the EOC has not been created. Prompting for passcode.");
- changePageGotoCreatePassword();
- }
- }
- function createEOC(passcode, onSuccess, onFailure){
- WL.EncryptedCache.open(passcode, true, onSuccess, onFailure);
- function onOpenComplete(status){
- onSuccess();
- }
- function onOpenError(status){
- switch(status){
- case WL.EncryptedCache.ERROR_KEY_CREATION_IN_PROGRESS:
- WL.Logger.debug("ERROR: KEY CREATION IN PROGRESS");
- break;
- case WL.EncryptedCache.ERROR_LOCAL_STORAGE_NOT_SUPPORTED:
- WL.Logger.debug("ERROR: LOCAL STORAGE NOT SUPPORTED");
- break;
- case WL.EncryptedCache.ERROR_NO_EOC:
- WL.Logger.debug("ERROR: NO EOC");
- break;
- case WL.EncryptedCache.ERROR_COULD_NOT_GENERATE_KEY:
- WL.Logger.debug("ERROR: COULD NOT GENERATE KEY");
- break;
- case WL.EncryptedCache.ERROR_CREDENTIALS_MISMATCH:
- WL.Logger.debug("ERROR: CREDENTIALS MISMATCH");
- break;
- }
- }
- }
- function saveCredentialsToEOC(params){
- WL.EncryptedCache.write(constant.KEY_CREDENTIALS, JSON.stringify(params), onWriteSuccess, onWriteFailure);
- function onWriteSuccess(status){
- WL.Logger.debug("Succesfully encrypted credentials into cache. Credentials:" + JSON.stringify(params));
- }
- function onWriteFailure(status){
- if (status == WL.EncryptedCache.ERROR_EOC_CLOSED){
- WL.Logger.debug("Encrypted cache closed, write failed. error code= "+ status);
- clearEOC();
- changePageGotoIndex();
- }
- }
- }
- function clearEOC(){
- localStorage.clear(); //TODO: Replace with EOC.destroy()
- }
- function failedPasscodeAttempt(){
- passcodeAttempts--;
- if(passcodeAttempts === 0){
- WP.msg.alert("You have entered the passcode incorrectly 3 times. The cache will now be destroyed");
- clearEOC();
- changePageGotoIndex();
- }else{
- WP.msg.alert("Incorrect passcode. You have " + passcodeAttempts + " more attempt(s) before the cache will be destroyed.");
- }
- }
- function isEocCreated(){
- var STORAGE_PREFIX = "__$WLEOC__";
- var SALT_KEY = "__$WLEOC_SALT";
- var CIPHER_KEY = "__$WLEOC_CIPHER";
- var i = localStorage.length;
- while( i-- ) {
- var key = localStorage.key(i);
- if (key.indexOf(STORAGE_PREFIX) === 0 ||
- key.indexOf(SALT_KEY) === 0 ||
- key.indexOf(CIPHER_KEY) === 0) {
- //TODO: Try checkin just whatever I end up using to store the user/pass obj
- return true;
- }
- }//end loop
- return false;
- }
- //public API
- return {
- show : function(){
- showIDCard();
- },
- saveCredentials : function(params){
- saveCredentialsToEOC(params);
- }
- };
- }());//WP.eoc
- //////////////////////////////////////// AUTH.JS //////////////////////////////////////////
- function onFormSubmit() {
- var reqURL = './' + LOGIN_PAGE_SECURITY_INDICATOR;
- var params = {
- j_username : $(USERNAME_INPUT_ID).val(),
- j_password : $(PASSWORD_INPUT_ID).val()
- };
- WL.Logger.debug("[Authenication] Auth saving credentials to EOC. Credentials: " + JSON.stringify(params));
- WP.eoc.saveCredentials(params);
- onSubmitCallback(reqURL, {parameters:params});
- }
Add Comment
Please, Sign In to add comment