Пример #1
0
    public static void LoginUserWithGameCenterId(string id, Action <bool> callback)
    {
        string auth = System.Convert.ToBase64String(Encoding.UTF8.GetBytes("gamecenter|" + id));

        Dictionary <string, string> body = new Dictionary <string, string>();

        body.Add("Authorization", auth);
        Gamedonia.RunCoroutine(
            GamedoniaRequest.post("/account/login", JsonMapper.ToJson(body), auth, null, null,
                                  delegate(bool success, object data) {
            if (success)
            {
                sessionToken = JsonMapper.ToObject <GDSessionToken>((string)data);
                PlayerPrefs.SetString("gd_session_token", sessionToken.session_token);
                RegisterDeviceAfterLogin(callback);
            }
            else
            {
                if (callback != null)
                {
                    callback(success);
                }
            }
        }
                                  )
            );
    }
Пример #2
0
    public static void LoginUserWithSessionToken(Action <bool> callback)
    {
        string session_token = PlayerPrefs.GetString("gd_session_token");

        if (session_token != null && session_token.Length > 0)
        {
            string auth = System.Convert.ToBase64String(Encoding.UTF8.GetBytes("session_token|" + session_token));

            Dictionary <string, string> body = new Dictionary <string, string> ();
            body.Add(GamedoniaRequest.GD_AUTH, auth);
            Gamedonia.RunCoroutine(
                GamedoniaRequest.post("/account/login", JsonMapper.ToJson(body), auth, null, null,
                                      delegate(bool success, object data) {
                if (success)
                {
                    sessionToken = JsonMapper.ToObject <GDSessionToken> ((string)data);
                    RegisterDeviceAfterLogin(callback);
                }
                else
                {
                    if (callback != null)
                    {
                        callback(success);
                    }
                }
            }
                                      )
                );
        }
        else
        {
            Debug.LogWarning("No sessionToken stored in PlayerPrefs");
            if (callback != null)
            {
                callback(false);
            }
        }
    }
    public static void LoginUserWithSessionToken(Action<bool> callback)
    {
        string session_token = PlayerPrefs.GetString("gd_session_token");
        if (session_token != null && session_token.Length > 0) {
            string auth = System.Convert.ToBase64String (Encoding.UTF8.GetBytes ("session_token|" + session_token));

            Dictionary<string,string> body = new Dictionary<string, string> ();
            body.Add (GamedoniaRequest.GD_AUTH, auth);
            Gamedonia.RunCoroutine (
            GamedoniaRequest.post ("/account/login", JsonMapper.ToJson (body), auth, null, null,
                delegate (bool success, object data) {
                            if (success) {
                                    sessionToken = JsonMapper.ToObject<GDSessionToken> ((string)data);
                                    RegisterDeviceAfterLogin (callback);
                            } else {
                                    if (callback != null)
                                            callback (success);
                            }
                    }
                )
            );
        } else {
            Debug.LogWarning("No sessionToken stored in PlayerPrefs");
            if (callback!=null) callback(false);
        }
    }
    public static void LoginUserWithTwitter(string twuid, string twTokenSecret, string twToken, Action<bool> callback)
    {
        string auth = System.Convert.ToBase64String(Encoding.UTF8.GetBytes("twitter|" + twuid + "|" + twTokenSecret + "|" + twToken));

        Dictionary<string,string> body = new Dictionary<string, string>();
        body.Add(GamedoniaRequest.GD_AUTH,auth);
        Gamedonia.RunCoroutine(
            GamedoniaRequest.post("/account/login",JsonMapper.ToJson(body),auth,null,null,
                delegate (bool success, object data) {
                    if (success) {
                        sessionToken = JsonMapper.ToObject<GDSessionToken>((string)data);
                        PlayerPrefs.SetString("gd_session_token", sessionToken.session_token);
                        RegisterDeviceAfterLogin(callback);
                    }else {
                        if (callback != null) callback(success);
                    }
                }
         	 )
        );
    }
    public static void LoginUserWithEmail(string email, string password, Action<bool> callback)
    {
        string auth = System.Convert.ToBase64String(Encoding.UTF8.GetBytes("email|" + email + "|" + password));

        Dictionary<string,string> body = new Dictionary<string, string>();
        body.Add("Authorization",auth);
        Gamedonia.RunCoroutine(
            GamedoniaRequest.post("/account/login",JsonMapper.ToJson(body),auth,null,null,
                delegate (bool success, object data) {
                    if (success) {
                        sessionToken = JsonMapper.ToObject<GDSessionToken>((string)data);
                        PlayerPrefs.SetString("gd_session_token", sessionToken.session_token);
                        RegisterDeviceAfterLogin(callback);
                    }else {
                        if (callback != null) callback(success);
                    }
                }
         	 )
        );
    }