Beispiel #1
0
        public async Task<Result<GtokenAPILoginModel>> GTokenAPIAccount(GtokenModelAccountAction model)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["GTOKEN_SERVICE_HOST"]);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                // HTTP POST
                List<KeyValuePair<string, string>> ValueCollection = new List<KeyValuePair<string, string>>();
                string action = string.Empty;
                switch (model.enumAction)
                {
                    #region Account
                    case EGtokenAction.Login:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_USERNAME, model.username));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PASSWORD, model.pwd));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_GAME_ID, model.game_id));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_DEVICE_ID, model.device_id));

                        action = Urls.ACTION_LOGIN;
                        break;
                    case EGtokenAction.Register:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_USERNAME, model.username));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PASSWORD, model.pwd));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_EMAIL, model.email));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_NICKNAME, model.nickname));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_GENDER, model.gender));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_REFERRAL_CODE, model.referral_code));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_IP_ADDRESS, model.ip_address));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_COUNTRY_CODE, model.country_code));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_COUNTRY_NAME, model.country_name));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_GAME_ID, model.game_id));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_DEVICE_ID, model.device_id));
                        action = Urls.ACTION_REGISTER;
                        break;
                    case EGtokenAction.Profile:
                        model.partnerId = string.IsNullOrEmpty(model.partnerId) ? ConfigurationManager.AppSettings["GTOKEN_PARTNER_UID"] : model.partnerId;
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_USERNAME, model.username));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SESSION, model.session));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        action = Urls.ACTION_PROFILE;
                        break;
                    case EGtokenAction.EditProfile:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_NICKNAME, model.nickname));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SESSION, model.session));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_EMAIL, model.email));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_GENDER, model.gender));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_BIO, model.bio));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_COUNTRY_CODE, model.country_code));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_COUNTRY_NAME, model.country_name));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_REFERRAL_CODE, model.referral_code));
                        action = Urls.ACTION_EDIT_PROFILE;
                        break;
                    case EGtokenAction.ConnectOauth:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_TOKEN, model.token));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SESSION, model.session));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SERVICE, model.service));
                        action = Urls.ACTION_CONNECT_OAUTH;
                        break;
                    case EGtokenAction.DisconnectOauth:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SESSION, model.session));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SERVICE, model.service));
                        action = Urls.ACTION_DISCONNECT_OAUTH;
                        break;
                    case EGtokenAction.QueryUserId:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_OAUTH_ID, model.oauth_id));
                        action = Urls.ACTION_QUERY_USER_ID;
                        break;
                    case EGtokenAction.GetNotifications:
                        action = Urls.ACTION_GET_NOTIFICATIONS;
                        break;
                    case EGtokenAction.LoginOauth:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_TOKEN, model.token));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SERVICE, model.service));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_GAME_ID, model.game_id));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_DEVICE_ID, model.device_id));
                        action = Urls.ACTION_LOGIN_OAUTH;
                        break;
                    case EGtokenAction.ChangePassword:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SESSION, model.session));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_NEW_PASSWORD, model.pwd));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_OLD_PASSWORD, model.old_pwd));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_CONFIRM_PASSWORD, model.confirm_pwd));
                        action = Urls.ACTION_CHANGE_PASSWORD;
                        break;
                    case EGtokenAction.CheckOauthConnection:
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_PARTNER_ID, model.partnerId));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SESSION, model.session));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_SERVICE, model.service));
                        ValueCollection.Add(new KeyValuePair<string, string>(ConstantValues.S_TOKEN, model.token));
                        action = Urls.ACTION_CHECK_OAUTH_CONNECTION;
                        break;
                    #endregion
                    default:
                        break;

                }
                var formContent = new FormUrlEncodedContent(ValueCollection);
                HttpResponseMessage response = client.PostAsync(action, formContent).Result;
                if (response.IsSuccessStatusCode)
                {
                    var customerLogin = JsonConvert.DeserializeObject<GtokenAPILoginModel>(await response.Content.ReadAsStringAsync());
                    if (customerLogin.success)
                    {
                        return Result<GtokenAPILoginModel>.Make(customerLogin);
                    }
                    ErrorCodes err;
                    Enum.TryParse(customerLogin.error_code, out err);
                    return Result<GtokenAPILoginModel>.Null(err);
                }
                return Result<GtokenAPILoginModel>.Null(ErrorCodes.ServerError);
            }
        }
 private bool CreateLoginOauth()
 {
     var api = GoPlayApi.Instance;
     string msg = string.Empty;
     if (Session["facebook_identity"] != null)
     {
         var modelAccount = new GtokenModelAccountAction()
         {
             enumAction = EGtokenAction.ConnectOauth,
             service = "Facebook",
             session = Session["gtoken_section"] == null ? string.Empty : Session["gtoken_section"].ToString(),
             token = Session["access_token"] == null ? string.Empty : Session["access_token"].ToString(),
             partnerId = ConfigurationManager.AppSettings["GTOKEN_PARTNER_UID"]
         };
         var result = api.GTokenAPIAccount(modelAccount).Result;
         Session.Remove("facebook_identity");
         Session.Remove("facebook_email");
         Session.Remove("facebook_token");
         Session.Remove("access_token");
         return result.Data != null;
     }
     return true;
 }