示例#1
0
        public async Task <bool> LoginAsync(PandoraConfig config, RESTfulService service, PandoraState pandoraState)
        {
            Dictionary <string, object> data = new Dictionary <string, object>
            {
                { "loginType", "user" },
                { "username", config.Username },
                { "password", config.Password },
                { "partnerAuthToken", pandoraState.PartnerAuthToken },
                { "syncTime", pandoraState.SyncTime }
            };

            CryptoConfig cryptoConfig = PandoraConstants.GetCryptoConfig();
            Crypto       crypto       = new Crypto();

            HttpResponseMessage response = await service.DoPost(PandoraConstants.BuildUrl($"method=auth.userLogin&auth_token={HttpUtility.UrlEncode(pandoraState.PartnerAuthToken)}&partner_id={pandoraState.PartnerId}"), data, cryptoConfig);

            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            PartnerLoginStatusDto loginData = JsonConvert.DeserializeObject <PartnerLoginStatusDto>(await response.Content.ReadAsStringAsync(), serializerSettings);

            if (loginData.Stat == "ok")
            {
                pandoraState.UserAuthToken = loginData.Result.UserAuthToken;
                pandoraState.UserId        = loginData.Result.UserId;
                return(await Task.FromResult(true));
            }
            return(await Task.FromResult(false));
        }
示例#2
0
        public async Task <PandoraState> ConnectAsync(RESTfulService service)
        {
            Dictionary <string, object> data = new Dictionary <string, object>
            {
                { "username", "android" },
                { "password", PandoraConstants.ANDROID_PARTNER_PASSWORD },
                { "deviceModel", "android-generic" },
                { "version", "5" },
                { "includeUrls", true }
            };

            CryptoConfig cryptoConfig = PandoraConstants.GetCryptoConfig();
            Crypto       crypto       = new Crypto();

            HttpResponseMessage response = await service.DoPost(PandoraConstants.BuildUrl("method=auth.partnerLogin"), data, null);

            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            PartnerLoginDataDto loginData = JsonConvert.DeserializeObject <PartnerLoginDataDto>(await response.Content.ReadAsStringAsync(), serializerSettings);
            string partnerAuthToken       = loginData.Result.PartnerAuthToken;
            string decryptedSyncTime      = crypto.Decrypt(cryptoConfig, loginData.Result.SyncTime);
            long   syncTime  = long.Parse(System.Text.RegularExpressions.Regex.Match(decryptedSyncTime.Substring(4), "^[0-9]*").Groups[0].Value);
            int    partnerId = loginData.Result.PartnerId;

            return(await Task.FromResult(new PandoraState {
                PartnerAuthToken = partnerAuthToken,
                SyncTime = syncTime,
                PartnerId = partnerId
            }));
        }