public void TrySubmitAuthentication() { string trimmedInput = inputField.text.Trim(); inputField.interactable = false; if (Utility.IsEmail(trimmedInput)) { APIClient.SendSecurityCode(trimmedInput, OnSecurityCodeSent, (e) => ProcessWebRequestError(e, false)); } else if (Utility.IsSecurityCode(trimmedInput)) { UserAccountManagement.AuthenticateWithSecurityCode(trimmedInput.ToUpper(), OnAuthenticated, (e) => ProcessWebRequestError(e, true)); } else { StartCoroutine(DisableInteractivity(2f)); MessageSystem.QueueMessage(MessageDisplayData.Type.Error, invalidSubmissionMessage); } }
protected virtual void OnGUI() { EditorGUILayout.LabelField("LOG IN TO/REGISTER YOUR MOD.IO ACCOUNT"); using (new EditorGUI.DisabledScope(isAwaitingServerResponse || isLoggedIn)) { EditorGUILayout.BeginHorizontal(); { using (new EditorGUI.DisabledScope(isInputtingEmail)) { if (GUILayout.Button("Email")) { isInputtingEmail = true; } } using (new EditorGUI.DisabledScope(!isInputtingEmail)) { if (GUILayout.Button("Security Code")) { isInputtingEmail = false; } } } EditorGUILayout.EndHorizontal(); if (isInputtingEmail) { emailAddressInput = EditorGUILayout.TextField("Email Address", emailAddressInput); } else { securityCodeInput = EditorGUILayout.TextField("Security Code", securityCodeInput); } EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Submit")) { isAwaitingServerResponse = true; GUIUtility.keyboardControl = 0; Action <string, MessageType> endRequestSendingAndInputEmail = (m, t) => { isAwaitingServerResponse = false; isInputtingEmail = true; helpMessage = m; helpType = t; Repaint(); }; Action <string, MessageType> endRequestSendingAndInputCode = (m, t) => { isAwaitingServerResponse = false; isInputtingEmail = false; helpMessage = m; helpType = t; Repaint(); }; if (isInputtingEmail) { securityCodeInput = ""; APIClient.SendSecurityCode(emailAddressInput, m => endRequestSendingAndInputCode(m.message, MessageType.Info), e => endRequestSendingAndInputEmail(ConvertErrorToHelpString(e), MessageType.Error)); } else { UserAccountManagement.AuthenticateWithSecurityCode(securityCodeInput, (u) => { helpMessage = ("Welcome " + u.username + "! You have successfully logged in." + " Feel free to close this window."); isLoggedIn = true; LoginWindow.isAwaitingServerResponse = false; Repaint(); if (userLoggedIn != null) { userLoggedIn(u); } }, (e) => { endRequestSendingAndInputCode(ConvertErrorToHelpString(e), MessageType.Error); }); } } } EditorGUILayout.EndHorizontal(); } if (!String.IsNullOrEmpty(helpMessage)) { EditorGUILayout.HelpBox(helpMessage, helpType); } }