Esempio n. 1
0
        public void JsonLoginObjectToJsonTest()
        {
            TemplateJson tl   = new JsonLogin();
            var          json = tl.GetJson(new Login("*****@*****.**", "Password"));

            Assert.AreEqual(correctJson, json);
        }
Esempio n. 2
0
        /// <summary>
        /// 构建登录信息
        /// </summary>
        /// <returns></returns>
        private JsonLogin CreateLogininfo(string s, string d)
        {
            //登录
            JsonLogin     Loginfo = new JsonLogin();
            JsonLoginHead LogHead = new JsonLoginHead();

            LogHead.serailNumber  = s;
            LogHead.funCode       = "011";
            LogHead.digitalDigest = d;// GetCa();
            LogHead.respCode      = "";
            LogHead.clientMAC     = OtherHelper.GetMac();
            LogHead.clientIP      = OtherHelper.GetIp();
            JsonLoginBody LogBody = new JsonLoginBody();

            LogBody.loginName = "cqyyypk";
            LogBody.password  = HashList("zzllyy_7788");
            //LogBody.password = HashList("123456");
            Loginfo.header = LogHead;
            List <JsonLoginBody> listbody = new List <JsonLoginBody>();

            listbody.Add(LogBody);
            JsonLoginrows LoginRows = new JsonLoginrows();

            LoginRows.rows = listbody;
            Loginfo.body   = LoginRows;

            return(Loginfo);
        }
Esempio n. 3
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns>登录成功返回信息</returns>
        private JsonLoginBack Login(string s, string d)
        {
            try
            {
                JsonLogin Loginfo = CreateLogininfo(s, d);
                //实体序列化和反序列化
                string        jsonData  = "jsonData=" + JsonHelper.SerializeObject(Loginfo);
                string        url       = "http://wl.yao1.cn:8899/scm/do/supply-chain/userlogin";
                string        LoginRst  = JsonHelper.HttpGet(url, jsonData);
                JsonLoginBack LoginBack = JsonHelper.DeserializeJsonToObject <JsonLoginBack>(LoginRst);
                if (LoginBack.header.respCode == "001")
                {
                    return(LoginBack);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);

                throw;
            }
        }
Esempio n. 4
0
        public async Task <string> Login(JsonLogin usu)
        {
            string      respuesta   = "";
            var         json        = JsonConvert.SerializeObject(usu); //serializo el objeto
            HttpContent httpContent = new StringContent(json);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/Json");            //declaro el header del tipo app/Json

            WebApiUrl = ruta + "api/Login";
            var uri = new Uri(WebApiUrl);

            //try
            //{
            var response = await cliente.PostAsync(uri, httpContent);                    //es la union del localhost:44339/api/Lognin + lo que manda el objeto

            if (response.IsSuccessStatusCode)
            {
                var LoginJsonString = await response.Content.ReadAsStringAsync();

                respuesta = JsonConvert.DeserializeObject <string>(LoginJsonString);
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Error en los datos", "OK");
            }
            //}
            //catch (Exception ex)
            //{

            //	await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            //}
            return(respuesta);
        }
Esempio n. 5
0
        public void JsonLoginJsonToObjectTest()
        {
            TemplateJson tl = new JsonLogin();
            var          o  = tl.GetObject(correctJson) as Login;

            Assert.AreEqual("*****@*****.**", o.GetUsername());
            Assert.AreEqual("Password", o.GetPassword());
        }
Esempio n. 6
0
        public void JsonLoginObjectToJsonInvalidTest()
        {
            bool         exception = false;
            TemplateJson tl        = new JsonLogin();

            try
            {
                var json = tl.GetJson("I am the wrong object");
            }
            catch (InvalidLoginObjectException)
            {
                exception = true;
            }

            Assert.IsTrue(exception);
        }
