예제 #1
0
        public async Task <string> ServiceAuthentication(STPLoginSocial L_model)
        {
            string isoJson = JsonConvert.SerializeObject(L_model);

            var request = (HttpWebRequest)WebRequest.Create(Utility.login_registartion_url + "/DesktopModules/stpapi/API/Auth/sociallogin");


            var data = Encoding.ASCII.GetBytes(isoJson);

            request.Method = "POST";
            //request.ContentType = "application/x-www-form-urlencoded";
            request.ContentType   = "application/json; charset=utf-8";
            request.Accept        = "application/json; charset=utf-8";
            request.ContentLength = data.Length;
            var responseString = "";



            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            try
            {
                var response1 = (HttpWebResponse)request.GetResponse();
                if (response1.StatusCode == HttpStatusCode.OK)
                {
                    responseString = new StreamReader(response1.GetResponseStream()).ReadToEnd();
                }
            }

            catch (WebException we)
            {
                var errresponse = (HttpWebResponse)we.Response;
                using (StreamReader errreader = new StreamReader(errresponse.GetResponseStream()))
                {
                    responseString = errreader.ReadToEnd();
                }
            }


            //else if (response1.StatusCode == HttpStatusCode.Forbidden)
            //{
            //    responseString = new StreamReader(response1.GetResponseStream()).ReadToEnd();
            //}
            //else
            //{
            //    responseString = "Error: " + response1.StatusCode.ToString();
            //}



            return(responseString);
        }
        async void DoAuthentication(string email, string password, string username)
        {
            // string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");

            string         myts  = DateTime.Now.ToString("yyyyMMddHHmmss");
            STPLoginSocial model = new STPLoginSocial
            {
                Username = email,
                Password = password,
                ts       = myts
            };

            model.hash = model.GetHashforSocial(myts);

            string response = "";

            try
            {
                response = await restService.ServiceAuthentication(model).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                //cpd.DismissDialog();
                mGoogleApiClient.Disconnect();
                Toast.MakeText(this, e.Message, ToastLength.Long).Show();
            }
            mGoogleApiClient.Disconnect();
            Toast.MakeText(this, response, ToastLength.Long).Show();
            try
            {
                STPReg userinfo = new STPReg();

                userinfo = JsonConvert.DeserializeObject <STPReg>(response);

                if (response.Contains("ERROR"))
                {
                    //cpd.DismissDialog();

                    var socialintent = new Intent(this, typeof(Registration_Activity));
                    socialintent.PutExtra("email", email);
                    socialintent.PutExtra("username", username);
                    StartActivityForResult(socialintent, 125);
                }

                else
                {
                    //cpd.DismissDialog();
                    STPUserInfo userinfo2 = new STPUserInfo();

                    userinfo2 = JsonConvert.DeserializeObject <STPUserInfo>(response);
                    edit.Clear();
                    // login suceeded, parse json
                    edit.PutString("username", userinfo2.DisplayName);
                    edit.PutInt("userid", userinfo2.UserID);
                    edit.PutString("profilePath", userinfo2.ImageURL);
                    edit.PutBoolean("pluscard", userinfo2.PlusCard);
                    edit.PutBoolean("banned", userinfo2.Banned);
                    edit.Apply();
                    //cpd.DismissDialog();

                    Finish();
                    Toast.MakeText(this, "Welcome " + userinfo.DisplayName, ToastLength.Long).Show();
                }
            }

            catch (Exception)
            {
                //cpd.DismissDialog();
            }
        }
        async void DoAuthentication(string email, string password)
        {
            // string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");


            STPLoginSocial model = new STPLoginSocial
            {
                Username = email,
                Password = password,
            };

            model.hash = model.GetHashforSocial("");

            string response = "";

            try
            {
                response = await restService.ServiceAuthentication(model).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Toast.MakeText(this, e.Message, ToastLength.Long).Show();
            }

            try
            {
                STPReg userinfo = new STPReg();

                // userinfo = JsonConvert.DeserializeObject<STPReg>(response);

                if (response.Contains("ERROR"))
                {
                    userinfo.Username = email;
                    alreadyregistered = userinfo.Username;

                    var socialintent = new Intent(this, typeof(Registration_Activity));

                    StartActivityForResult(socialintent, 125);
                }

                else
                {
                    STPUserInfo userinfo2 = new STPUserInfo();

                    userinfo2 = JsonConvert.DeserializeObject <STPUserInfo>(response);
                    edit.Clear();
                    // login suceeded, parse json
                    edit.PutString("username", userinfo2.DisplayName);
                    edit.PutString("profilePath", userinfo2.ImageURL);
                    edit.PutInt("userid", userinfo2.UserID);

                    edit.Apply();

                    Finish();
                    Toast.MakeText(this, "Welcome " + userinfo.DisplayName, ToastLength.Long).Show();

                    var registerintent = new Intent(this, typeof(MainActivity));

                    StartActivityForResult(registerintent, 123);
                }



                // Toast.MakeText(this, "Welcome " + userinfo.Username, ToastLength.Long).Show();
            }


            catch (Exception)
            {
            }
        }