private IEnumerator Continue(VOGController ctrl) { try { ctrl.DisableInput(); //wait for connection while (!VostopiaClient.HasSessionKey) { yield return null; } //See if user exists ApiCall call = VostopiaClient.Authentication.BeginFindUser(Email); IEnumerator e = call.Wait(); while (e.MoveNext()) { yield return e.Current; } VostopiaUser user = VostopiaClient.Authentication.EndFindUser(call); if (user != null) { var passwordData = new VOGStateAuthPassword.PasswordData(); passwordData.CancelOnBack = false; passwordData.User = user; ctrl.StartTransition(PasswordState, passwordData); } else { if (!ValidateEmail(Email)) { ctrl.ShowMessageDialog("Oops!", "Please enter a valid email address.", () => { }); yield break; } else { ctrl.StartTransition(NewUserState, Email); } } } finally { ctrl.EnableInput(); } }
/** * Authenticate when we're in the Linked Account mode. If we have a valid authentication * token in AuthenticationSettings, use it to automatically log in user. If we have an invalid * authentication token, force the same user to log in again. If we don't have any authentication token, * let the user login or create a new vostopia user. */ public IEnumerator AuthenticateLinkedAccount() { StoredAuthenticationKey userAuthKey = null; if (!string.IsNullOrEmpty(AuthenticationSettings.AuthenticationToken)) { try { userAuthKey = JObject.Parse(AuthenticationSettings.AuthenticationToken).ToObject<StoredAuthenticationKey>(); } catch (System.Exception ex) { Debug.LogWarning("Unable to parse AuthenticationToken, " + ex.ToString()); } } if (userAuthKey != null) { //If we have auth key, try to authenticate automatically ApiCall call = VostopiaClient.Authentication.BeginSignInAuthKey(userAuthKey.AuthKey); IEnumerator e = call.Wait(); while (e.MoveNext()) { yield return e.Current; } if (VostopiaClient.Authentication.EndSignIn(call)) { //authentication completed successfully, nothing more to do AuthenticationCompleted(); yield break; } //If we failed to log in automatically, find the user and get him to supply the password call = VostopiaClient.Authentication.BeginFindUser(userAuthKey.UserName); e = call.Wait(); while (e.MoveNext()) { yield return e.Current; } VostopiaUser user = VostopiaClient.Authentication.EndFindUser(call); if (user != null) { var passwordData = new VOGStateAuthPassword.PasswordData(); passwordData.CancelOnBack = true; passwordData.User = user; StartTransition(PasswordScreen, passwordData); yield break; } } //Otherwise, show the authentication screen var authSelectData = new VOGStateAuthSelect.AuthSelectData(); authSelectData.EnableCancel = true; StartTransition(AuthenticationSelectorScreen, authSelectData); }