Exemple #1
0
    //Facebook
    public static IEnumerator TryToRegisterFB(AS_AccountInfo newAccountInfo, Action <string> resultCallback, string email, string nickname, string hostUrl = null)
    {
        if (hostUrl == null)
        {
            hostUrl = AS_Credentials.phpScriptsLocation;
        }

        if (hostUrl == "")
        {
            Debug.LogError("AccountSystem: Host URL not set..! Please load the Account System Setup window.");
            yield break;
        }

        // Location of the registration script
        string url = hostUrl + registerPhp;


        url += "&requiredForMobile=" + UnityEngine.Random.Range(0, int.MaxValue).ToString();

        // Create a new form
        WWWForm form = new WWWForm();

        // Hash the password
        string password       = newAccountInfo.fields.GetFieldValue("password");
        string hashedPassword = newAccountInfo.fields.GetFieldValue("password").Hash();

        newAccountInfo.fields.SetFieldValue("password", hashedPassword);

        // If there should be an account activation, make sure we require it
        //bool requireEmailActivation = false;// (newAccountInfo.fields.GetIndex("isactive") >= 0);
        // if (requireEmailActivation)
        //     newAccountInfo.fields.SetFieldValue("isactive", "0");
        newAccountInfo.fields.SetFieldValue("isactive", "1");

        // Serialize the custom info field
        newAccountInfo.SerializeCustomInfo();

        // Serialize the account info
        string serializedAccountInfo = newAccountInfo.AccInfoToString(false);

        if (serializedAccountInfo == null)
        {
            Debug.LogError("AccountSystem: Could not serialize account info - check previous Debug.Log for errors");
            yield break;
        }

        form.AddField("newAccountInfo", serializedAccountInfo);

        form.AddField("requireEmailActivation", 1);

        // Connect to the script
        WWW www = new WWW(url, form);

        // Wait for it to respond
        yield return(www);


        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError("AccountSystem: WWW Error:\n" + www.error);
            resultCallback("Error: Could not connect. Please try again later!");
            yield break;
        }
        if (www.text.ToLower().Contains("error"))
        {
            Debug.LogError("AccountSystem: PHP/MySQL Error:\n" + www.text);
            resultCallback(www.text.HandleError());
            yield break;
        }

        if (www.text.ToLower().Contains("success"))
        {
            Net.instance.OnLoginFB(email, password, nickname);
            //Debug.Log("AccountSystem: New account registered successfully!\n" + www.text);
            //resultCallback("New account registered successfully!");
        }
        else
        {
            Debug.LogError("AccountSystem: Could not register new account - Check Message:\n" + www.text);
            resultCallback("Error: Could not register new account");
        }


        yield break;
    }
Exemple #2
0
    /// <summary>
    /// Attempt to login to our database. When we are done with that attempt, return something meaningful or an error message.
    /// </summary>
    public static IEnumerator TryToUploadAccountInfoToDb(int id, AS_AccountInfo accountInfo, System.Action <string> callback, string phpScriptsLocation = null)
    {
        if (phpScriptsLocation == null)
        {
            phpScriptsLocation = AS_Credentials.phpScriptsLocation;
        }

        if (phpScriptsLocation == "")
        {
            Debug.LogError("AccountSystem: PHP Scripts Location not set..! Please load the Setup scene located in ../AccountSystem/Setup/");
            yield break;
        }

        Debug.Log("AccountSystem: Uploading Account Info for user with id " + id);


        // Location of our download info script
        string url = phpScriptsLocation + setAccountInfoPhp;


        url += "&requiredForMobile=" + UnityEngine.Random.Range(0, int.MaxValue).ToString();


        // Create a new form
        WWWForm form = new WWWForm();

        // Add The required fields
        form.AddField("id", WWW.EscapeURL(id.ToString()));

        // Serialize the customInfo field
        if (!accountInfo.SerializeCustomInfo())
        {
            Debug.LogError("AccountSystem: Could not serialize custom info - check previous Debug.Log for errors");
            yield break;
        }
        string serializedAccountInfo = accountInfo.AccInfoToString(true);

        if (serializedAccountInfo == null)
        {
            Debug.LogError("AccountSystem: Could not serialize account info - check previous Debug.Log for errors");
            yield break;
        }

        form.AddField("info", serializedAccountInfo);


        // Connect to the script
        WWW www = new WWW(url, form);

        // Wait for it to respond
        Debug.Log("AccountSystem: Awaiting response from: " + url);
        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError("AccountSystem: WWW Error:\n" + www.error);
            callback("error: " + www.error);
            yield break;
        }
        if (www.text.ToLower().Contains("error"))
        {
            Debug.LogError("AccountSystem: PHP/MySQL Error:\n" + www.text);
            callback("error: " + www.text);
            yield break;
        }

        if (www.text.ToLower().Contains("success"))
        {
            Debug.Log("AccountSystem: Account Info uploaded successfully for user with id " + id);
            callback("Account Info uploaded successfully for user with id " + id);
            yield break;
        }
    }