コード例 #1
0
ファイル: UserDatabase.cs プロジェクト: timkoff/SGICollab
    public bool signUp(string username, string password)
    {
        print("Signing up...");

        string urlconcat = "?user[name]=" + username +
                           "&user[password]=" + password +
                           "&user[password_confirmation]=" + password +
                           "&user[maxStageReached]=5" +
                           "&user[admin_id]=" + adminID;

        var r = new HTTP.Request("POST", url + urlconcat);

        r.Send();
        while (!r.isDone)
        {
            if (r.exception != null)
            {
                Debug.Log(r.exception.ToString());
            }
        }

        if (r.exception != null)
        {
            Debug.Log(r.exception.ToString());
        }
        else
        {
            Debug.Log(r.response.Text);
            Hashtable json = (Hashtable)JsonSerializer.Decode(r.response.Bytes);

            if (json.ContainsKey("auth_token"))
            {
                token = json["auth_token"].ToString();
                return(true);
            }
            else if (json.ContainsKey("error"))
            {
                string errorMessage = "";
                if (((Hashtable)json["error"]).ContainsKey("name"))
                {
                    errorMessage = "Username has been taken!";
                }
                else if (((Hashtable)json["error"]).ContainsKey("password"))
                {
                    errorMessage = "Password too short!";
                }
                NecroGUI.showMessage(errorMessage, 2);
            }
        }
        return(false);
    }
コード例 #2
0
ファイル: UserDatabase.cs プロジェクト: timkoff/SGICollab
    //User log in
    public bool login(string username, string password)
    {
        print("Logging in...");

        string urlconcat = "/sign_in" +
                           "?user[name]=" + username +
                           "&user[password]=" + password;

        var r = new HTTP.Request("POST", url + urlconcat);

        r.Send();
        while (!r.isDone)
        {
            if (r.exception != null)
            {
                Debug.Log(r.exception.ToString());
                return(false);
            }
        }

        if (r.exception != null)
        {
            Debug.Log(r.exception.ToString());
            return(false);
        }
        else
        {
            Debug.Log(r.response.Text);

            Hashtable json = (Hashtable)JsonSerializer.Decode(r.response.Bytes);
            if (json.ContainsKey("auth_token"))
            {
                token = json["auth_token"].ToString();
                GameManagerVik.maxStageReached = (int)json["maxStageReached"];
                return(true);
            }
        }
        return(false);
    }