public IEnumerator Start() { loginUI = FindObjectOfType <LoginUI>(); // Init SF controller SalesforceClient client = GetComponent <SalesforceClient>(); if (ApplicationState.sfConnection != null) { client.setConnection(ApplicationState.sfConnection); } sfController = new SalesforceController(this, client); // Is this the first run? if (ApplicationState.sfConnection == null) { // Show login screen yield return(FindObjectOfType <VRUtil>().enableVrMode(false)); loginUI.setSalesforceController(sfController); StartCoroutine(loginUI.fadeIn()); } else // Returning to menu, display config list { // Destroy non-VR UI Destroy(loginUI.gameObject); Destroy(FindObjectOfType <StandaloneInputModule>()); // Enable VR UI StartCoroutine(Camera.main.fadeIn(3)); setVrUiScreen(configurationSelectionContainer.name); yield return(initConfigSelectionView()); yield return(transitionUi(true)); } }
public IEnumerator login(string username, string password) { // Check for existing connection SalesforceConnection connection = ApplicationState.sfConnection; if (connection != null) { sfClient.setConnection(connection); Debug.Log("Salesforce connection resumed."); yield return(true); } else // Establish a new connection { // Set OAuth settings sfClient.consumerKey = SalesforceAuthConfig.OAUTH_CONSUMER_KEY; sfClient.consumerSecret = SalesforceAuthConfig.OAUTH_CONSUMER_SECRET; // Attemp login bool isUserLogged = false; bool shouldRetry = true; while (!isUserLogged && shouldRetry) { Coroutine <bool> routine = owner.StartCoroutine <bool>( sfClient.login(username, password) ); yield return(routine.coroutine); try { isUserLogged = routine.getValue(); Debug.Log("Salesforce login successful."); // Store connection for later use ApplicationState.sfConnection = sfClient.getConnection(); } catch (SalesforceConfigurationException e) { throw e; } catch (SalesforceAuthenticationException e) { throw e; } catch (SalesforceApiException) { Debug.Log("Salesforce login failed, retrying..."); } } yield return(isUserLogged); } }