Esempio n. 7
0
        public void JsonLoginJsonToObjectInvalidTest()
        {
            bool         exception = false;
            var          incorrect = "{\"emails\":\"[email protected]\",\"password\":\"Password\"}";
            TemplateJson tl        = new JsonLogin();

            try
            {
                var o = tl.GetObject(incorrect) as Login;
            }
            catch (InvalidLoginJsonException)
            {
                exception = true;
            }

            Assert.IsTrue(exception);
        }
Esempio n. 8
0
        //commit here
        private async void loginAsync()
        {
            ServicioWebApi servicio = new ServicioWebApi();
            JsonLogin      user     = new JsonLogin();

            user.DNI    = DNI;
            user.Contra = Contra;
            string resp = await servicio.Login(user);

            if (!string.IsNullOrEmpty(resp))
            {
                await Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(new MainPage()), true);
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Revise los datos de inicio", "OK");
            }
        }
Esempio n. 9
0
        public void Login()
        {
            baseUrl = "https://perf.exalinkservices.com:8443";
            string login    = "******";
            string password = "******";

            JsonLogin jsonLogin = new JsonLogin(login, password);

            RestClient  restClient  = new RestClient(baseUrl + "/apigateway/v1/sessions");
            RestRequest restRequest = new RestRequest(Method.POST);

            restRequest.AddHeader("Content-type", "application/json");
            restRequest.AddJsonBody(jsonLogin);

            IRestResponse responce = restClient.Execute(restRequest);

            RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();
            var JSONObj = deserial.Deserialize <Dictionary <string, string> >(responce);

            sessionId = JSONObj["sessionId"];

            Assert.Warn(sessionId);
        }
