void PasswordRecoveryGUI() { // Title GUILayout.Label("~~~==== Password Recovery ====~~~", GUILayout.Width(300)); GUILayout.Label(" ", GUILayout.Width(100)); // Email address prompt GUILayout.Label("Enter your account's email address:", GUILayout.Width(200)); emailPasswordRecovery = GUILayout.TextField(emailPasswordRecovery, GUILayout.Width(200)); // Send email button if (GUILayout.Button("Email password reset link", new GUILayoutOption[] { GUILayout.Width(200), GUILayout.Height(40) })) { emailPasswordRecovery.TryToRecoverPassword(PasswordRecoveryAttempted); // Equivalent to: // StartCoroutine(AS_Login.TryToRecoverPassword ( emailPasswordRecovery, PasswordRecoveryAttempted ) ); guiMessage = "Processing your request.."; } // Return to Login if (GUILayout.Button("Back", new GUILayoutOption[] { GUILayout.Width(100), GUILayout.Height(25) })) { loginState = AS_LoginState.LoginPrompt; } // For errors ( username taken etc.. ) GUILayout.Label(guiMessage); GUILayout.Label(" ", GUILayout.Height(10)); }
// Used by the AttemptDownloadRegistrationForm when it's finished executing void RegistrationFormDownloaded(string callbackMessage) { guiMessage = callbackMessage; if (callbackMessage.IsAnError()) { Debug.LogError(callbackMessage); return; } loginState = AS_LoginState.Registering; // What you want to appear in the registration GUI guiMessage = "Please fill in the required fields."; }
// Called by OnGUI and provides a Logout option void LoggedInGUI() { if (GUI.Button(new Rect(40, Screen.height - 60, 150, 30), "Logout")) { // If we have an account management GUI, enable it if (accountManagementGUI) { accountManagementGUI.enabled = false; } usernameLogin = ""; passwordLogin = ""; loginState = AS_LoginState.LoginPrompt; } }
// Called by the AttemptPasswordRecovery coroutine when it's finished executing public void PasswordRecoveryAttempted(string callbackMessage) { guiMessage = callbackMessage; // If our registration failed, if (callbackMessage.IsAnError()) { Debug.LogError(callbackMessage); return; } // Otherwise, loginState = AS_LoginState.LoginPrompt; guiMessage = callbackMessage; }
// Called by OnGUI and provides a basic registration GUI layout void RegistrationGUI() { // Title GUILayout.Label("~~~==== Registration ====~~~", GUILayout.Width(300)); GUILayout.Label(" ", GUILayout.Width(100)); // Registration Info has the fields the user should fill in foreach (AS_MySQLField field in accountInfo.fields) { // Id is an auto-increment unique identifier // and custom info is not specified during registration if (field.name.ToLower() == "id" | field.name.ToLower() == "custominfo" | field.name.ToLower() == "isactive") { continue; } // For any given field GUILayout.BeginHorizontal(); // Print the name // Check if it's required string msgRequired = field.isRequired ? "\t\b *" : ""; GUILayout.Label(field.name.UppercaseFirst() + msgRequired, GUILayout.Width(200)); // Prompt the user to input the value // And store the value string tempVal = ""; if (field.name.ToLower().Contains("password")) { passwordPrompt = GUILayout.TextField(passwordPrompt, new GUILayoutOption[] { GUILayout.Width(200), GUILayout.Height(20) }); accountInfo.fields.SetFieldValue(field.name, passwordPrompt); } else { tempVal = GUILayout.TextField(accountInfo.fields.GetFieldValue(field.name), new GUILayoutOption[] { GUILayout.Width(200), GUILayout.Height(20) }); accountInfo.fields.SetFieldValue(field.name, tempVal); } GUILayout.EndHorizontal(); // Additionally, if it's the password or email // Ask for confirmation if (field.name.ToLower().Contains("password")) { GUILayout.BeginHorizontal(); GUILayout.Label("Repeat your Password:"******"email")) { GUILayout.BeginHorizontal(); GUILayout.Label("Repeat your Email:", GUILayout.Width(200)); emailConfirm = GUILayout.TextField(emailConfirm, new GUILayoutOption[] { GUILayout.Width(200), GUILayout.Height(20) }); GUILayout.EndHorizontal(); } } GUILayout.Label(" ", GUILayout.Height(10)); GUILayout.Label("*: Required Field", GUILayout.Width(300)); GUILayout.Label(" ", GUILayout.Height(10)); // For errors ( username taken etc.. ) GUILayout.Label(guiMessage); GUILayout.Label(" ", GUILayout.Height(10)); // Submit registration button if (GUILayout.Button("Register", new GUILayoutOption[] { GUILayout.Width(150), GUILayout.Height(50) })) { // Offline field check if (!AS_Login.CheckFields(accountInfo, ref guiMessage)) // passwordConfirm, emailConfirm, ref guiMessage)) { return; } // Online check with the given database guiMessage = "Attempting to Register.."; accountInfo.TryToRegister(RegistrationAttempted); // Equivalent to: // StartCoroutine ( AS_Login.TryToRegister( accountInfo, RegistrationAttempted ) ) ; } // Return to Login if (GUILayout.Button("Back", new GUILayoutOption[] { GUILayout.Width(75), GUILayout.Height(40) })) { usernameLogin = ""; passwordLogin = ""; loginState = AS_LoginState.LoginPrompt; } }
// Called by OnGUI and provides a basic login GUI layout void LoginGUI(bool enablePasswordRecovery) { // Tittle GUILayout.Label("~~~==== Login ====~~~", GUILayout.Width(300)); GUILayout.Label(" ", GUILayout.Width(100)); // Username Propmpt GUILayout.BeginHorizontal(); GUILayout.Label("Username: "******"Password: "******"Login", new GUILayoutOption[] { GUILayout.Width(200), GUILayout.Height(20) })) { // Calls the appropriate php script (its location is specified from the crentials) // with the following arguments {username, password} and when it gets a response, // it calls the function "setLoginState" with the appropriate arguments usernameLogin.TryToLogin(passwordLogin, LoginAttempted); // Equivalent to: // StartCoroutine ( AS_Login.TryToLogin( usernameLogin, passwordLogin, LoginAttempted ) ) ; guiMessage = "Attempting to Log In.."; } // Register Button - Attempts to download the registration form (which fields are required in order to log in if (GUILayout.Button("Register", new GUILayoutOption[] { GUILayout.Width(200), GUILayout.Height(20) })) { passwordPrompt = ""; passwordConfirm = ""; emailConfirm = ""; // When the form is downloaded, RegistrationFormDownloaded is called accountInfo.TryToDownloadRegistrationForm(RegistrationFormDownloaded); // Equivalent to: // StartCoroutine ( AS_Login.TryToDownloadRegistrationForm (accountInfo, RegistrationFormDownloaded) ); guiMessage = "Loading.."; } // Password Recovery screen if (enablePasswordRecovery) { if (GUILayout.Button("Retrieve Password", new GUILayoutOption[] { GUILayout.Width(200), GUILayout.Height(20) })) { loginState = AS_LoginState.RecoverPassword; } } // Tutorial #if UNITY_EDITOR GUILayout.Label("", GUILayout.Height(10)); GUILayout.Label("\bGetting Started:" + "\n1) From the Menu Bar select Window->Online Account System" + "\n2) Follow the Setup Guide" + "\n3) Try to Register and then Login to Manage your Account" + "\n\nThis message was printed from AS_LoginGUI.cs", GUILayout.Width(500)); #endif }