public async Task <string> Logining(string email, string password) { /*string email_val = email; * string password_val = password;*/ var client = new RestClient("http://api.xplorpal.com"); var request = new RestRequest("/login", Method.POST); /* * request.AddParameter("email", "*****@*****.**"); * request.AddParameter("password", "dontoretto23"); */ request.AddParameter("email", email); request.AddParameter("password", password); IRestResponse response = await client.ExecuteTaskAsync(request); var content = response.Content; // Toast.MakeText(this, content, ToastLength.Long).Show(); //Console.WriteLine(content.ToString()); if (content.Length > 100)//response.StatusCode == System.Net.HttpStatusCode.OK) { var usr = JsonConvert.DeserializeObject <List <User> >(content); var usr_ = usr[0]; try { RecyclerViewSample.Login.token = usr_.api_token; } catch { } try { RecyclerViewSample.Login.name = usr_.name; } catch { } try { RecyclerViewSample.Login.email_ = usr_.email; } catch { } try { RecyclerViewSample.Login.user_id = usr_.id; } catch { } try { RecyclerViewSample.Login.user_country_id = Convert.ToInt32(usr_.user_country_id); } catch { } try { RecyclerViewSample.Login.birth_date = usr_.birth_date.ToString(); } catch { } try { RecyclerViewSample.Login.gender = usr_.gender.ToString(); } catch { } try { RecyclerViewSample.Login.phone_num = usr_.phone_num.ToString(); } catch { } try { RecyclerViewSample.Login.interests = usr_.bio; } catch { } try { RecyclerViewSample.Login.password = password; } catch { } try { //removing this part of the content RecyclerViewSample.Login.avatar = Convert.FromBase64String(usr_.avatar_base64.Replace("data:image/jpeg;base64,", "")); } catch { } //declaring path for RETRIEVING DATA string dbPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "ormdemo.db3"); var db = new SQLiteConnection(dbPath); var user_table = db.Table <RecyclerViewSample.ORM.UsersDataTable>(); RecyclerViewSample.MainActivity.isLogined = false; //clearing table foreach (var item in user_table) { dbr.RemoveUsersData(item.Id); } dbr.InsertRecord(RecyclerViewSample.Login.name, RecyclerViewSample.Login.email_, RecyclerViewSample.Login.avatar, RecyclerViewSample.Login.token, RecyclerViewSample.Login.birth_date, RecyclerViewSample.Login.gender, RecyclerViewSample.Login.phone_num, RecyclerViewSample.Login.interests, RecyclerViewSample.Login.user_country_id, RecyclerViewSample.Login.user_id, RecyclerViewSample.Login.password); RecyclerViewSample.MainActivity.isLogined = true; GettingJSON gj = new GettingJSON(); //await gj.VictorSologoob(token, lat, lon); //await gj.VictorSologoob(token, "38.8951100", "-77.0363700"); if (RecyclerViewSample.Login.lat_For_places_of_interest_table != null) { await gj.VictorSologoob( RecyclerViewSample.Login.token, RecyclerViewSample.Login.lat_For_places_of_interest_table, RecyclerViewSample.Login.lng_For_places_of_interest_table); login.addTo_placesOfInterest(); } else { //gj.VictorSologoob(token, "38.8951100", "-77.0363700"); await gj.VictorSologoob( RecyclerViewSample.Login.token, RecyclerViewSample.Activities.NEWstartActivity.lat, RecyclerViewSample.Activities.NEWstartActivity.lon); login.addTo_placesOfInterest(); } string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); var filePath = System.IO.Path.Combine(path, "iootext.txt"); using (var streamWriter = new StreamWriter(filePath, true)) { streamWriter.WriteLine(RecyclerViewSample.Login.token.ToString()); } using (var streamReader = new StreamReader(filePath)) { string containing = streamReader.ReadToEnd(); System.Diagnostics.Debug.WriteLine(containing); } activityIndicator.Visibility = Android.Views.ViewStates.Gone; StartActivity(typeof(RecyclerViewSampl.ImageUpload)); //StartActivity(typeof(MainActivity)); } else { try { activityIndicator.Visibility = Android.Views.ViewStates.Gone; } catch { } string toast = "Check your Email and Password"; Toast.MakeText(this, toast, ToastLength.Long).Show(); } return(""); }
public async Task <string> Logining() { Button login = FindViewById <Button>(Resource.Id.login_button); Button cancelBn = FindViewById <Button>(Resource.Id.cancelBn); TextView forgetYourPassword = FindViewById <TextView>(Resource.Id.forgetYourPassword); EditText email = FindViewById <EditText>(Resource.Id.login_email); EditText passwordET = FindViewById <EditText>(Resource.Id.login_password); if (String.IsNullOrWhiteSpace(email.Text) || String.IsNullOrWhiteSpace(passwordET.Text)) { try { activityIndicator.Visibility = Android.Views.ViewStates.Gone; } catch { } Toast.MakeText(this, "Credentials must not be empty", ToastLength.Short).Show(); } else { activityIndicator.Visibility = Android.Views.ViewStates.Visible; login.Visibility = Android.Views.ViewStates.Gone; cancelBn.Visibility = Android.Views.ViewStates.Gone; forgetYourPassword.Visibility = ViewStates.Gone; string path2 = "fonts/HelveticaNeueLight.ttf"; Typeface tf = Typeface.CreateFromAsset(Assets, path2); email.Typeface = tf; passwordET.Typeface = tf; string email_val = email.Text; string password_val = passwordET.Text; var client = new RestClient("http://api.xplorpal.com"); var request = new RestRequest("/login", Method.POST); /* * request.AddParameter("email", "*****@*****.**"); * request.AddParameter("password", "dontoretto23"); */ request.AddParameter("email", email.Text); request.AddParameter("password", passwordET.Text); IRestResponse response = await client.ExecuteTaskAsync(request); var content = response.Content; // Toast.MakeText(this, content, ToastLength.Long).Show(); Console.WriteLine(content.ToString()); if (content.Length > 100)//response.StatusCode == System.Net.HttpStatusCode.OK) { try { var usr = JsonConvert.DeserializeObject <List <User> >(content); var usr_ = usr[0]; try { token = usr_.api_token; } catch { } try { name = usr_.name; } catch { } try { email_ = usr_.email; } catch { } try { user_id = usr_.id; } catch { } try { birth_date = usr_.birth_date.ToString(); } catch { } try { gender = usr_.gender.ToString(); } catch { } try { phone_num = usr_.phone_num.ToString(); } catch { } try { interests = usr_.bio; } catch { } try { password = passwordET.Text; } catch { } try { avatar = Convert.FromBase64String(usr_.avatar_base64.Replace("data:image/jpeg;base64,", "")); } catch { } try{ user_country_id = Convert.ToInt32(usr_.user_country_id); }catch {} } catch { } /*ImageView Image = FindViewById<ImageView>(Resource.Id.imageView1); * /* Glide.With(Application.Context) * .Load(avatar) * .Into(Image); * //WE NEED ALL OF THIS TO WRITE IMAGE TO DATABASE * Image.BuildDrawingCache(true); * Bitmap bitmap = Image.GetDrawingCache(true); * Image.SetImageBitmap(bitmap); * Bitmap b = Bitmap.CreateBitmap(Image.GetDrawingCache(true)); * MemoryStream memStream = new MemoryStream(); * b.Compress(Bitmap.CompressFormat.Webp, 100, memStream); * //WE NEED ALL OF THIS TO WRITE IMAGE TO DATABASE ENDED */ //declaring path for RETRIEVING DATA string dbPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "ormdemo.db3"); var db = new SQLiteConnection(dbPath); var user_table = db.Table <ORM.UsersDataTable>(); MainActivity.isLogined = false; //clearing table foreach (var item in user_table) { dbr.RemoveUsersData(item.Id); } dbr.InsertRecord(name, email_, avatar, token, birth_date, gender, phone_num, interests, RecyclerViewSample.Login.user_country_id, user_id, password); MainActivity.isLogined = true; GettingJSON gj = new GettingJSON(); //await gj.VictorSologoob(token, lat, lon); //await gj.VictorSologoob(token, "38.8951100", "-77.0363700"); if (lat_For_places_of_interest_table != null) { await gj.VictorSologoob(token, lat_For_places_of_interest_table, lng_For_places_of_interest_table); addTo_placesOfInterest(); } else { //await gj.VictorSologoob(token, "38.8951100", "-77.0363700"); await gj.VictorSologoob(token, Activities.NEWstartActivity.lat, Activities.NEWstartActivity.lon); addTo_placesOfInterest(); } string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var filePath = System.IO.Path.Combine(path, "iootext.txt"); using (var streamWriter = new StreamWriter(filePath, true)) { streamWriter.WriteLine(token.ToString()); } using (var streamReader = new StreamReader(filePath)) { string containing = streamReader.ReadToEnd(); System.Diagnostics.Debug.WriteLine(containing); } activityIndicator.Visibility = Android.Views.ViewStates.Gone; login.Visibility = Android.Views.ViewStates.Visible; cancelBn.Visibility = Android.Views.ViewStates.Visible; forgetYourPassword.Visibility = ViewStates.Visible; //StartActivity(typeof(MainActivity)); if (String.IsNullOrEmpty(Tours_detail.titleStatic)) { StartActivity(typeof(MainActivity)); } else { StartActivity(typeof(SelectAvialability)); } } else { try { login.Visibility = Android.Views.ViewStates.Visible; cancelBn.Visibility = Android.Views.ViewStates.Visible; forgetYourPassword.Visibility = ViewStates.Visible; activityIndicator.Visibility = Android.Views.ViewStates.Gone; } catch { } string toast = "Check your Email and Password"; Toast.MakeText(this, toast, ToastLength.Long).Show(); } } return(""); }