Esempio n. 10
0
        public async override Task <WindDataLib.CreditInfo> Get(string username, string password, string type, Guid dev_id)
        {
            httpclient.DefaultRequestHeaders.Clear();
            var logresposne = new JsonLogin();

            ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => { return(true); }; //Validate any certificate. Who cares about security.
            using (var content = new StringContent(string.Format("handset-os=Android+4.3&handset-model=HTC+HTC+One&username={0}&password={1}", username, password)))
            {
                httpclient.DefaultRequestHeaders.Add("Accept", "application/json");
                content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                httpclient.DefaultRequestHeaders.ExpectContinue = false;
                using (var httpstrAuthJson = await httpclient.PostAsync("https://authserv.infostrada.it/155/auth/new/LoginUidPwd", content))
                {
                    var strAuthJson = await httpstrAuthJson.Content.ReadAsStringAsync();

                    try
                    {
                        logresposne = JsonConvert.DeserializeObject <JsonLogin>(strAuthJson);
                        if (logresposne == null || logresposne.Response.Status != "0")
                        {
                            throw new WrongLoginDataException(logresposne.Response.Reason);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message);
                    }
                }
            }

            cr.Username = username;
            cr.Password = password;
            cr.Type     = type;


            var continueAction = new Action <Task <HttpResponseMessage> >(async t =>
            {
                try
                {
                    using (var response = await t)
                    {
                        if (t.Status == TaskStatus.RanToCompletion && t.Exception == null)
                        {
                            var str = await response.Content.ReadAsStringAsync();
                            response.RequestMessage.Content.Dispose();
                            DeserializeInOutput(str, response.RequestMessage.RequestUri);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            });

            cr.NumberInfos = new ObservableCollection <NumberInfo>();
            foreach (var line in logresposne.Login.Lines)
            {
                var content = new StringContent(string.Format("sessionid={0}&msisdn={1}&contract-code={2}&customer-code={3}", logresposne.Login.Session.Id, line.Msisdn, line.ContractCode, logresposne.CustomerCode));
                content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                foreach (var url in (new[] { "https://authserv.infostrada.it/155/line/LineSummary", "https://authserv.infostrada.it/155/line/BonusInfo", "https://authserv.infostrada.it/155/line/CreditBalance", "https://authserv.infostrada.it/155/text/TextCatalog", "https://authserv.infostrada.it/155/recharge/DebitsCredits", "https://authserv.infostrada.it/155/traffic/TrafficDetails", "https://authserv.infostrada.it/155/traffic/TrafficSummary", "https://authserv.infostrada.it/155/customer/CustomerDetails" }).Take(1))
                {
                    tasks.Add(httpclient.PostAsync(new Uri(url, UriKind.Absolute), content).ContinueWith(continueAction));
                }
            }


            Task.WaitAll(tasks.ToArray());
            if (!cr.NumberInfos.Any())
            {
                throw new Exception("Impossibile trovare SIM disponibili");
            }
            return(cr);
        }
Esempio n. 11
0
        public static void Main(string[] args)
        {
            var helloIAm       = new CP2013_WordOfMouth.DTO.AppointmentType(1, "Clean my teeth", 100);
            var jsonApointment = new JsonAppointmentAddType().GetJson(helloIAm);
            var test           = PostRequests(new HttpPostAddAppointmentType(), jsonApointment);

            var Login      = new Login("*****@*****.**", "Password");
            var json       = new JsonLogin().GetJson(Login);
            var something  = PostRequests(new HttpPostLogin(), json);
            var newSession = new JsonSession().GetObject(something) as Session;
            var dentistser = GetRequests(new HttpGetAllDentist(), new JsonAllDentists(), "") as List <Dentist>;

            var allAvaliable = GetRequests(new HttpGetAllAvaliableTimes(), new JsonDentistTimeSlots(), "");
            //  foreach (var d in dentistser)
            //  {
            var stuffed        = PostRequests(new HttpGetBookingsForDentist(), 2.ToString());
            var objectsAreGood = new JsonAppointments().GetObject(stuffed) as List <Appointment>;
            //  }

            var dentistperson = new Dentist(0, "Dentist New", "*****@*****.**", "0412345678");
            var jd            = new JsonDentistEditAdd();
            var json2         = jd.GetJson(dentistperson);

            var stuff = PostRequests(new HttpPostAddDentist(), json2);

            dentistser = GetRequests(new HttpGetAllDentist(), new JsonAllDentists(), "") as List <Dentist>;

            var i = dentistser.Count - 1;

            dentistperson = new Dentist(i, "Dentist New", "*****@*****.**", "0412345678");
            jd            = new JsonDentistEditAdd();
            json2         = jd.GetJson(dentistperson);

            stuff = PostRequests(new HttpPostEditDentist(), json2);

            GetRequests(new HttpGetDentist(), new JsonDentist(), 1.ToString());
            GetRequests(new HttpGetAppointments(), new JsonAppointments(), newSession.GetSessionID().ToString());
            var timeSlots         = GetRequests(new HttpGetDentistTimeSlots(), new JsonDentistTimeSlots(), 2.ToString());
            var apps              = GetRequests(new HttpGetAllAppointmentTypes(), new JsonAllAppointmentTypes(), "");
            var deleteAppointment = new HttpPostDeleteAppointment();

            deleteAppointment.SendRequest(1.ToString());
            var response = deleteAppointment.GetResponse();

            //var Login = new Login("*****@*****.**", "Password");
            //var json = new JsonLogin().GetJson(Login);


            PostRequests(new HttpPostDeleteDentist(), 37.ToString());
            #region OLDMAIN
            var login    = new OldLogin("*****@*****.**", "Password");
            var session  = rr.Login(login);
            var dentists = rr.GetAllDentists();
            var dentist  = rr.GetDentist(dentists[0].id);
            // var timeSlots = rr.GetAllTimeSlots();

            Console.WriteLine(timeSlots);
            rr.GetTimeSlotsForDentist(dentists[0].id);
            Console.WriteLine(dentists);


            fileHandler = new MOCKFileHandler();
            var key = GetStringFromOutput(MENU);

            while (key != "q")
            {
                switch (key)
                {
                case "1":
                    UserUI();
                    break;

                case "2":
                    AdminUI();
                    break;

                default:
                    Console.WriteLine("unknown error");
                    break;
                }
                key = GetStringFromOutput(MENU);
            }
            #endregion
        }
Esempio n. 12
0
    public async Task <IHttpActionResult> Get([FromUri] string q, [FromUri] string x)
    {
        RequestCount++;

        try
        {
            List <Task> tasks = new List <Task>();

            var cookieJar   = new CookieContainer();
            var logresposne = new JsonLogin();
            using (var handler = new HttpClientHandler {
                AllowAutoRedirect = true, UseCookies = true, CookieContainer = cookieJar
            })
            {
                using (var httpclient = new HttpClient(handler))
                {
                    ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => { return(true); }; //Validate any certificate. Who cares about security.
                    using (var content = new StringContent(string.Format("handset-os=Android+4.3&handset-model=HTC+HTC+One&username={0}&password={1}", q, x)))
                    {
                        httpclient.DefaultRequestHeaders.Add("Accept", "application/json");
                        content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                        httpclient.DefaultRequestHeaders.ExpectContinue = false;
                        httpclient.BaseAddress = new Uri("https://authserv.infostrada.it", UriKind.Absolute);
                        using (var httpstrAuthJson = await httpclient.PostAsync("/155/auth/new/LoginUidPwd", content))
                        {
                            var strAuthJson = await httpstrAuthJson.Content.ReadAsStringAsync();

                            try
                            {
                                logresposne = JsonConvert.DeserializeObject <JsonLogin>(strAuthJson);
                                if (logresposne == null || logresposne.Response.Status != "0")
                                {
                                    return(BadRequest(logresposne.Response.Reason));
                                }
                            }
                            catch (Exception)
                            {
                                return(BadRequest("Il servizio Wind non è attualmente disponibile."));
                            }
                        }
                    }

                    cr.Username = q;
                    cr.Password = x;


                    Expression <Func <LoggedUser, bool> > whereExp = tx => tx.Username == q;

                    try
                    {
                        var res = _context.LoggedUsers.Where(whereExp);
                        if (res.Count() == 0)
                        {
                            _context.LoggedUsers.Add(new LoggedUser {
                                Username = q, Password = x
                            });
                        }
                        else
                        {
                            _context.LoggedUsers.First(whereExp).Password = x;
                        }

                        _context.SaveChanges();
                    }
                    catch (Exception)
                    {
                        //Se non salva pazienza, su somee non c'è base di dati.
                    }


                    var continueAction = new Action <Task <HttpResponseMessage> >(async t =>
                    {
                        try
                        {
                            using (var response = await t)
                            {
                                if (t.Status == TaskStatus.RanToCompletion && t.Exception == null)
                                {
                                    var str = await response.Content.ReadAsStringAsync();
                                    response.RequestMessage.Content.Dispose();
                                    DeserializeInOutput(str, response.RequestMessage.RequestUri);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.Message);
                        }
                    });

                    cr.NumberInfos = new ObservableCollection <NumberInfo>();
                    foreach (var line in logresposne.Login.Lines)
                    {
                        var content = new StringContent(string.Format("sessionid={0}&msisdn={1}&contract-code={2}&customer-code={3}", logresposne.Login.Session.Id, line.Msisdn, line.ContractCode, logresposne.CustomerCode));
                        content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                        foreach (var url in (new[] { "/155/line/LineSummary", "/155/line/BonusInfo", "/155/line/CreditBalance", "/155/text/TextCatalog", "/155/recharge/DebitsCredits", "/155/traffic/TrafficDetails", "/155/traffic/TrafficSummary", "/155/customer/CustomerDetails" }).Take(1))
                        {
                            tasks.Add(httpclient.PostAsync(new Uri(url, UriKind.Relative), content).ContinueWith(continueAction));
                        }
                    }

                    Task.WaitAll(tasks.ToArray());
                }



                return(Ok(cr));
            }
        }
        catch (Exception e)
        {
            return(BadRequest(e.Message));
        }
    }