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 DoRegistration(string username, string pasword, string mobilenumber, string emailadress) { //string hash = new LoginModel().GetHash(pasword, username); string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); LoginModel objmodel = new LoginModel { Username = emailadress, Password = pasword, Mobile = mobilenumber, Email = emailadress, DisplayName = username, LoginType = "stportal", ts = timestamp }; objmodel.hash = objmodel.GetHash(); string test = JsonConvert.SerializeObject(objmodel); string response = ""; try { var thread = new System.Threading.Thread(new ThreadStart(async delegate { cpd.Show(); })); thread.Start(); while (thread.ThreadState == ThreadState.Running) { await Task.Delay(100); } response = await restService.PostServiceMethodRegistration(objmodel).ConfigureAwait(false); } catch (Exception we) { cpd.DismissDialog(); //var errresponse = (HttpWebResponse)we.Response; //using (StreamReader errreader = new StreamReader(errresponse.GetResponseStream())) //{ // responseString = errreader.ReadToEnd(); //} ////Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } if (response.StartsWith("Error")) { cpd.DismissDialog(); Toast.MakeText(this, response, ToastLength.Long).Show(); // login failed } else { try { cpd.DismissDialog(); STPUserInfo userinfo = new STPUserInfo(); userinfo = JsonConvert.DeserializeObject <STPUserInfo>(response); if (response.Contains("UserAlreadyRegistered")) { //var registerintent = new Intent(this, typeof(MainActivity)); //StartActivityForResult(registerintent, 123); //Toast.MakeText(this, "Welcome " + userinfo.DisplayName, ToastLength.Long).Show(); } else { STPUserInfo userinfo2 = new STPUserInfo(); userinfo = JsonConvert.DeserializeObject <STPUserInfo>(response); edit.Clear(); // login suceeded, parse json edit.PutString("username", userinfo.DisplayName); edit.PutString("profilePath", userinfo.ImageURL); edit.PutInt("userid", userinfo.UserID); edit.PutBoolean("pluscard", userinfo.PlusCard); edit.PutBoolean("banned", userinfo.Banned); edit.Apply(); Finish(); Toast.MakeText(this, "Welcome " + userinfo.DisplayName, ToastLength.Long).Show(); // var registerintent = new Intent(this, typeof(MainActivity)); // StartActivityForResult(registerintent, 123); } } catch (Exception e) { cpd.DismissDialog(); Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } } }
async void DoLogin(string username, string pasword) { cpd.Show(); LoginModel model = new LoginModel(); model.Username = username; model.Password = pasword; string ret = ""; try { var thread = new System.Threading.Thread(new ThreadStart(async delegate { cpd.Show(); })); thread.Start(); while (thread.ThreadState == ThreadState.Running) { await Task.Delay(100); } ret = await restService.PostServiceMethod(model).ConfigureAwait(false); if (ret.StartsWith("Error")) { cpd.DismissDialog(); if (ret.Contains("403")) { Toast.MakeText(this, "Invalis Username/Password", ToastLength.Long).Show(); } else { Toast.MakeText(this, ret, ToastLength.Long).Show(); } // login failed } else { try { STPUserInfo userinfo = new STPUserInfo(); userinfo = JsonConvert.DeserializeObject <STPUserInfo>(ret); edit.Clear(); // login suceeded, parse json edit.PutString("username", userinfo.DisplayName); edit.PutInt("userid", userinfo.UserID); edit.PutString("profilePath", userinfo.ImageURL); edit.PutBoolean("pluscard", userinfo.PlusCard); edit.PutBoolean("banned", userinfo.Banned); edit.Apply(); cpd.DismissDialog(); Finish(); Toast.MakeText(this, "Welcome " + userinfo.DisplayName, ToastLength.Long).Show(); } catch (Exception e) { cpd.DismissDialog(); Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } } } catch (Exception e) { cpd.DismissDialog(); if (e.Message.Contains("403")) { Toast.MakeText(this, "Invalis Username/Password", ToastLength.Long).Show(); } else { Toast.MakeText(this, ret, ToastLength.Long).Show(); } } }
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) { } }